Spaces:
Runtime error
Runtime error
Commit Β·
bb16f9b
1
Parent(s): 4d2b5bf
commit 000379
Browse files- static/style.css +22 -0
- templates/index.html +15 -15
static/style.css
CHANGED
|
@@ -197,4 +197,26 @@
|
|
| 197 |
white-space: pre-wrap;
|
| 198 |
}
|
| 199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
|
|
|
| 197 |
white-space: pre-wrap;
|
| 198 |
}
|
| 199 |
|
| 200 |
+
.code-block-wrapper {
|
| 201 |
+
position: relative;
|
| 202 |
+
margin: 16px 0;
|
| 203 |
+
border-radius: 8px;
|
| 204 |
+
overflow: hidden;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
.language-label {
|
| 208 |
+
position: absolute;
|
| 209 |
+
top: 8px;
|
| 210 |
+
left: 12px;
|
| 211 |
+
background: #333;
|
| 212 |
+
color: #fff;
|
| 213 |
+
font-size: 12px;
|
| 214 |
+
padding: 2px 8px;
|
| 215 |
+
border-radius: 4px;
|
| 216 |
+
z-index: 1;
|
| 217 |
+
pointer-events: none;
|
| 218 |
+
opacity: 0.85;
|
| 219 |
+
font-family: monospace;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
|
templates/index.html
CHANGED
|
@@ -69,26 +69,26 @@
|
|
| 69 |
for (let i = 0; i < codeBlocks.length; i++) {
|
| 70 |
if (i % 2 === 1) {
|
| 71 |
const lines = codeBlocks[i].split('\n');
|
| 72 |
-
const langGuess = /^[a-zA-Z]+$/.test(lines[0]) ? lines[0] : '';
|
| 73 |
const codeLines = langGuess ? lines.slice(1) : lines;
|
|
|
|
| 74 |
|
| 75 |
const highlightedBlock = langGuess
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
const numberedLines = highlightedBlock
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
const rawCode = codeLines.join('\n');
|
| 89 |
|
| 90 |
output += `
|
| 91 |
-
<div class="code-block">
|
|
|
|
| 92 |
<button class="copy-btn" onclick="copyToClipboard(\`${rawCode.replace(/\\/g, '\\\\').replace(/`/g, '\\`')}\`, this)">Copy</button>
|
| 93 |
<pre><code class="hljs">${numberedLines}</code></pre>
|
| 94 |
</div>
|
|
|
|
| 69 |
for (let i = 0; i < codeBlocks.length; i++) {
|
| 70 |
if (i % 2 === 1) {
|
| 71 |
const lines = codeBlocks[i].split('\n');
|
| 72 |
+
const langGuess = /^[a-zA-Z]+$/.test(lines[0]) ? lines[0].trim() : '';
|
| 73 |
const codeLines = langGuess ? lines.slice(1) : lines;
|
| 74 |
+
const rawCode = codeLines.join('\n');
|
| 75 |
|
| 76 |
const highlightedBlock = langGuess
|
| 77 |
+
? hljs.highlight(rawCode, { language: langGuess, ignoreIllegals: true }).value
|
| 78 |
+
: hljs.highlightAuto(rawCode).value;
|
| 79 |
+
|
| 80 |
+
const numberedLines = highlightedBlock
|
| 81 |
+
.split('\n')
|
| 82 |
+
.map((line, i) => `
|
| 83 |
+
<div class="code-line">
|
| 84 |
+
<span class="line-number">${i + 1}</span>
|
| 85 |
+
<span class="line-content">${line || ' '}</span>
|
| 86 |
+
</div>
|
| 87 |
+
`).join('');
|
|
|
|
|
|
|
| 88 |
|
| 89 |
output += `
|
| 90 |
+
<div class="code-block-wrapper">
|
| 91 |
+
<div class="language-label">${langGuess || 'Code'}</div>
|
| 92 |
<button class="copy-btn" onclick="copyToClipboard(\`${rawCode.replace(/\\/g, '\\\\').replace(/`/g, '\\`')}\`, this)">Copy</button>
|
| 93 |
<pre><code class="hljs">${numberedLines}</code></pre>
|
| 94 |
</div>
|