kristapsdz / lowdown

simple markdown translator
https://kristaps.bsd.lv/lowdown
ISC License
294 stars 36 forks source link

Weirdness with whitespace before code blocks #135

Closed paravoid closed 2 weeks ago

paravoid commented 6 months ago

This:

This is a table:
```
| Column1 | Column2 |
| ------- | ------- |
| foo     | bar     |
```

Renders as:

    This is a table:  | Column1 | Column2 | | ------- | ------- | | foo | bar | 

...all in one line.

Adding a whitespace after the first line like so:

This is a table:

```
| Column1 | Column2 |
| ------- | ------- |
| foo     | bar     |
```

...renders the code block correctly, but omits the "This is a table:" line altogether!:

      | | Column1 | Column2 |
      | | ------- | ------- |
      | | foo     | bar     |

Adding another whitespace at the top like so:


This is a table:

```
| Column1 | Column2 |
| ------- | ------- |
| foo     | bar     |
```

...generates the expected (I think) output:

    This is a table:

      | | Column1 | Column2 |
      | | ------- | ------- |
      | | foo     | bar     |
kristapsdz commented 2 weeks ago

Haha! That was a head-scratcher. Taking these one at a time...

  1. The initial fence (```), right after a line of text, is interpreted as a regular code span within the paragraph. Code spans can have any number of backticks surrounding them.

  2. The blank line before the fence makes the fence be in its own block, so it's interpreted properly as block-level code.

  3. The "This is a table:" mystery! This is because it's being treated as document-level metadata. That's why it's not appearing in the document any more: it's now a metadata key with a zero-length value.

  4. By adding an initial newline, the "This is a table:" is no longer in the metadata block.

kristapsdz commented 2 weeks ago

This has also prompted me to document code fences in the manpages. If there's anything else you can find, or any language you think might have helped (I used -Ttree), then please let me know. Thanks again!