class RenderSymbols{
constructor(){
}
renderAll(elem){
this.renderText(elem);
this.renderCode(elem);
this.renderMath(elem)
}
renderMath(elem) {
let content = elem.innerHTML;
MathJax.typesetPromise([elem])
.then(() => {
})
.catch((err) => {
});
}
renderText(elem){
elem.innerHTML = elem.innerHTML.replace(/
/g, '\n');
elem.innerHTML = elem.innerHTML.replace(/\*\*\*(.*?)\*\*\*/g, '$1');
elem.innerHTML = elem.innerHTML.replace(/\*\*(.*?)\*\*/g, '$1');
elem.innerHTML = elem.innerHTML.replace(/\n/g, '
');
}
renderCode(element) {
let content = element.innerHTML;
if (content.includes("```") && content.split("```").length >= 3) {
content = content.replace(/```(\w*)
([\s\S]*?)```/g, (match, language, code) => {
code = code.replace(/
/g, '\n').trim();
language = language.trim() || 'text';
return `
${code}
`;
});
element.innerHTML = content;
element.querySelectorAll('code:not(.hljs)').forEach(block => {
hljs.highlightElement(block);
});
}
}
}
export default RenderSymbols