0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-03-27 12:28:11 +00:00

blocks working, spans and injections confused

This commit is contained in:
Víctor Losada Hernández
2026-03-23 12:13:55 +01:00
parent 4483537b93
commit c76b174fd6

View File

@@ -45,38 +45,27 @@ export function tokenizeCustomMarkdown(text) {
tokens.push({ line: lineNumber, type: customTags.definitionTerm }); tokens.push({ line: lineNumber, type: customTags.definitionTerm });
} }
// Track ranges already marked for injections // --- Injection `{…}` ---
const injectionRanges = []; const injectorRegex = /{(?=((?:[:=](?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"':={}\s]*)*))\1}/g;
let match;
if (line.includes("{") && line.includes("}")) { while ((match = injectorRegex.exec(lineText)) !== null) {
const regex = /{[^{}]*}/gm; tokens.push({
let match; line: lineNumber,
while ((match = regex.exec(line)) != null) { type: customTags.injection,
codeMirror?.markText( from: match.index,
{ line: lineNumber, ch: match.index }, to: match.index + match[0].length,
{ line: lineNumber, ch: match.index + match[0].length }, });
{ className: "injection" },
);
injectionRanges.push([match.index, match.index + match[0].length]);
}
} }
// Now mark inline blocks, but skip overlapping injection ranges // --- Inline block `{{…}}` on the same line ---
if (line.includes("{{") && line.includes("}}")) { const inlineRegex = /{{(?=((?:[:=](?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"':={}\s]*)*))\1 *}}/g;
const regex = /{{[^{}]*}}/gm; while ((match = inlineRegex.exec(lineText)) !== null) {
let match; tokens.push({
while ((match = regex.exec(line)) != null) { line: lineNumber,
const start = match.index, type: customTags.inlineBlock,
end = match.index + match[0].length; from: match.index,
const overlaps = injectionRanges.some(([iStart, iEnd]) => start < iEnd && end > iStart); to: match.index + match[0].length,
if (!overlaps) { });
codeMirror?.markText(
{ line: lineNumber, ch: start },
{ line: lineNumber, ch: end },
{ className: "inline-block" },
);
}
}
} }
// --- Multi-line blocks `{{…}}` --- only start/end lines // --- Multi-line blocks `{{…}}` --- only start/end lines
@@ -89,6 +78,8 @@ export function tokenizeCustomMarkdown(text) {
tokens.push({ line: lineNumber, type: customTags.block }); tokens.push({ line: lineNumber, type: customTags.block });
inBlock = false; inBlock = false;
} }
}); });
return tokens; return tokens;