question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CodeMirror's hypermd syntax highlighter stops working inside a code block

See original GitHub issue

Previously I have reported a bug with CodeMirror’s implementation in the Obsidian knowledge base editor.

Initially, you were hesitant to fix the issue, but eventually, after Obsidian’s developer chimed in, the issue was pinpointed to the Obsidian code and resolved. Hurray! 👍

Now I am coming to you with another issue that has to do with Obsidian and CodeMirror. I reported the bug to the Obsidian and the Admonition plugin developers, but they say that the issue is outside of their reach. I hope that you can check the bug and either fix it or tell me that the bug is not on CodeMirror’s end and thus try to convince the Obsidian/plugin developers that it’s them who should fix it.

Copy of the original bug report (please check for more comments):

How to reproduce the bug

  1. Add 3 test lines inside the admonition: image
  2. Use Obsidian/markdown quote feature(>) on the second line. BUG: Notice that syntax highlighter stopped working on all the lines even below the quoted one. image

Other interesting detail

Putting a code block returns highlighting back to normal. image

Versions

  • Obsidian 0.12.10
  • Admonition 6.2.2

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nothingislostcommented, Oct 1, 2021

This appears to be a bug in the CodeMirror 5 markdown mode. You can replicate the issue on the demo site https://codemirror.net/mode/markdown/ with the following code

```markdown

Test line 1 

> Test line 2  

This is still treated as a quote  
So is this
```

This appears to happen due to the local code block mode state not being reset for quotes. Once a quote is detected on a line. Quote is set to 1 in the local mode state and never reset.

I was able to resolve this by patching the markdown.js mode to add the line: state.quote = 0; after this line https://github.com/codemirror/CodeMirror/blob/47e850575ea314f768ca8539de54ab7a6d8f3779/mode/markdown/markdown.js#L826

0reactions
mikkovedrucommented, Oct 7, 2021

@nothingislost Since it was you who discovered the solution, I think it would only be fair for you to do the honors. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

There seems to be a problem with highlighting code blocks in ...
When initializing the editor, I assigned a long text to the doc attribute. Then, when the page first enters or refreshes, the editor...
Read more >
Syntax highlighter stops working after using Obsidian ...
I reported the bug, but the developer said " I think this is the default behavior for the hypermd CodeMirror syntax highlighter inside...
Read more >
HTML formatting inside highlighted code blocks is no longer ...
Why is text formatting in code blocks now broken? This is caused by a change to the syntax highlighter used by Stack Overflow,...
Read more >
Not highlighting on post page but highlighting on edit page
[This thread is closed.] When I'm editing a post, codemirror blocks is properly highlighting the syntax for me, and in real-time too, very…...
Read more >
obsidian syntax highlighting not working - Moneywecan
This imports a bunch of syntax highlighting modes from CodeMirror, ... To insert a code block use the ` (Found Under your escape...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found