How to stop Kramdown from removing indents in code blocks?

63 Views Asked by At

When rendering Python codeblocks on my Jekyll site, Kramdown removes all of the indents.

The code:

from sort.AbstractSort import AbstractSort

class BubbleSort(AbstractSort):  
    @staticmethod  
    def swap(arr, i, j):  
        arr[i], arr[j] = arr[j], arr[i]  
  
    def _sort(self, arr):  
        for i in range(len(arr) - 1):  
            for j in range(len(arr) - 1):  
                if arr[j] > arr[j + 1]:  
                    BubbleSort.swap(arr, j, j + 1)  
        return arr
    

Kramdown render:

Indents removed

Kramdown doesn't have the best documentation and I couldn't find any obvious settings that I should change in _config.yaml of my Jekyll site.

I'm hosting the site on GitHub pages.

If it is not possible, maybe I should change to a different rendered? But then this is also poorly documented and my attempts to switch to GFM had failed.

1

There are 1 best solutions below

0
matwasilewski On BEST ANSWER

As Benjamin W. have written, this is due to bad CSS configuration in assets/css/style.css.

To solve the problem, change:

pre code {
    ...
    white-space: pre-line !important;       
    ...
}

to

pre code {
    ...
    white-space: pre !important;       
    ...
}

solves the problem.