ttscoff/mdless

Codeblocks are broken when having # in the text

ehvs opened this issue · 7 comments

ehvs commented

When having # inside a code block, it reads as a header tag instead of ignoring it.
Eg. Below code block:
```
# TYPE apiserver_audit_requests_rejected_total counter
apiserver_audit_requests_rejected_total 0
```

Is shown as:

TYPE apiserver_audit_requests_rejected_total counter

apiserver_audit_requests_rejected_total 0

When it should show as:

--[ code ]----------------------------------------
# TYPE apiserver_audit_requests_rejected_total counter
apiserver_audit_requests_rejected_total 0
----------------------------------------------------

I like to support this bug report with additional information.
I'm using mdless in the WSL where I have set LC_ALL to C.UTF-8. Comments inside code blocks were working fine up until (including) v1.0.21. From v1.0.22 on, comments are not rendered correctly.

Additionally I found for code blocks where the syntax language is not found:

  • comments are rendered as Markdown titles, with only the first word and the '=' characters being black-on-white
  • before and after v1.0.22, bold and italic text is rendered inside the code block, but again only the first word

Test Markdown script:

# Test

```sh
# shell comment
echo *'Hello World'*
```

```asdf
# shell comment
echo *'Hello World'*
```

GitHub rendering:

Test

# shell comment
echo *'Hello World'*
# shell comment
echo *'Hello World'*

mdless:

v1.0.21 v1.0.22
mdless-code-comment-bug-1 mdless-code-comment-bug-2

Same issue for me with v1.0.35, code blocks are full of wrong background colors and visible escape codes.

Please try installing 1.0.37 and see if the issue is resolved.

Thank you, the issues with apparent escape sequences and with the # are resolved.

Can confirm the biggest issues are solved 👍🏽. However there are still some minor issues that I tried to pinpoint as much as possible:

  • The first word in MD style italic or bold formatted texts is still formatted inside code blocks with unknown syntax.
    • Same for code blocks with known syntax in lines starting with #. Here however it formats the whole italic or bold part.
  • Heading lines starting with one or more # that contain another # somewhere in the line are not formatted as a heading. Instead the line is printed as plain text.
  • --- and ===, which formats text one line above it as a heading, breaks on lines already marked as a heading by #, both outside and inside code blocks:
    • To apply the formatting, mdless seems to add # or ## in front of the line to format the line as a heading afterwards. As described above, the line is then printed as plain text because of the additional #.
  • --- followed by another --- formats the first line as a heading instead of printing two horizontal bars.
  • For two consecutive === it is correct behaviour to format the first === as a heading.
  • In code blocks with unknown syntax, the inner text is indented by one more space.
  • The ending bar of a code block might preferably be printed right after the code without the extra empty line?

Also tested with --no-color to make sure color doesn't break anything. Result was the same output just without colors.

Regarding code blocks my main question would be, why is Markdown formatting applied to the blocks at all? Maybe this can be avoided entirely, I'm not familiar with the code.

Test markdown script:

# Title 1

# # Title 2.1

# Title # 2.2

Title 3.1
===

Title 3.2
---

# Title 4.1
===

# Title 4.2
---

---

---
---

===
===

```sh
# *comment 1*
# comment 2
===
# comment 3
===
===
# comment 4
===
---
echo ***'Hello World'***
echo ***'Hello World'***
===
```

```asdf
# *comment 1*
# comment 2
---
# comment 3
---
---
# comment 4
---
===
echo ***'Hello World'***
echo ***'Hello World'***
---
```

GitHub rendering:

Title 1

# Title 2.1

Title # 2.2

Title 3.1

Title 3.2

Title 4.1

===

Title 4.2





===

# *comment 1*
# comment 2
===
# comment 3
===
===
# comment 4
===
---
echo ***'Hello World'***
echo ***'Hello World'***
===
# *comment 1*
# comment 2
---
# comment 3
---
---
# comment 4
---
===
echo ***'Hello World'***
echo ***'Hello World'***
---

mdless:

mdless