FrederickSundeep commited on
Commit
5fdb7b1
Β·
1 Parent(s): d63b07e

commit 000396

Browse files
Files changed (2) hide show
  1. static/style.css +0 -2
  2. templates/index.html +29 -20
static/style.css CHANGED
@@ -232,8 +232,6 @@ pre[class*="language-"] {
232
  white-space: pre-wrap !important;
233
  word-break: break-word;
234
  overflow-x: auto;
235
- padding: 1em;
236
- border-radius: 8px;
237
  }
238
 
239
 
 
232
  white-space: pre-wrap !important;
233
  word-break: break-word;
234
  overflow-x: auto;
 
 
235
  }
236
 
237
 
templates/index.html CHANGED
@@ -67,7 +67,7 @@
67
  python: ['def ', 'print(', 'import ', 'class '],
68
  javascript: ['function ', 'console.log(', 'let ', 'const ', 'document.getElementById'],
69
  typescript: ['interface ', 'type ', 'let ', 'const ', ': string', ': number'],
70
- java: ['public class', 'System.out', 'void main(', 'new Scanner'],
71
  c: ['#include <stdio.h>', 'printf(', 'scanf(', 'int main('],
72
  cpp: ['#include', 'std::', 'cout <<', 'cin >>'],
73
  bash: ['#!/bin/bash', 'echo ', 'cd ', 'ls', 'pwd'],
@@ -96,7 +96,7 @@ const detectLanguageByKeywords = (code) => {
96
 
97
  const renderCode = (text) => {
98
  const codeBlocks = text.split(/```/);
99
- let output = '';
100
 
101
  for (let i = 0; i < codeBlocks.length; i++) {
102
  if (i % 2 === 1) {
@@ -109,29 +109,38 @@ const renderCode = (text) => {
109
  langGuess = detectLanguageByKeywords(rawCode);
110
  }
111
 
112
- const escapedCode = rawCode
113
- .replace(/&/g, "&amp;")
114
- .replace(/</g, "&lt;")
115
- .replace(/>/g, "&gt;");
116
-
117
- output += `
118
- <div class="code-block-wrapper">
119
- <div class="language-label">${langGuess.toUpperCase() || 'CODE'}</div>
120
- <button class="copy-btn" onclick="copyToClipboard(\`${rawCode.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$/g, '\\$')}\`, this)">
121
- <span class="material-icons">content_copy</span>
122
- </button>
123
- <pre class="line-numbers language-${langGuess}"><code class="language-${langGuess}">${escapedCode}</code></pre>
124
- </div>
125
- `;
 
 
 
 
 
 
 
 
126
  } else {
127
- output += `<div class="text-content">${formatText(codeBlocks[i])}</div>`;
 
 
 
128
  }
129
  }
130
 
131
- // highlight all new code blocks
132
  nextTick(() => Prism.highlightAll());
133
-
134
- return output;
135
  };
136
 
137
 
 
67
  python: ['def ', 'print(', 'import ', 'class '],
68
  javascript: ['function ', 'console.log(', 'let ', 'const ', 'document.getElementById'],
69
  typescript: ['interface ', 'type ', 'let ', 'const ', ': string', ': number'],
70
+ java: ['import java.', 'ArrayList<', 'System.out', 'void main(', 'public class', 'new '],
71
  c: ['#include <stdio.h>', 'printf(', 'scanf(', 'int main('],
72
  cpp: ['#include', 'std::', 'cout <<', 'cin >>'],
73
  bash: ['#!/bin/bash', 'echo ', 'cd ', 'ls', 'pwd'],
 
96
 
97
  const renderCode = (text) => {
98
  const codeBlocks = text.split(/```/);
99
+ let container = document.createElement('div');
100
 
101
  for (let i = 0; i < codeBlocks.length; i++) {
102
  if (i % 2 === 1) {
 
109
  langGuess = detectLanguageByKeywords(rawCode);
110
  }
111
 
112
+ const wrapper = document.createElement('div');
113
+ wrapper.className = 'code-block-wrapper';
114
+
115
+ const label = document.createElement('div');
116
+ label.className = 'language-label';
117
+ label.textContent = langGuess.toUpperCase() || 'CODE';
118
+
119
+ const button = document.createElement('button');
120
+ button.className = 'copy-btn';
121
+ button.innerHTML = `<span class="material-icons">content_copy</span>`;
122
+ button.onclick = () =>
123
+ copyToClipboard(rawCode, button);
124
+
125
+ const pre = document.createElement('pre');
126
+ pre.className = `line-numbers language-${langGuess}`;
127
+ const code = document.createElement('code');
128
+ code.className = `language-${langGuess}`;
129
+ code.textContent = rawCode;
130
+
131
+ pre.appendChild(code);
132
+ wrapper.append(label, button, pre);
133
+ container.appendChild(wrapper);
134
  } else {
135
+ const textDiv = document.createElement('div');
136
+ textDiv.className = 'text-content';
137
+ textDiv.innerHTML = formatText(codeBlocks[i]);
138
+ container.appendChild(textDiv);
139
  }
140
  }
141
 
 
142
  nextTick(() => Prism.highlightAll());
143
+ return container.innerHTML;
 
144
  };
145
 
146