mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
fix(zalouser): handle quoted fenced code blocks
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user