Skip to content

Instantly share code, notes, and snippets.

@nhrones
Created October 31, 2023 18:17
Show Gist options
  • Save nhrones/2e82ab90f162623e3f26c3434656f2ac to your computer and use it in GitHub Desktop.
Save nhrones/2e82ab90f162623e3f26c3434656f2ac to your computer and use it in GitHub Desktop.
Md to HTML with code highlighting
// Import GFM (GitHub Flavored Markdown rendering for Deno)
import { CSS, render } from "https://deno.land/x/gfm@0.2.1/mod.ts";
// Add prism - syntax highlighter for TypeScript, Bash, and Rust
import "https://esm.sh/prismjs@1.29.0/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