Remove markdown to HTML conversion function
This commit is contained in:
@@ -564,70 +564,6 @@ window.addEventListener('DOMContentLoaded', async () => {
|
||||
setActionLinksDisabled(isLoading);
|
||||
}
|
||||
|
||||
function markdownToHTML(text) {
|
||||
text = text.replace(/<\/think(?:ing)?>[^\S\n]*\n+[^\S\n]*/gi, '</think>');
|
||||
text = text.replace(
|
||||
/(^|\n)\s*<think>[\s\S]*?<\/think(?:ing)?>\s*(\n\s*\n)?/gi,
|
||||
(_, lead) => (lead ? '\n' : '')
|
||||
);
|
||||
|
||||
let tmp = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
||||
tmp = tmp.replace(
|
||||
/(^|\n)\s*<think>[\s\S]*?<\/think(?:ing)?>\s*(?=\n|$)/gi,
|
||||
(_, lead) => (lead ? '\n' : '')
|
||||
);
|
||||
|
||||
const codeblocks = [];
|
||||
const placeholder = idx => `@@CODEBLOCK${idx}@@`;
|
||||
tmp = tmp.replace(/```([\s\S]*?)```/g, (_, code) => {
|
||||
codeblocks.push(code);
|
||||
return placeholder(codeblocks.length - 1);
|
||||
});
|
||||
|
||||
let escaped = tmp
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
|
||||
escaped = escaped
|
||||
.replace(/^#### (.+)$/gm, '<h4>$1</h4>')
|
||||
.replace(/^### (.+)$/gm, '<h3>$1</h3>')
|
||||
.replace(/^## (.+)$/gm, '<h2>$1</h2>')
|
||||
.replace(/^# (.+)$/gm, '<h1>$1</h1>');
|
||||
|
||||
escaped = escaped.replace(/^---$/gm, '<hr>');
|
||||
|
||||
escaped = escaped.replace(
|
||||
/(^|\n)([ \t]*\* .+(?:\n[ \t]*\* .+)*)/g,
|
||||
(_, lead, listBlock) => {
|
||||
const items = listBlock
|
||||
.split(/\n/)
|
||||
.map(line => line.replace(/^[ \t]*\*\s+/, '').trim())
|
||||
.map(item => `<li>${item}</li>`)
|
||||
.join('');
|
||||
return `${lead}<ul>${items}</ul>`;
|
||||
}
|
||||
);
|
||||
|
||||
let html = escaped
|
||||
.replace(/\*\*(.+?)\*\*/g, '<b>$1</b>')
|
||||
.replace(/(?<!\*)\*(.+?)\*(?!\*)/g, '<i>$1</i>')
|
||||
.replace(/`(.+?)`/g, '<code>$1</code>');
|
||||
|
||||
html = html.replace(/@@CODEBLOCK(\d+)@@/g, (_, idx) => {
|
||||
const code = codeblocks[Number(idx)];
|
||||
return `<pre><code>${code}</code></pre>`;
|
||||
});
|
||||
|
||||
html = html.replace(/\n*(<h[1-3]>.*?<\/h[1-3]>)\n*/g, '$1\n');
|
||||
html = html.replace(/\n/g, '<br>');
|
||||
html = html
|
||||
.replace(/<br>\s*(<h[1-3]>)/g, '$1')
|
||||
.replace(/(<\/h[1-3]>)\s*<br>/g, '$1');
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
function setActionLinksDisabled(disabled) {
|
||||
document.querySelectorAll('.entry-icon-button').forEach(button => {
|
||||
if (disabled) {
|
||||
|
||||
Reference in New Issue
Block a user