Skip to content

Introduces optional syntax highlighting#74

Open
LiquidityC wants to merge 1 commit intoCanop:mainfrom
LiquidityC:feature/optional_syntax_highlighting
Open

Introduces optional syntax highlighting#74
LiquidityC wants to merge 1 commit intoCanop:mainfrom
LiquidityC:feature/optional_syntax_highlighting

Conversation

@LiquidityC
Copy link
Copy Markdown

Allows syntax highlighting to configured in the MadSkin by a caller
allow for custom syntax highlighting. Eg. through Syntext or a custom
function.

Fixes: #1

Allows syntax highlighting to configured in the MadSkin by a caller
allow for custom syntax highlighting. Eg. through Syntext or a custom
function.

Fixes: Canop#1
@Canop
Copy link
Copy Markdown
Owner

Canop commented Feb 27, 2026

This isn't a trivial change, I'll have a look and review it but it won't be immediate.

Repository owner deleted a comment from magikRUKKOLA Mar 2, 2026
@Canop
Copy link
Copy Markdown
Owner

Canop commented Mar 23, 2026

Storing an optional reference to an highlighter in the skin looks right (the highlighter could probably be a trait, though).

I'm not thrilled by having the lang code carried by the FmtComposite and by having the FmtLine holding the already rendered line.
Is there a reason you didn't do the rendering when writing (i.e. in write_fmt_line) ?

@LiquidityC
Copy link
Copy Markdown
Author

Thanks for taking a look at this!

On the code_lang field: I don't see a way to avoid it given the flat Vec<FmtLine> architecture. By the time highlighting runs, all CodeFence lines have been discarded, so the language tag has to be attached to the surviving code lines somehow. I can't see any obvious alternative here without introducing larger changes. Such as introducing a FmtLine::CodeBlock { lang: Option<String>, Vec<FmtComposite> }

On rendering in write_fmt_line instead of as a pre-pass: the obstacle is that most highlighters need the full block as context (multi-line strings, block comments, etc.), but write_fmt_line only sees one line at a time. Two paths I see:

  • Line-by-line highlighting: simplifies the code significantly, but loses cross-line context — incorrect highlighting for anything spanning multiple lines. Eg. Comments.
  • A FmtLine::CodeBlock variant that groups all lines of a block together with the language tag, letting write_fmt_line highlight the whole block at once. This also solves the code_lang-on-FmtComposite concern, but write_fmt_line would then emit a variable number of newlines per FmtLine, which changes its semantics.

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 for syntax highlighting

2 participants