export const INLINE_CODE_RE = /`([^`]+)`/g;
export const LINK_RE = /\[([^\]]+)\]\(([^)]+)\)/g;
export const BOLD_ASTERISK_RE = /\*\*(.+?)\*\*/g;
export const BOLD_UNDERSCORE_RE = /__(.+?)__/g;
export const ITALIC_ASTERISK_RE = /\*(.+?)\*/g;
export const ITALIC_UNDERSCORE_RE = /(?/g, ">")
.replace(/"/g, """);
}
function render_link(_match: string, text: string, url: string): string {
const trimmed = url.trim();
if (PROTOCOL_RE.test(trimmed)) {
if (/^https?:/i.test(trimmed)) {
return `${text}`;
}
return text;
}
return `${text}`;
}
export function render_inline_markdown(text: string): string {
let result = escape_html(text);
result = result.replace(INLINE_CODE_RE, "$1");
result = result.replace(LINK_RE, render_link);
result = result.replace(BOLD_ASTERISK_RE, "$1");
result = result.replace(BOLD_UNDERSCORE_RE, "$1");
result = result.replace(ITALIC_ASTERISK_RE, "$1");
result = result.replace(ITALIC_UNDERSCORE_RE, "$1");
result = result.replace(/\n/g, "
");
return result;
}