From 5b982ac2572caf3de0f81fc5724ab815554cc9df Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 10 Feb 2025 20:29:52 +0100 Subject: [PATCH] Fix syntax highlighting of Lua expressions that start with whitespace --- common/markdown_parser/parser.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/markdown_parser/parser.ts b/common/markdown_parser/parser.ts index 6d262a06..e79932f4 100644 --- a/common/markdown_parser/parser.ts +++ b/common/markdown_parser/parser.ts @@ -357,6 +357,9 @@ const LuaDirectives: MarkdownConfig = { // Let's parse as an expression const parsedExpression = luaLanguage.parser.parse(`_(${bodyText})`); + // If bodyText starts with whitespace, we need to offset this later + const whiteSpaceOffset = bodyText.match(/^\s*/)?.[0].length ?? 0; + const node = parsedExpression.resolveInner(2, 0).firstChild?.nextSibling ?.nextSibling; @@ -367,7 +370,7 @@ const LuaDirectives: MarkdownConfig = { "LuaExpressionDirective", pos + 2, endPos - 1, - [cx.elt(node.toTree()!, pos + 2)], + [cx.elt(node.toTree()!, pos + 2 + whiteSpaceOffset)], ); return cx.addElement(