fix(typst): highlight idents after #keyword and wire tok-attributeName
Build and Deploy Verso / deploy (push) Successful in 9m34s

- codeIdentTokenizer: extend guard to scan back through the keyword word
  and accept when '#' immediately precedes it, so 'text' in '#set text(...)'
  and 'heading' in '#show heading:' are highlighted as function names
- classHighlighter: add tags.attributeName → tok-attributeName mapping;
  all 26 themes already define .tok-attributeName colours but the tag was
  never mapped to the class, leaving named arg keys (columns:, caption:)
  completely unstyled

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
claude
2026-06-09 09:18:31 +00:00
parent 1b773fdda0
commit 75bc3bcc73
2 changed files with 9 additions and 3 deletions
@@ -46,5 +46,6 @@ export const classHighlighter = tagHighlighter([
{ tag: tags.invalid, class: 'tok-invalid' }, { tag: tags.invalid, class: 'tok-invalid' },
{ tag: tags.punctuation, class: 'tok-punctuation' }, { tag: tags.punctuation, class: 'tok-punctuation' },
// additional // additional
{ tag: tags.attributeName, class: 'tok-attributeName' },
{ tag: tags.attributeValue, class: 'tok-attributeValue' }, { tag: tags.attributeValue, class: 'tok-attributeValue' },
]) ])
@@ -321,12 +321,17 @@ export const codeIdentTokenizer = new ExternalTokenizer(
if (!stack.canShift(CodeIdent)) return if (!stack.canShift(CodeIdent)) return
// Guard: only fire in code context. // Guard: only fire in code context.
// Walk back past whitespace (including newlines inside multi-line arg lists) // Walk back past whitespace to the nearest non-space character.
// to the nearest non-space character and check that it is a code-mode delimiter.
let back = -1 let back = -1
while (input.peek(back) === SPACE || input.peek(back) === TAB || input.peek(back) === NEWLINE) back-- while (input.peek(back) === SPACE || input.peek(back) === TAB || input.peek(back) === NEWLINE) back--
const prev = input.peek(back) const prev = input.peek(back)
if (prev !== HASH && prev !== DOT && prev !== OPEN_PAREN && prev !== COMMA) return if (prev !== HASH && prev !== DOT && prev !== OPEN_PAREN && prev !== COMMA) {
// May be after a keyword like '#set' or '#show': scan back through the
// keyword word itself and check that '#' immediately precedes it.
if (!isIdentTail(prev)) return
while (isIdentTail(input.peek(back))) back--
if (input.peek(back) !== HASH) return
}
// Must start with an identifier head character. // Must start with an identifier head character.
if (!isIdentHead(input.next)) return if (!isIdentHead(input.next)) return