Cambios desde el servidor cliente

This commit is contained in:
2026-02-23 10:57:12 -06:00
parent 17c1ef3947
commit 168a5fdf1c
2 changed files with 8 additions and 9 deletions

View File

@@ -48,6 +48,8 @@
});
}
import { browser } from '$app/environment';
function renderMarkdown(content: string) {
const rawHtml = marked.parse(content || '') as string;
// Add IDs to headers for TOC navigation
@@ -55,7 +57,10 @@
const id = text.toLowerCase().replace(/[^\w]+/g, '-');
return `<h${level} id="${id}">${text}</h${level}>`;
});
return DOMPurify.sanitize(htmlWithIds);
if (browser) {
return DOMPurify.sanitize(htmlWithIds);
}
return htmlWithIds;
}
function scrollToHeader(id: string) {

View File

@@ -139,15 +139,9 @@
}
}
import { browser } from '$app/environment';
function renderMarkdown(text: string) {
if (!browser) {
// Basic fallback for SSR to avoid crashing
return (text || '')
.replace(/^# (.*$)/gim, '<h1>$1</h1>')
.replace(/^## (.*$)/gim, '<h2>$1</h2>')
.replace(/\*\*(.*)\*\*/gim, '<b>$1</b>')
.replace(/\n/gim, '<br />');
}
// @ts-ignore
return DOMPurify.sanitize(marked.parse(text || '') as string);
}