mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-26 11:12:53 +00:00
fix(markdown): normalize HTML following code elements
This commit is contained in:
@@ -85,15 +85,11 @@ export function normalizeMarkdownHtml(source: string): string {
|
||||
// Inline HTML code has separate opening/closing AST nodes. Convert the pair
|
||||
// together so its contents keep backslashes and get a safe backtick delimiter.
|
||||
const code = /^<code\b[^>]*>[\s\S]*?<\/code\s*>/i.exec(source.slice(range.start));
|
||||
if (code) {
|
||||
result += convert(code[0], range.start);
|
||||
cursor = range.start + code[0].length;
|
||||
} else {
|
||||
result += source
|
||||
.slice(range.start, range.end)
|
||||
.replace(HTML, (raw, offset) => convert(raw, range.start + offset));
|
||||
cursor = range.end;
|
||||
}
|
||||
const end = code ? Math.max(range.end, range.start + code[0].length) : range.end;
|
||||
result += source
|
||||
.slice(range.start, end)
|
||||
.replace(HTML, (raw, offset) => convert(raw, range.start + offset));
|
||||
cursor = end;
|
||||
}
|
||||
return result + source.slice(cursor);
|
||||
}
|
||||
|
||||
@@ -328,3 +328,10 @@ it("keeps paragraph, heading and table-row boundaries when stripping HTML", () =
|
||||
const rendered = prepareMarkdownSource(source).render();
|
||||
expect(rendered).toBe("First\n\nSecond \nline\n\nHeading\n\nA B\n\nC D");
|
||||
});
|
||||
|
||||
it("normalizes images following HTML code in the same HTML block", () => {
|
||||
const prepared = prepareMarkdownSource('<code>\nx\n</code>\n<img src="shot.png">');
|
||||
expect(prepared.images.map((image) => image.source)).toEqual(["shot.png"]);
|
||||
expect(prepared.render(new Map([["shot.png", "blob:shot"]]))).toContain("");
|
||||
expect(prepared.render()).toContain("`\nx\n`");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user