diff --git a/extensions/zalouser/src/text-styles.test.ts b/extensions/zalouser/src/text-styles.test.ts index 1e17a433541..987667d1193 100644 --- a/extensions/zalouser/src/text-styles.test.ts +++ b/extensions/zalouser/src/text-styles.test.ts @@ -62,6 +62,20 @@ describe("parseZalouserTextStyles", () => { }); }); + it("treats quoted backtick fences as literal code blocks", () => { + expect(parseZalouserTextStyles("> ```js\n> *cmd*\n> ```")).toEqual({ + text: "*cmd*", + styles: [], + }); + }); + + it("treats quoted tilde fences as literal code blocks", () => { + expect(parseZalouserTextStyles("> ~~~\n> *cmd*\n> ~~~")).toEqual({ + text: "*cmd*", + styles: [], + }); + }); + it("keeps unmatched fences literal", () => { expect(parseZalouserTextStyles("```python")).toEqual({ text: "```python", diff --git a/extensions/zalouser/src/text-styles.ts b/extensions/zalouser/src/text-styles.ts index 82f4d96b278..093c9e2f23b 100644 --- a/extensions/zalouser/src/text-styles.ts +++ b/extensions/zalouser/src/text-styles.ts @@ -106,7 +106,8 @@ export function parseZalouserTextStyles(input: string): { text: string; styles: for (let lineIndex = 0; lineIndex < lines.length; lineIndex += 1) { let line = lines[lineIndex]; - let baseIndent = 0; + let { text: unquotedLine, indent: baseIndent } = stripQuotePrefix(line); + line = unquotedLine; const fence = parseFenceMarker(line); if (fence) { @@ -148,12 +149,6 @@ export function parseZalouserTextStyles(input: string): { text: string; styles: continue; } - const quoteMatch = line.match(/^(>+)\s?(.*)$/); - if (quoteMatch) { - baseIndent = Math.min(5, quoteMatch[1].length); - line = quoteMatch[2]; - } - const indentMatch = line.match(/^(\s+)(.*)$/); let indentLevel = 0; let content = line; @@ -295,13 +290,24 @@ function clampIndent(spaceCount: number): number { function hasClosingFence(lines: string[], startIndex: number, fence: FenceMarker): boolean { for (let index = startIndex; index < lines.length; index += 1) { - if (isClosingFence(lines[index], fence)) { + if (isClosingFence(stripQuotePrefix(lines[index]).text, fence)) { return true; } } return false; } +function stripQuotePrefix(line: string): { text: string; indent: number } { + const match = line.match(/^(>+)\s?(.*)$/); + if (!match) { + return { text: line, indent: 0 }; + } + return { + text: match[2], + indent: Math.min(5, match[1].length), + }; +} + function parseFenceMarker(line: string): FenceMarker | null { const match = line.match(/^([ ]{0,3})(`{3,}|~{3,})(.*)$/); if (!match) {