mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-27 11:42:52 +00:00
fix(markdown): preserve literal image fallback labels
This commit is contained in:
@@ -335,3 +335,16 @@ it("normalizes images following HTML code in the same HTML block", () => {
|
||||
expect(prepared.render(new Map([["shot.png", "blob:shot"]]))).toContain("");
|
||||
expect(prepared.render()).toContain("`\nx\n`");
|
||||
});
|
||||
|
||||
it("preserves literal Markdown punctuation in unsupported and failed image labels", () => {
|
||||
const label = String.raw`\*literal\* \[label\]`;
|
||||
expect(
|
||||
prepareMarkdownSource(``, undefined, { supportsSvg: false }).render(),
|
||||
).toBe(label);
|
||||
expect(
|
||||
prepareMarkdownSource(``).render(
|
||||
new Map(),
|
||||
new Set(["https://example.com/badge.png"]),
|
||||
),
|
||||
).toBe(label);
|
||||
});
|
||||
|
||||
@@ -90,7 +90,7 @@ export function prepareMarkdownSource(
|
||||
options.supportsSvg === false &&
|
||||
/(?:\.svg(?:[?#]|$)|^data:image\/svg\+xml)/i.test(target.url)
|
||||
) {
|
||||
edits.push({ start, end, text: node.alt ?? "" });
|
||||
edits.push({ start, end, text: escapeMarkdownText(node.alt ?? "") });
|
||||
return;
|
||||
}
|
||||
if (target)
|
||||
@@ -153,7 +153,7 @@ export function prepareMarkdownSource(
|
||||
end: image.end,
|
||||
text: url
|
||||
? `![${image.alt.replace(/[[\]\\]/g, "\\$&")}](<${url}>${image.title ? ` ${JSON.stringify(image.title)}` : ""})`
|
||||
: image.alt,
|
||||
: escapeMarkdownText(image.alt),
|
||||
});
|
||||
}
|
||||
let result = source;
|
||||
@@ -164,3 +164,7 @@ export function prepareMarkdownSource(
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function escapeMarkdownText(text: string): string {
|
||||
return text.replace(/[!-/:-@[-`{-~]/g, "\\$&");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user