Fix syntax highlighting of Lua expressions that start with whitespace

pull/1219/merge
Zef Hemel 2025-02-10 20:29:52 +01:00
parent 8e8acbb470
commit 5b982ac257
1 changed files with 4 additions and 1 deletions

View File

@ -357,6 +357,9 @@ const LuaDirectives: MarkdownConfig = {
// Let's parse as an expression // Let's parse as an expression
const parsedExpression = luaLanguage.parser.parse(`_(${bodyText})`); 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 const node = parsedExpression.resolveInner(2, 0).firstChild?.nextSibling
?.nextSibling; ?.nextSibling;
@ -367,7 +370,7 @@ const LuaDirectives: MarkdownConfig = {
"LuaExpressionDirective", "LuaExpressionDirective",
pos + 2, pos + 2,
endPos - 1, endPos - 1,
[cx.elt(node.toTree()!, pos + 2)], [cx.elt(node.toTree()!, pos + 2 + whiteSpaceOffset)],
); );
return cx.addElement( return cx.addElement(