Skip to content

Commit 8994082

Browse files
committed
Improve: Better formatting for markdown and code files
- Configure marked.js with GFM and line breaks for better markdown rendering - Add DOMPurify for sanitizing markdown HTML output - Improve code block styling: better font size (13px), line height (1.6), word wrapping - Add word-wrap and overflow-wrap to markdown and code containers - Improve markdown word wrapping and layout - Better color contrast and readability for code blocks
1 parent 91c519a commit 8994082

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

docs/app.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ const state = {
88
useLocalContent: false,
99
};
1010

11+
// Configure marked for better markdown rendering
12+
if (window.marked) {
13+
window.marked.setOptions({
14+
breaks: true,
15+
gfm: true,
16+
});
17+
}
18+
1119
const treeRoot = document.getElementById("treeRoot");
1220
const codeBlock = document.getElementById("codeBlock");
1321
const codeContainer = document.getElementById("codeContainer");
@@ -170,7 +178,8 @@ async function loadFile(path, meta = {}) {
170178
const text = await response.text();
171179
if (languageClass === "markdown" && window.marked) {
172180
const html = window.marked.parse(text);
173-
markdownContent.innerHTML = html;
181+
const sanitized = window.DOMPurify ? window.DOMPurify.sanitize(html) : html;
182+
markdownContent.innerHTML = sanitized;
174183
markdownContent.classList.remove("hidden");
175184
imageContent.classList.add("hidden");
176185
codeContainer.classList.add("hidden");

docs/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
6868
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/12.0.1/marked.min.js"></script>
69+
<script src="https://cdn.jsdelivr.net/npm/dompurify@3.0.6/dist/purify.min.js"></script>
6970
<script src="app.js"></script>
7071
</body>
7172
</html>

docs/styles.css

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,26 @@ pre {
265265
background: #fdf9f2;
266266
border: 1px solid rgba(31, 27, 22, 0.12);
267267
font-family: "Spline Sans Mono", monospace;
268-
font-size: 14px;
269-
line-height: 1.85;
268+
font-size: 13px;
269+
line-height: 1.6;
270270
letter-spacing: 0.1px;
271271
tab-size: 2;
272272
overflow-x: auto;
273+
color: #2d241d;
273274
}
274275

275276
code {
276-
white-space: pre;
277+
white-space: pre-wrap;
278+
word-wrap: break-word;
279+
font-family: "Spline Sans Mono", monospace;
280+
}
281+
282+
#codeContainer {
283+
margin: 0;
284+
padding: 24px;
285+
border-radius: 16px;
286+
background: #fdf9f2;
287+
border: 1px solid rgba(31, 27, 22, 0.12);
277288
}
278289

279290
.code-lines {
@@ -315,9 +326,11 @@ code {
315326
border: 1px solid rgba(31, 27, 22, 0.12);
316327
border-radius: 16px;
317328
padding: 28px;
318-
line-height: 1.85;
329+
line-height: 1.8;
319330
font-size: 15px;
320331
color: var(--text);
332+
word-wrap: break-word;
333+
overflow-wrap: break-word;
321334
}
322335

323336
.markdown h1,

0 commit comments

Comments
 (0)