0

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.

matwasilewski
  • 384
  • 2
  • 11
  • What does the raw input look like? And are you using GitHub Pages, or something else? – Benjamin W. Jun 26 '22 at 23:13
  • 1
    I've [found it](https://github.com/matwasilewski/matwasilewski.github.io/blob/main/_notes/Public/Pytest%20fixtures%20-%20introduction.md?plain=1). It's a CSS problem: your code block ends up with `white-space: pre-line !important;`, set [here](https://github.com/matwasilewski/matwasilewski.github.io/blob/eb1b265a8f31d3db31dd4184929923c7074be62e/assets/css/style.css#L297), as far as I can tell. If you switch that to `pre`, the whitespace/indentation is preserved. – Benjamin W. Jun 26 '22 at 23:20
  • Thanks - this indeed solves the problem. I added my code and the solution in an answer. – matwasilewski Jun 27 '22 at 11:02

1 Answers1

0

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.

matwasilewski
  • 384
  • 2
  • 11