Repository navigation
Syntect highlighting for template expression blocks - #1792
Conversation
Replace the accent-only body approach for {{ }} commands with the
cmd parameter approach using text placeholders. The terminal shortcode
template replaces placeholders back to real braces before Syntect
processes them, giving full multi-color highlighting.
Also fixes double-encoding of " in cmd parameters by using a
placeholder instead of ".
Co-Authored-By: Claude <[email protected]>
Tera has no backslash-escape mechanism for string literals, so \" doesn't work — we must use a placeholder for double quotes in cmd parameters. Co-Authored-By: Claude <[email protected]>
The table row for {{ }} blocks was stale — all $ commands now use the
cmd parameter path. Document the placeholder mechanism and why it's
needed (Tera has no backslash escaping).
Co-Authored-By: Claude <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
The core change in src/docs.rs and terminal.html is clean — unifying all blocks through the cmd parameter with placeholders is the right approach.
However, transform_docs_for_skill in readme_sync.rs doesn't fully handle the new format, causing issues in skills/worktrunk/reference/step.md:
1. Body-form shortcodes lose commands. ZOLA_TERMINAL_BODY_PATTERN strips {% terminal(cmd="...") %}...{% end %} and keeps only the body ($1). Previously the command was in the body as <span class="cmd">, but now it's in the cmd parameter — so it gets dropped. Several examples show only output with no command:
- "Get the port for the current branch:" → just
16066(line 435) - "Use conditionals and filters:" → just
feature_auth_oauth2_a1b(line 451) - "Show available template variables:" → just output lines (line 455)
2. Regex breaks on ) inside cmd values. See inline comment.
The fix would update ZOLA_TERMINAL_BODY_PATTERN to extract the cmd parameter and emit it as $ command in a code block before the body content, and use a ) -tolerant pattern like (?:[^)"]*|"[^"]*")*. Happy to push a fix commit if you'd like.
The body-form regex was dropping commands that moved from the body (as <span class="cmd">) to the cmd parameter. Now both body-form and self-closing patterns properly extract cmd values, split ||| delimiters, and emit $ -prefixed bash blocks. Also fixes the [^)]* regex that would break on ) inside cmd values. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
The previous review's issues are addressed — {{ }} commands now get full Syntect highlighting through the cmd parameter, and the regex no longer breaks on ) inside quoted values.
One remaining issue: body-form shortcodes that have both a cmd parameter and <span class="cmd"> in the body produce duplicate command lines in skill reference files (see inline comment).
Body-form shortcodes without a cmd parameter (hand-written docs) had raw <span class="cmd"> HTML leaking into skill reference files. Now these are converted to $ -prefixed lines in bash blocks. Also strip duplicate <span class="cmd"> from bodies that have both a cmd parameter and legacy span tags. Co-Authored-By: Claude <[email protected]>
Commands containing
{{ }}template expressions (e.g.,wt step eval '{{ branch | hash_port }}') were the only blocks that didn't get full Syntect highlighting on the docs site — they fell back to accent-only color because Tera would interpret{{ }}in thecmdparameter as template expressions.This uses text placeholders (
__WT_OPEN2__,__WT_CLOSE2__) that pass through Tera safely. The terminal shortcode template replaces them back to real braces before Syntect processes them. Also fixes double-encoding of"in cmd parameters (the old"was getting double-encoded by Syntect to&quot;), using a__WT_QUOT__placeholder for the same reason — Tera has no backslash-escape mechanism for string literals.The skill file generator (
transform_docs_for_skill) was updated to handle the new format: extractingcmdparameter values and|||delimiters into$-prefixed bash blocks, converting legacy<span class="cmd">body tags, and fixing the[^)]*regex that broke on)inside cmd values.Net effect: all code blocks on the docs site now have consistent multi-color Syntect highlighting, and skill reference files have clean
$ commandblocks instead of raw HTML.