srid / emanote

Emanate a structured view of your plain-text notes
https://emanote.srid.ca
Other
793 stars 70 forks source link

highlight.js occasionally does not highlight Haskell/Nix code blocks when editing #463

Open tmoux opened 9 months ago

tmoux commented 9 months ago

Describe the bug When editing a page with a Haskell/Nix/any non-default-highlight.js language code block, syntax highlighting will occasionally break. When this happens, the following warning is displayed in the browser console:

WARN: Could not find the language 'haskell', did you forget to load/include a language module?
WARN: Falling back to no-highlight mode for this block. 

The issue is fixed whenever the page is reloaded, or by calling hljs.highlightAll() in the console. Additional edits will sometimes fix the problem, sometimes not.

To Reproduce Steps to reproduce the behavior:

  1. Download the emanote-template and start the server.
  2. Add the following code block to Tutorials/Slug.md:
    ```haskell
    data Foo = A | B
    1. Add/remove lines of text. It may take several edits for the highlighting to stop working. I find that adding a new line of text and then deleting it frequently causes the error.
    2. Alternatively, refresh the page several times until the highlighting breaks.

Expected behavior Code blocks should be correctly highlighted whenever the page is being edited.

Screenshots

Screenshot 2023-11-30 at 2 24 42 PM

Desktop (please complete the following information):

Additional context

The problem seems to only occur with languages that are not included by default in highlight.js. As seen in the screenshot, the syntax highlighting for the yaml code block never breaks. I tried updating the version of highlight.js to 11.9.0, but this had no effect.

srid commented 9 months ago

Aside: another case for #337 I suppose ...