简体   繁体   中英

How to stop Kramdown from removing indents in code blocks?

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:

已删除缩进

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM