Don't apply emphasis or links inside inline code spans - #48
jasonzondor wants to merge 3 commits into
Conversation
inlineMarkup() ran the bold, italic, and link regexes over the whole line without regard for backtick-delimited code spans, so text like `The_brown_fox` had "brown" styled as italic (and the caret skipped the underscores as if they were hidden markers). Collect the inline code-span ranges first and skip any emphasis or link match that overlaps one. Fixes omacom#47 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MfBmFxT8EkK9Aan5bSopm5
Rejecting every emphasis or link whose range overlaps a code span also rejects markup that merely encloses one. `_a `b` c_` lost its italics and `[see `code`](url)` stopped being a link, both of which worked before this branch. A code span makes its own contents literal; it does not make the text around it literal. Testing the two delimiter positions instead keeps the reported case fixed -- in `` `The_brown_fox` `` both underscores sit inside the code span -- while leaving enclosing markup alone. It also still rejects markup that straddles a boundary, as in `_a `b_ c` d_`, where the closing underscore is inside the code span and so is not a marker. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Now that emphasis may enclose a code span, the two passes overlap on the code span's own range, and setFormat replaces rather than merges -- Qt assigns the whole QTextCharFormat to every covered character. Running the code pass first meant the enclosing emphasis overwrote it, so `_a `b` c_` italicised the code span and dropped its background, which is the thing the issue asked to stop. Running it last makes the code styling win on exactly the nested range: `a ` and ` c` stay italic, `` `b` `` keeps the code background and is not italicised. The markers are untouched either way, because markup with a delimiter inside a code span is already rejected. The test reads the block layout's format ranges rather than asserting on spans, since this is about which pass wins where the two overlap. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-Authored-By: Codex XHigh <noreply@openai.com>
|
Reviewed, and the precedence rule needed one correction. I pushed two commits to this branch ( The overlap test was too wide.
Those three worked before the branch, so this was a regression rather than a case it merely failed to improve. It hit the caret too, not just the styling:
The code span then needed to win where emphasis encloses it. With enclosing emphasis restored, the two passes overlap on the code span's own range, and Tests: the repo's own Second opinion: Codex at xhigh reasoning reviewed this independently and reached the same conclusion about the predicate, naming Two things left, neither pushed. Both are pre-existing and neither is a regression, so they are yours or the maintainer's call rather than mine:
Heads-up on a collision: #15 adds a fourth pass to |
Handle closing fence lines in caret ranges and escaped opening backticks in inline parsing. Apply code styling after enclosing markup, as in PR omacom#48, so code retains its panel and literal appearance. Make Backend the sole source of code-panel colors, remove unused QML exposure, and clarify fence transitions. Cover the review cases with rendering, caret, escape, and theme reload regressions.

Problem
Text inside an inline code span (backticks) still had Markdown emphasis applied. Typing
`The_brown_fox`rendered "brown" in italics;`a **b**`bolded "b";`[x](y)`got link styling. The caret also skipped over the underscores/asterisks as if they were hidden markers.Fixes #47.
Cause
MarkdownHighlighter::inlineMarkup()is the single source of truth for inline spans (highlighter styling +Backend::hiddenRangesAtcaret skipping). It ran the bold/italic/link regexes over the entire line with no awareness of backtick-delimited code spans, andhighlightInline()applied those formats after the code format, overriding it.Fix
Collect inline code-span ranges first (same
`([^`]+)`pattern the highlighter already uses), then skip any emphasis/link match whose range overlaps a code span. Because the fix lives ininlineMarkup(), both the rendered styling and the caret-skip behaviour are corrected together.Tests
Added
ignoresInlineMarkdownInsideCodeSpanscovering underscores,**/[]()inside code, and a mixed line where real emphasis outside the code span is still detected. Full suite passes (qmake6 && make && QT_QPA_PLATFORM=offscreen ./tst_omawrite).🤖 Generated with Claude Code