Created
June 26, 2018 10:58
-
-
Save rene-d/b46d4cc5330896dd81e669f6a77b8bca to your computer and use it in GitHub Desktop.
Convert Markdown to HTML
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
// rené 06/2018 | |
// Showdown: https://github.com/showdownjs/showdown | |
// Bootstrap: https://getbootstrap.com/ | |
'use strict'; | |
let fs = require('fs'); | |
let showdown = require('showdown'); | |
let conv = new showdown.Converter(); | |
conv.setOption('tables', true); | |
conv.setOption('ghCodeBlocks', true); | |
conv.setFlavor('github'); | |
fs.readFile('README.md', 'utf8', function(err,data) { | |
if (err) { | |
return console.log(err); | |
} | |
let html = conv.makeHtml(data); | |
let head = ` | |
<html> | |
<head> | |
<meta charset="UTF-8"> <meta name="description" content="README"> | |
<title>Markdown</title> | |
<link rel="stylesheet" type="text/css" href="bootstrap.min.css"> | |
</head> | |
<body> | |
<div class='container'> | |
`; | |
let tail = '</div></body></html>'; | |
html = html.replace('<table>', '<table class="table table-dark table-striped>'); | |
fs.writeFile("README.html", head + html + tail, (err) => { | |
if (err) { | |
return console.log(err); | |
} else { | |
return console.log("file created:", "README.html"); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment