Depend on markdown-it、 highlight.js, analyse markdown to html for nodejs.
yarn add @juexro/markdown2html -D
markdown
---
title: demo
date: 2018/11/22 17:27:56
---
# demo
You can add key-values between --- ---
at the top. And get info in beforeOuput meta.
nodejs
const fs = require('fs')
const MarkdownAnalyse = require('@juexro/markdown2html')
const minify = require('html-minifier').minify
new MarkdownAnalyse({
cleanDir: true,
filePath: ['markdown/foo.md', 'markdown/bar'],
outputPath: 'html',
beforeOutput ({content, meta, outputFilePath} = {}, md) {
return minify(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>${meta.title}</title>
<style>
${fs.readFileSync('node_modules/highlight.js/styles/github.css')}
</style>
</head>
<body>
${md.render(content)}
</body>
</html>`, {
removeComments: true,
collapseWhitespace: true,
minifyCSS: true
})
}
}).run()
Name | Type | Description |
---|---|---|
cleanDir | Boolean | remove outputPath directory at first |
filePath | Array|String | file path or directory |
outputPath | String | output directory |
beforeOutput | Function | @param {*} [{outputFilePath, meta, content}={}, md] , you can use md.render to render your markdown template. |