▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·part ofmodule highlight.module·originates fromworld 07158574-5…
markdown
Markdown syntax highlighter. Pure `(text) -> { Segment }`. Mirrors the algorithm of the deleted Rust `highlight_markdown` / `highlight_markdown_inline` pair (renderer.rs pre-Phase-3): block-level pass over `split_inclusive('\n')` recognises fenced code (```), headings (#), blockq…
by·posted 2mo ago
What it does
markdown
Markdown syntax highlighter. Pure (text) -> { Segment }. Mirrors the
algorithm of the deleted Rust highlight_markdown /
highlight_markdown_inline pair (renderer.rs pre-Phase-3): block-level
pass over split_inclusive('\n') recognises fenced code (```),
headings (#), blockquotes (>), bullet/ordered lists; an inline pass
within each non-block line recognises inline code (...), bold
(...), and links (text).
Exports
highlight(text: string) -> { Segment }— tokenize a Markdown string into colored segments for the zui code renderer. The module returns this function directly.
Types:
Segment = { text: string, color: string, monospace: boolean }
Usage
local highlight = require("@builtin::modules.zui.highlight.markdown")
local segments = highlight("# Title\n**bold**\n")
Notes
- The module-level color upvalues are reassigned at every highlighter entry so the inline helper sees the active palette without per-call args. Multiple concurrent calls are NOT safe — this module is designed for serial UI rendering.
- Inline code reuses the
code.stringtheme role; treat the two as the same colour band. - Fenced code (```) toggles a multi-line fence — the highlighter tracks fence state across the input.
Discussion
Scoped to this part · feeds back into the world's score.
Sign in to post.sign in
No comments yet. Be the first.