mity / md4c

C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
MIT License
756 stars 138 forks source link

Code block weirdness #124

Closed niblo closed 3 years ago

niblo commented 3 years ago

Input (extra empty line at the beginning for better readable output); the row of A's is indented by 17 spaces:

```
A                A
                 A
                 A
                 A
```

Output:

<pre><code>
A                A
                A
                A
                A
</code></pre>

But look at this; the row of A's is indented by 16 spaces instead of 17:

Input:

```

A               A
                A
                A
                A
```

Output:

<pre><code>
A               A
                A
                A
                A
</code></pre>

Anything below an indent of 17 spaces seems ok.


I just used a column of A's to see the results better; here's a minimal case:

```

A
                 B
```

Output (one less space before the 'b':

<pre><code>
A
                B
</code></pre>

Even more minimal:

```
                 B
```

Output (one leading space stripped off):

<pre><code>                B
</code></pre>

It doesn't seem to happen if you indent by less than 17.

mity commented 3 years ago

I cannot reproduce with md2html utility in the current head:

$ printf 'A                A\n                 A\n                 A\n                 A' | ./md2html/md2html
<p>A                A
A
A
A</p>

Are you using some non-default flags or something?

mity commented 3 years ago

The first examples are not valid code blocks at all because the 1st line is not indented enough.

When trying the "more minimal" test case, I still can't see any problem:

$ printf '                 B'  | ./md2html/md2html
<pre><code>             B
</code></pre>

The input has exactly 17 spaces of indentation, the output (between <code> and B) has 13 spaces (which is imho ok because 13 = 17 - 4).

niblo commented 3 years ago

I forgot to mention that it was fenced code blocks, and I forgot to add in the fences in the input examples. I updated the examples now.

mity commented 3 years ago

Fixed. Thanks for reporting it.

niblo commented 3 years ago

Thanks.