Created
August 19, 2023 13:17
-
-
Save hmble/623f8a1d7f606a81fc2d52d74a2d82a4 to your computer and use it in GitHub Desktop.
astro with shiki and markdown it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
import Header from "../components/Header.astro"; | |
import BaseHead from "../components/BaseHead.astro"; | |
import { SITE_TITLE, SITE_DESCRIPTION } from '../consts'; | |
import markdownIt from 'markdown-it'; | |
import shiki from 'shiki' | |
const response = await fetch('https://raw.githubusercontent.com/shikijs/shiki/main/README.md'); | |
// const response = await fetch('https://raw.githubusercontent.com/wiki/adam-p/markdown-here/Markdown-Cheatsheet.md'); | |
const markdownResponse = await response.text(); | |
const content = await shiki.getHighlighter({ theme: 'github-dark'}).then(highlighter => { | |
const md = markdownIt({ | |
html: true, | |
highlight: (code, lang) => { | |
let templang = lang === 'no-highlight' ? 'text' : lang | |
return highlighter.codeToHtml(code, {lang: templang}) | |
} | |
}) | |
return md.render(markdownResponse) | |
}) | |
--- | |
<main class="outline outline-red-500 mx-auto container max-w-6xl flex justify-center"> | |
<article class="prose-xl md:prose" set:html={content}/> | |
</main> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment