Created
October 31, 2023 18:17
-
-
Save nhrones/2e82ab90f162623e3f26c3434656f2ac to your computer and use it in GitHub Desktop.
Md to HTML with code highlighting
This file contains hidden or 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 GFM (GitHub Flavored Markdown rendering for Deno) | |
import { CSS, render } from "https://deno.land/x/[email protected]/mod.ts"; | |
// Add prism - syntax highlighter for TypeScript, Bash, and Rust | |
import "https://esm.sh/[email protected]/components/prism-typescript?no-check"; | |
/** | |
* Export an html doc file builder (builds html from markdown) | |
*/ | |
export function buildHtml( markdownName: string, srcFolder: string ) { | |
// get the markdown text | |
const markdown = Deno.readTextFileSync(srcFolder + '\\' + markdownName + '.md') | |
// convert it to html text | |
const body = render( markdown ); | |
// blend it with a document template | |
const html = ` | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="shortcut icon" type="image/x-icon" href="data:image/x-icon;,"> | |
<style> | |
main { | |
max-width: 800px; | |
margin: 0 auto; | |
} | |
${CSS} | |
</style> | |
</head> | |
<body> | |
<main data-color-mode="light" data-light-theme="light" data-dark-theme="dark" class="markdown-body"> | |
${body} | |
</main> | |
</body> | |
</html> | |
`; | |
// Save it as an html file | |
Deno.writeTextFileSync('./html/' + markdownName + '.html', html ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment