Keep code literal and match its background to the theme - #2
scottjones wants to merge 4 commits into
Conversation
|
Reviewed both halves against the source and on a disposable VM. The theme half holds up under the checks I had doubts about. Three small things:
Unterminated fences behave correctly: every remaining block stays Heads up that PRs #5, #8, #15 and #17 all touch |
Resolved against PR omacom#34, which restructured loadOmarchyTheme() to parse into locals before applying: the new lighter_background key follows that shape, and the per-load reset moves down with it.
Resolved against PR omacom#34, which restructured loadOmarchyTheme() to parse into locals before applying: the new lighter_background key follows that shape, and the per-load reset moves down with it.
An identifier like `default_line_height` came out italic with its underscores hidden: the inline rules ran over the raw line, so every underscore between backticks looked like an emphasis marker. Collect the code spans first and drop any markup whose markers land inside one. Matching on the markers rather than the whole span keeps emphasis that merely wraps code, as in **bold with `code` inside**, intact. Underscores now also need a word boundary to open emphasis, the way CommonMark and GitHub read them, so snake_case_name is left alone in prose too. Asterisks still delimit anywhere, and Ctrl+B and Ctrl+I insert asterisks, so nothing changes for the toolbar. Both fixes live in inlineMarkup, the source the editor shares through Backend::hiddenRangesAt, so the caret stops skipping over underscores it should never have hidden. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Everything between a pair of ``` fences is literal, but the highlighter had no memory of where it stood, so a code block was read as prose: snake_case_name came out italic with its underscores hidden, and a comment opening a line was set as a bold heading. The editor already counted fences for smartReturn, so it knew what the highlighter did not. Carry the state from block to block instead. Inside a fence nothing is markup and no markers are hidden; the code sits on the same panel inline code gets, and the fences themselves recede the way a heading's `#` does. The state lives on the block, which is how Backend::hiddenRangesAt learns to stop skipping the caret over underscores in code. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Inline code and fenced blocks sat on a hardcoded #1c1a1a, a warm grey left over from before the editor followed the desktop. On the current theme it read as a smudge against a green page while every colour around it tracked the theme. Omarchy themes name a lighter background for panels exactly like this one, so use the shade the theme chose. Not every theme sets the key, and a few set it to the page background, which would leave code with no panel at all; those fall back to a shade mixed from the page towards the text. Mixing rather than lightening keeps the shade moving on a pure black background, and lands on the theme's own hue either way. Backend resolves the colour and publishes it, the way it already does for the page and the accent, so the highlighter is handed a colour to paint rather than a theme to interpret. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
1171cc7 to
bc1e2c0
Compare
Code containing Markdown characters was being styled as prose:
default_line_heightlost its underscores to italics,*value*inside a fenced block became emphasis, and the caret skipped visible characters as though they were hidden markup.Treat inline code and triple-backtick fenced blocks as literal text, using the same parsing for highlighting and caret movement. Preserve underscores inside identifiers in ordinary prose. Emphasis and links can still surround inline code, while the code keeps its own styling and background. Escaped opening backticks stay literal, and closing fence lines no longer report hidden markers.
Code backgrounds now use the Omarchy theme's
lighter_background. If that value is missing, invalid, or identical to the page background, Backend mixes the page color 6% toward the text color. This also works on pure black and white pages, and reloading a theme cannot retain the previous theme's panel color.Validation
8f98892).QT_QPA_PLATFORMTHEME=generic bin/test: 21 passed, 0 failed on Qt 6.11.2.bin/buildbuilds the application.The inline-code portion overlaps with #48 and includes the same code-last rendering order needed to preserve nested code styling. This PR also handles underscores in prose, fenced blocks, and theme-derived code backgrounds.
The existing parser remains limited to single-backtick inline spans and the editor's triple-backtick fence convention. Fence backgrounds are painted per character, so their right edges follow line lengths and empty lines have no panel.