typst: stop heading title at // or /* comment markers
Build and Deploy Verso / deploy (push) Successful in 9m24s
Build and Deploy Verso / deploy (push) Successful in 9m24s
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 <intro>'.
|
||||
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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user