summaryrefslogtreecommitdiff
path: root/src/components/Markdown.astro
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/Markdown.astro')
-rw-r--r--src/components/Markdown.astro35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/components/Markdown.astro b/src/components/Markdown.astro
new file mode 100644
index 0000000..d9881a8
--- /dev/null
+++ b/src/components/Markdown.astro
@@ -0,0 +1,35 @@
+---
+import { Marked } from 'marked';
+import markedShiki from 'marked-shiki';
+import { getHighlighter } from 'shiki';
+
+interface Props {
+ content: string;
+ class?: string;
+}
+
+const { content, class: className } = Astro.props;
+
+// `getHighlighter` is async, it initializes the internal and
+// loads the languages and themes specified.
+// Then later you can use `highlighter.codeToHtml` synchronously
+// with the loaded themes and languages.
+const highlighter = await getHighlighter({
+ langs: ['jsx', 'js'],
+ themes: ['poimandres']
+});
+const html = await new Marked()
+ .use(
+ markedShiki({
+ highlight(code, lang, props) {
+ return highlighter.codeToHtml(code, {
+ lang,
+ theme: 'poimandres'
+ });
+ }
+ })
+ )
+ .parse(content);
+---
+
+<div class:list={['markdown', className]} set:html={html} />