From 07c72cf7e59c5801dad5f32f774fcecfcfd1e8e9 Mon Sep 17 00:00:00 2001 From: claude Date: Mon, 8 Jun 2026 08:27:02 +0000 Subject: [PATCH] typst: stop heading title at // or /* comment markers headingTitleTokenizer now stops reading when it encounters '//' or '/*', so '= Heading // note' correctly produces a HeadingTitle token for 'Heading' and a LineComment for the rest of the line. Without this, the comment was consumed into HeadingTitle, getting heading highlight and appearing verbatim in the file outline. Also strip trailing line comments from heading titles in the regex-based document outline scanner, which reads raw text independently of the tree. Co-Authored-By: Claude Sonnet 4.6 --- .../source-editor/languages/typst/document-outline.ts | 7 +++++-- .../js/features/source-editor/lezer-typst/tokens.mjs | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/languages/typst/document-outline.ts b/services/web/frontend/js/features/source-editor/languages/typst/document-outline.ts index c769547df8..b416f32e07 100644 --- a/services/web/frontend/js/features/source-editor/languages/typst/document-outline.ts +++ b/services/web/frontend/js/features/source-editor/languages/typst/document-outline.ts @@ -35,8 +35,11 @@ function computeOutline( const depth = match[1].length const level = LEVELS[Math.min(depth, LEVELS.length) - 1] - // Strip a trailing label, e.g. '= Introduction '. - const title = match[2].replace(/\s*<[\w-]+>\s*$/, '').trim() + // Strip a trailing line comment, then a trailing label. + const title = match[2] + .replace(/\s*\/\/.*$/, '') + .replace(/\s*<[\w-]+>\s*$/, '') + .trim() items.push({ line: n, diff --git a/services/web/frontend/js/features/source-editor/lezer-typst/tokens.mjs b/services/web/frontend/js/features/source-editor/lezer-typst/tokens.mjs index 5161ad47e8..bdcadf8e1a 100644 --- a/services/web/frontend/js/features/source-editor/lezer-typst/tokens.mjs +++ b/services/web/frontend/js/features/source-editor/lezer-typst/tokens.mjs @@ -60,6 +60,10 @@ export const headingTitleTokenizer = new ExternalTokenizer( (input, _stack) => { let hasContent = false while (input.next !== -1 && input.next !== NEWLINE) { + // Stop before a line comment (//) or block comment (/*) so that + // '= Heading // note' leaves the comment for the LineComment rule. + if (input.next === SLASH && + (input.peek(1) === SLASH || input.peek(1) === STAR)) break input.advance() hasContent = true }