yasirme commited on
Commit
af9a3da
·
verified ·
1 Parent(s): c3aa7c6

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
- renderMath(elem) {
11
- let content = elem.innerHTML;
12
- MathJax.typesetPromise([elem])
13
- .then(() => {
14
-
15
- })
16
- .catch((err) => {
17
-
18
- });
19
- }
20
- renderText(elem){
21
- elem.innerHTML = elem.innerHTML.replace(/<br\s*\/?>/g, '\n');
22
- elem.innerHTML = elem.innerHTML.replace(/\*\*\*(.*?)\*\*\*/g, '<span class="heading">$1</span>');
23
- elem.innerHTML = elem.innerHTML.replace(/\*\*(.*?)\*\*/g, '<span class="subHeading">$1</span>');
24
- elem.innerHTML = elem.innerHTML.replace(/\n/g, '<br>');
25
- }
26
- renderCode(element) {
27
- let content = element.innerHTML;
28
- if (content.includes("```") && content.split("```").length >= 3) {
29
- content = content.replace(/```(\w*)<br>([\s\S]*?)```/g, (match, language, code) => {
30
- code = code.replace(/<br>/g, '\n').trim();
31
- language = language.trim() || 'text';
32
- return `<pre class="code-block"><code class="language-${language}">${code}</code></pre>`;
33
- });
34
-
35
- element.innerHTML = content;
36
- element.querySelectorAll('code:not(.hljs)').forEach(block => {
37
- hljs.highlightElement(block);
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