python-markdownify icon indicating copy to clipboard operation
python-markdownify copied to clipboard

Whitespace is removed in code

Open JamesDConley opened this issue 1 year ago • 3 comments

When converting html with <code> blocks the whitespace ends up with a maximum of one space. This unfortunately means anything with python in codeblocks can't be converted :(

JamesDConley avatar Mar 02 '23 04:03 JamesDConley

image

kelibird avatar Mar 09 '23 08:03 kelibird

image

Thanks! Was wondering why my code was doing this.

Meathelix1 avatar Mar 10 '23 02:03 Meathelix1

I don't think this is a bug. <code> is an inline HTML element per the specification, and thus it does not preserve whitespace. If you render

<code>line1
line2
line3</code>

in a browser, all three words will be on a single line.

You need to enclose your code in a <pre> block, which is whitespace-preserved per the specification.

chrispy-snps avatar Jan 14 '24 14:01 chrispy-snps