feat: Codeblock syntax highlighting with HLJS

This commit is contained in:
April Hall 2025-02-10 13:29:09 -05:00
parent 97e9fd3f2e
commit e46ea9987a
No known key found for this signature in database
GPG Key ID: A49AC35CB186266C
6 changed files with 22 additions and 2 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -52,6 +52,7 @@
"cassandra-driver": "^4.7.2", "cassandra-driver": "^4.7.2",
"express": "^4.21.2", "express": "^4.21.2",
"lucide-svelte": "^0.474.0", "lucide-svelte": "^0.474.0",
"markdown-it-highlightjs": "^4.2.0",
"mode-watcher": "^0.5.1", "mode-watcher": "^0.5.1",
"socket.io": "^4.8.1", "socket.io": "^4.8.1",
"socket.io-client": "^4.8.1", "socket.io-client": "^4.8.1",

View File

@ -1,3 +1,5 @@
@import '../node_modules/highlight.js/styles/github-dark.min.css';
@tailwind base; @tailwind base;
@tailwind components; @tailwind components;
@tailwind utilities; @tailwind utilities;

View File

@ -14,7 +14,7 @@
</div> </div>
<div class="w-full"> <div class="w-full">
<p class="inline-size-full break-words font-bold">{user}</p> <p class="inline-size-full break-words font-bold">{user}</p>
<Prose class="inline-size-full text-wrap break-words font-sans">{@html renderMarkdown(escapeHTML(message))}</Prose> <Prose class="inline-size-full text-wrap break-words font-sans">{@html renderMarkdown(message)}</Prose>
</div> </div>
</div> </div>

View File

@ -1,4 +1,5 @@
import markdownit from 'markdown-it'; import markdownit from 'markdown-it';
import highlightjs from 'markdown-it-highlightjs';
export default function renderMarkdown(input: string): string { export default function renderMarkdown(input: string): string {
const md = markdownit({ const md = markdownit({
@ -6,7 +7,10 @@ export default function renderMarkdown(input: string): string {
linkify: true, linkify: true,
typographer: true, typographer: true,
breaks: true, breaks: true,
}).disable(['image', 'table']); });
md.disable(['image', 'table']);
md.use(highlightjs);
return md.render(input); return md.render(input);
} }

View File

@ -53,11 +53,24 @@ const config: Config = {
borderRadius: { borderRadius: {
lg: 'var(--radius)', lg: 'var(--radius)',
md: 'calc(var(--radius) - 2px)', md: 'calc(var(--radius) - 2px)',
'background-color': '#22272E',
sm: 'calc(var(--radius) - 4px)', sm: 'calc(var(--radius) - 4px)',
}, },
fontFamily: { fontFamily: {
sans: [...fontFamily.sans], sans: [...fontFamily.sans],
}, },
typography: () => ({
DEFAULT: {
css: {
pre: {
'background-color': '#22272E',
code: {
'background-color': '#22272E',
},
},
},
},
}),
}, },
}, },
plugins: [typography], plugins: [typography],