Skip to content

fix: disable syntax highlighting for code blocks without language specifier#30

Open
codeananda wants to merge 1 commit intoMarkEdit-app:mainfrom
codeananda:fix/disable-auto-highlight-detection
Open

fix: disable syntax highlighting for code blocks without language specifier#30
codeananda wants to merge 1 commit intoMarkEdit-app:mainfrom
codeananda:fix/disable-auto-highlight-detection

Conversation

@codeananda
Copy link

Summary

Code blocks without a language specifier (just triple backticks) were getting unwanted syntax highlighting due to highlight.js auto-language detection. Words like "NATURAL", "Type", "OR", "trigger", "within" were being coloured as if they were programming keywords.

This was likely worsened by the recent dependency upgrade (commit 65e2616).

Changes

  • Added check for empty lang in the fence renderer to skip highlight.js processing
  • When no language is specified, renders as plain <pre><code> without hljs classes
  • Added vitest testing infrastructure with comprehensive tests

Test plan

  • Code blocks without language specifier render as plain text (no syntax highlighting)
  • Code blocks WITH language specifier still get syntax highlighting
  • Mermaid blocks still render correctly as diagrams
  • HTML is properly escaped in plain code blocks
  • All 7 tests pass (yarn test)
  • Lint passes (yarn lint)
  • Build succeeds (yarn build)
  • Manual testing in MarkEdit confirms fix works

@codeananda
Copy link
Author

codeananda commented Feb 3, 2026

Before fix example
markedit-preview-before-fix

After fix example

markedit-preview-after-fix

…cifier

Code blocks without a language specifier (just triple backticks) were
getting unwanted syntax highlighting due to highlight.js auto-detection.
Words like "NATURAL", "Type", "OR", "trigger" were being coloured as
programming keywords.

The fix intercepts code blocks with empty `lang` before they reach
highlight.js and renders them as plain `<pre><code>` without hljs classes.

Also adds vitest testing infrastructure with tests covering:
- Plain code blocks (no hljs classes)
- Code blocks with language (syntax highlighting applied)
- Mermaid blocks (render as div)
@codeananda codeananda force-pushed the fix/disable-auto-highlight-detection branch from ddc8588 to 43d8264 Compare February 3, 2026 11:20
@cyanzhong
Copy link
Contributor

Thank you for submitting the PR.

While the change serves its purpose, I believe we should address the following points:

  • There's a recommended approach for disabling auto-detection: markdown-it-highlightjs. I think we should take advantage of it.
  • While we're unsure whether auto-detect is optimal, it seems to be the default option for a reason. Perhaps we could introduce a configurable option for this behavior.
  • The change isn't fully atomic, as it also introduces unit test infrastructure.

To resolve these, would you be open to merging this PR and repurposing your PR to focus solely on adding the tests?

Looking forward to hearing your thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments