Skip to content

Instantly share code, notes, and snippets.

@marshyon
Created February 4, 2023 16:47
Show Gist options
  • Save marshyon/8b35193c4876d00ea64904b1ccd28d08 to your computer and use it in GitHub Desktop.
Save marshyon/8b35193c4876d00ea64904b1ccd28d08 to your computer and use it in GitHub Desktop.
simple nodejs app that parses markdown, extracts the front-matter for later use then extracts, parses and outputs html for the main body, itself containing 'escaped' html in code blocks
mdHTMLMix = `---
id: q.yada yada.e
title: Network Designs Quiz
desc: ''
updated: 1668088687103
created: 1667513672394
---
# Network Designs Quiz
<figure>
<img src="assets/images/albuquerque.jpg"
alt="Albuquerque, New Mexico">
<figcaption>A single track trail outside of Albuquerque, New Mexico.</figcaption>
</figure>
<br />
# TCP/IP Model
***First line***
> Second line
> Third line
>> # Fourth line
1. Open the file.
2. Find the following code block on line 21:
<html>
<head>
<title>Test</title>
</head>
<html>
***
My favourite search engine is [Duck Duck Go](http://duckduckgo.com)
`
const buffer = Buffer.from(mdHTMLMix, 'utf8');
const matter = require('gray-matter');
const result = matter(buffer)
const marked = require('marked');
marked.setOptions({
pedantic: false,
gfm: true,
breaks: false,
sanitize: false,
smartypants: false,
xhtml: false
});
const html = marked.parse(result.content)
console.log(html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment