fix: preserve markdown code fences
This commit is contained in:
@@ -459,11 +459,18 @@ export function markdownToIR(markdown: string, options: MarkdownParseOptions = {
|
|||||||
|
|
||||||
const trimmedText = state.text.trimEnd();
|
const trimmedText = state.text.trimEnd();
|
||||||
const trimmedLength = trimmedText.length;
|
const trimmedLength = trimmedText.length;
|
||||||
|
let codeBlockEnd = 0;
|
||||||
|
for (const span of state.styles) {
|
||||||
|
if (span.style !== "code_block") continue;
|
||||||
|
if (span.end > codeBlockEnd) codeBlockEnd = span.end;
|
||||||
|
}
|
||||||
|
const finalLength = Math.max(trimmedLength, codeBlockEnd);
|
||||||
|
const finalText = finalLength === state.text.length ? state.text : state.text.slice(0, finalLength);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
text: trimmedText,
|
text: finalText,
|
||||||
styles: mergeStyleSpans(clampStyleSpans(state.styles, trimmedLength)),
|
styles: mergeStyleSpans(clampStyleSpans(state.styles, finalLength)),
|
||||||
links: clampLinkSpans(state.links, trimmedLength),
|
links: clampLinkSpans(state.links, finalLength),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ function isAllowedSlackAngleToken(token: string): boolean {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapeSlackMrkdwnText(text: string): string {
|
function escapeSlackMrkdwnContent(text: string): string {
|
||||||
if (!text.includes("&") && !text.includes("<") && !text.includes(">")) {
|
if (!text.includes("&") && !text.includes("<") && !text.includes(">")) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
@@ -49,6 +49,22 @@ function escapeSlackMrkdwnText(text: string): string {
|
|||||||
return out.join("");
|
return out.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeSlackMrkdwnText(text: string): string {
|
||||||
|
if (!text.includes("&") && !text.includes("<") && !text.includes(">")) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
return text
|
||||||
|
.split("\n")
|
||||||
|
.map((line) => {
|
||||||
|
if (line.startsWith("> ")) {
|
||||||
|
return `> ${escapeSlackMrkdwnContent(line.slice(2))}`;
|
||||||
|
}
|
||||||
|
return escapeSlackMrkdwnContent(line);
|
||||||
|
})
|
||||||
|
.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
function buildSlackLink(link: MarkdownLinkSpan, text: string) {
|
function buildSlackLink(link: MarkdownLinkSpan, text: string) {
|
||||||
const href = link.href.trim();
|
const href = link.href.trim();
|
||||||
if (!href) return null;
|
if (!href) return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user