feat: support ==highlight== markdown syntax (#2552) by Jocs · Pull Request #5647 · marktext/marktext · GitHub
Skip to content

feat: support ==highlight== markdown syntax (#2552) - #5647

Merged
Jocs merged 4 commits into
developfrom
feat/highlight-syntax-2552
Oct 7, 2026
Merged

Jocs merged 4 commits into
developfrom
feat/highlight-syntax-2552

Conversation

@Jocs

@Jocs Jocs commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Closes #2552

Summary

Implements ==highlight==, the non-standard markdown extension used by Obsidian / Typora / Logseq / Joplin, in both the editor and the export paths.

Adds an off-by-default Preferences → Markdown → Extensions → Highlight (==text==) toggle. When enabled, ==text== renders as <mark> in the WYSIWYG editor and in the HTML / PDF / print / "Copy as HTML" output. When disabled (the default), == keeps reading as literal text, so existing documents are unaffected.

The existing <mark> handling is unchanged, and the Highlight button / menu / shortcut keep inserting <mark>; the new syntax only activates on manual input or paste.

Type of change

  • New feature (non-breaking, adds functionality)
  • Documentation update
  • Bug fix (non-breaking, fixes an issue)
  • Breaking change (causes existing functionality to change)

Test plan

  • New tests added:
    • packages/muya/src/inlineRenderer/__tests__/markSyntax.spec.ts — editor lexer plus export (getHighlightHtml / getClipBoardHtml)
    • packages/muya/src/block/base/__tests__/formatToggle.spec.ts — toggling format('mark') off an ==…== run
    • packages/muya/src/__tests__/setOptions.spec.ts — live highlightSyntax toggle re-renders <mark>
    • packages/muya/src/state/__tests__/renderToStaticHTML.spec.ts — option on/off
  • pnpm -C packages/muya test (278 files / 2389 tests), test:spec (CommonMark + GFM), lint, check-circular, lint:types
  • pnpm run lint (0 errors) and pnpm run typecheck
  • Manually tested on: macOS

Notes for reviewers [optional]

  • Pandoc export is intentionally out of scope: pandoc's mark extension exists only on the markdown reader (not gfm), so enabling it would require switching readers. Verified with pandoc 3.12.
  • Source-code (CodeMirror) highlighting of == is not included.
  • The new inline token is typed mark (not highlight) so it maps onto the existing Highlight format/menu state without changing the menu id → format map.
  • == is not added to auto-pairing or the backslash-escape set.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

Add an off-by-default `highlightSyntax` preference that renders `==text==` as highlighted text in the editor and as `<mark>` in the HTML / PDF / print and copy-as-HTML export paths. The existing `<mark>` handling and the Highlight button/menu (which keep writing `<mark>`) are unchanged; the syntax only activates on manual input or paste.

- muya: new `mark` inline rule/token gated by `highlightSyntax`, rendered through the shared del/em/strong factory; format toggle/clear, TOC plain text and markdown round-trip cover the new token.

- export: new marked `mark` inline extension wired into getHighlightHtml, getClipBoardHtml and renderToStaticHTML.

- desktop: `highlightSyntax` preference (schema / store / Preferences UI, default false) plus all 12 locales and the markdown syntax doc.
@Jocs
Jocs requested a balanced review from Copilot October 7, 2026 13:08
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The preference does not survive restart, and export and formatting operations can discard trailing backslashes.

Review effort: Balanced
Findings: 4 Medium severity

Open (4)
What changed in this PR

Adds opt-in ==highlight== support to MarkText’s editor and HTML-based output, addressing interoperability requested in #2552.

Changes:

  • Adds highlight parsing, rendering, formatting integration, and export support.
  • Adds a disabled-by-default preference with localized labels.
  • Adds regression tests and user documentation.
File Description
packages/​website/​content/​docs/​end-user/​MARKDOWN_SYNTAX.md Documents highlight syntax and opt-in behavior.
packages/​muya/​src/​utils/​marked/​types.ts Types the export option.
packages/​muya/​src/​utils/​marked/​options.ts Defaults highlight export off.
packages/​muya/​src/​utils/​marked/​getHighlightHtml.ts Enables highlight HTML export.
packages/​muya/​src/​utils/​marked/​getClipboardHtml.ts Enables highlight clipboard output.
packages/​muya/​src/​utils/​marked/​extensions/​mark.ts Adds the Marked highlight extension.
packages/​muya/​src/​types.ts Exposes the Muya option.
packages/​muya/​src/​state/​renderToStaticHTML.ts Forwards the static export option.
packages/​muya/​src/​state/​markdownToHtml.ts Forwards the editor export option.
packages/​muya/​src/​state/​getTOC.ts Includes highlighting in heading text parsing.
packages/​muya/​src/​state/​__tests__/​texMathDollarsToggle.spec.ts Updates tokenizer options.
packages/​muya/​src/​state/​__tests__/​renderToStaticHTML.spec.ts Tests highlight export toggling.
packages/​muya/​src/​state/​__tests__/​referenceLink.spec.ts Updates tokenizer options.
packages/​muya/​src/​inlineRenderer/​types.ts Defines highlight tokens and options.
packages/​muya/​src/​inlineRenderer/​rules.ts Adds the highlight matching rule.
packages/​muya/​src/​inlineRenderer/​renderer/​mark.ts Renders highlight tokens.
packages/​muya/​src/​inlineRenderer/​renderer/​index.ts Registers the highlight renderer.
packages/​muya/​src/​inlineRenderer/​renderer/​delEmStrongFactory.ts Supports mark wrappers.
packages/​muya/​src/​inlineRenderer/​lexer.ts Integrates highlight token handling.
packages/​muya/​src/​inlineRenderer/​__tests__/​texMathSingleBackslash.spec.ts Updates tokenizer options.
packages/​muya/​src/​inlineRenderer/​__tests__/​texMathGfmInline.spec.ts Updates tokenizer options.
packages/​muya/​src/​inlineRenderer/​__tests__/​texMathDoubleBackslash.spec.ts Updates tokenizer options.
packages/​muya/​src/​inlineRenderer/​__tests__/​markSyntax.spec.ts Tests highlight parsing and exports.
packages/​muya/​src/​inlineRenderer/​__tests__/​linkDestination.spec.ts Updates tokenizer options.
packages/​muya/​src/​inlineRenderer/​__tests__/​emphasisDelimiterRuns.spec.ts Updates tokenizer options.
packages/​muya/​src/​config/​index.ts Registers mark formatting and defaults.
packages/​muya/​src/​clipboard/​copyData.ts Passes highlighting to clipboard conversion.
packages/​muya/​src/​block/​base/​format.ts Handles highlight removal and offsets.
packages/​muya/​src/​block/​base/​__tests__/​formatToggle.spec.ts Tests highlight removal.
packages/​muya/​src/​__tests__/​setOptions.spec.ts Tests live highlight toggling.
packages/​desktop/​static/​locales/​zh-TW.json Adds Traditional Chinese labels.
packages/​desktop/​static/​locales/​zh-CN.json Adds Simplified Chinese labels.
packages/​desktop/​static/​locales/​tr.json Adds Turkish labels.
packages/​desktop/​static/​locales/​ru.json Adds Russian labels.
packages/​desktop/​static/​locales/​pt.json Adds Portuguese labels.
packages/​desktop/​static/​locales/​nl.json Adds Dutch labels.
packages/​desktop/​static/​locales/​ko.json Adds Korean labels.
packages/​desktop/​static/​locales/​ja.json Adds Japanese labels.
packages/​desktop/​static/​locales/​fr.json Adds French labels.
packages/​desktop/​static/​locales/​es.json Adds Spanish labels.
packages/​desktop/​static/​locales/​en.json Adds English labels.
packages/​desktop/​static/​locales/​de.json Adds German labels.
packages/​desktop/​src/​shared/​types/​preferences.ts Types the shared preference.
packages/​desktop/​src/​renderer/​src/​store/​preferences.ts Adds renderer preference state.
packages/​desktop/​src/​renderer/​src/​prefComponents/​markdown/​index.vue Adds the preference toggle.
packages/​desktop/​src/​renderer/​src/​components/​editorWithTabs/​editor.vue Applies initial and live settings.
packages/​desktop/​src/​main/​preferences/​schema.json Defines preference validation and default.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/desktop/src/main/preferences/schema.json
Comment thread packages/muya/src/block/base/format.ts Outdated
Comment thread packages/muya/src/inlineRenderer/lexer.ts Outdated
Comment thread packages/muya/src/utils/marked/extensions/mark.ts Outdated
Add highlightSyntax to the shipped default preference.json (the source that migrates new keys into existing user settings), the Preferences reference table and the muya feature list.
@Jocs
Jocs force-pushed the feat/highlight-syntax-2552 branch from 803cb57 to 0ce102e Compare October 7, 2026 13:19
Jocs added 2 commits October 7, 2026 21:29
The `==text==` rule keeps the escaped run before the closing marker in `token.backlash`, outside `children`. Formatting dropped it: `clearFormat` spliced only the children and `rebuildWrapperToken` reproduced just marker + children + marker, so toggling Highlight off or formatting anything else in the block deleted the literal backslashes. Both now re-emit `backlash` (this also fixes the same latent loss for strong/em/del).

The marked extension is aligned with the editor too: it rejects odd backslash runs (where the editor keeps the span literal) and feeds the run through the inline lexer so `\\` renders as the single backslash the editor shows.
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Build artifacts for PR #5647:

Run: https://github.com/marktext/marktext/actions/runs/37631386652

Artifact Size Link
marktext-macos-arm64 285.6 MB Download
marktext-linux 635.0 MB Download
marktext-windows-arm64 278.2 MB Download
marktext-macos-x64 296.0 MB Download
marktext-windows-x64 286.3 MB Download

@Jocs
Jocs merged commit b317901 into develop Oct 7, 2026
21 of 24 checks passed
@Jocs
Jocs deleted the feat/highlight-syntax-2552 branch October 7, 2026 14:09
Wangqkoe pushed a commit to Wangqkoe/marktext that referenced this pull request Oct 24, 2026
…#5647)

Picked with the highlightSyntax switch off by default, as upstream ships it.

Local changes to the pick:
- Restores the two outline spots removed when the outline inline-markdown
  port (80f49274) dropped highlight code: getTOC passes highlightSyntax to
  the tokenizer, and tokensToInlineHtml renders mark tokens. Adds back
  upstream's outline test and a test that == stays literal while off.
- The desktop watcher uses applyOutlineAffectingOption, so toggling the
  switch refreshes the outline like the other syntax options.
- Leaves out the softNewlineAsSpace option the upstream commit carried
  (not picked), and the nl/ru locales this fork does not ship.
- Keeps the local Japanese strings and preference table, adding only the
  new highlightSyntax entries; a local tokenizer test gets the new option.

(cherry picked from commit b317901)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

Support ==highlighting== syntax

2 participants