Skip to content

Syntect highlighting for template expression blocks - #1792

Merged
max-sixty merged 6 commits into
mainfrom
more-color
Mar 29, 2026
Merged

max-sixty merged 6 commits into
mainfrom
more-color

Conversation

@max-sixty

@max-sixty max-sixty commented Mar 29, 2026 •

Copy link
Copy Markdown
Owner

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 the cmd parameter 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 "), 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: extracting cmd parameter 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 $ command blocks instead of raw HTML.

This was written by Claude Code on behalf of @max-sixty

max-sixty and others added 4 commits March 29, 2026 10:20
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 &quot;.

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 worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread skills/worktrunk/reference/step.md Resolved
Comment thread tests/integration_tests/readme_sync.rs Resolved
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 worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread tests/integration_tests/readme_sync.rs Resolved
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]>
@max-sixty
max-sixty merged commit bd9b9fe into main Mar 29, 2026
23 checks passed
@max-sixty
max-sixty deleted the more-color branch March 29, 2026 22:04
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.

2 participants