diff --git a/services/web/frontend/js/features/source-editor/lezer-typst/typst.grammar b/services/web/frontend/js/features/source-editor/lezer-typst/typst.grammar index f7e05a5ba3..f2ee06cb71 100644 --- a/services/web/frontend/js/features/source-editor/lezer-typst/typst.grammar +++ b/services/web/frontend/js/features/source-editor/lezer-typst/typst.grammar @@ -222,7 +222,11 @@ Escape { "\\" EscapeChar } // "(" > "." > "]" > text tokens: after '#' CodeIdent, callSuffix delimiters // must win over MarkupContent/StrongText/EmphText in merged states. // LineCommentContent and MathContent are external tokens — not listed here. - @precedence { CodeKeyword CodeBool CodeIdent EscapeChar "(" "." "]" spaces MarkupContent StrongText EmphText } + // "_" added after CodeIdent: KeywordExpr { CodeKeyword CallExpr? } merges + // the post-keyword state with markup states where "_" starts Emphasis. + // CodeIdent wins so '#set _name(...)' is tokenised correctly; in pure markup + // states CodeIdent is not in the valid set so "_" still opens Emphasis. + @precedence { CodeKeyword CodeBool CodeIdent EscapeChar "(" "." "]" "_" spaces MarkupContent StrongText EmphText } } @skip { spaces }