Spaces:
Running
Running
Update application/static/js/components/renderSymbols.js
Browse files
application/static/js/components/renderSymbols.js
CHANGED
@@ -1,43 +1,44 @@
|
|
1 |
-
class RenderSymbols{
|
2 |
-
constructor(){
|
3 |
-
|
4 |
-
}
|
5 |
-
renderAll(elem){
|
6 |
-
this.renderText(elem);
|
7 |
-
this.renderCode(elem);
|
8 |
-
this.renderMath(elem)
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
elem.innerHTML = elem.innerHTML.replace(
|
23 |
-
elem.innerHTML = elem.innerHTML.replace(
|
24 |
-
elem.innerHTML = elem.innerHTML.replace(
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
element.
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
43 |
export default RenderSymbols
|
|
|
1 |
+
class RenderSymbols{
|
2 |
+
constructor(){
|
3 |
+
|
4 |
+
}
|
5 |
+
renderAll(elem){
|
6 |
+
this.renderText(elem);
|
7 |
+
this.renderCode(elem);
|
8 |
+
this.renderMath(elem);
|
9 |
+
elem.scrollIntoView({behavior: "smooth", block: "end"});
|
10 |
+
}
|
11 |
+
renderMath(elem) {
|
12 |
+
let content = elem.innerHTML;
|
13 |
+
MathJax.typesetPromise([elem])
|
14 |
+
.then(() => {
|
15 |
+
|
16 |
+
})
|
17 |
+
.catch((err) => {
|
18 |
+
|
19 |
+
});
|
20 |
+
}
|
21 |
+
renderText(elem){
|
22 |
+
elem.innerHTML = elem.innerHTML.replace(/<br\s*\/?>/g, '\n');
|
23 |
+
elem.innerHTML = elem.innerHTML.replace(/\*\*\*(.*?)\*\*\*/g, '<span class="heading">$1</span>');
|
24 |
+
elem.innerHTML = elem.innerHTML.replace(/\*\*(.*?)\*\*/g, '<span class="subHeading">$1</span>');
|
25 |
+
elem.innerHTML = elem.innerHTML.replace(/\n/g, '<br>');
|
26 |
+
}
|
27 |
+
renderCode(element) {
|
28 |
+
let content = element.innerHTML;
|
29 |
+
if (content.includes("```") && content.split("```").length >= 3) {
|
30 |
+
content = content.replace(/```(\w*)<br>([\s\S]*?)```/g, (match, language, code) => {
|
31 |
+
code = code.replace(/<br>/g, '\n').trim();
|
32 |
+
language = language.trim() || 'text';
|
33 |
+
return `<pre class="code-block"><code class="language-${language}">${code}</code></pre>`;
|
34 |
+
});
|
35 |
+
|
36 |
+
element.innerHTML = content;
|
37 |
+
element.querySelectorAll('code:not(.hljs)').forEach(block => {
|
38 |
+
hljs.highlightElement(block);
|
39 |
+
});
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
}
|
44 |
export default RenderSymbols
|