@juexro/markdown2html

1.0.3 • Public • Published

markdown2html

Depend on markdown-ithighlight.js, analyse markdown to html for nodejs.

install

yarn add @juexro/markdown2html -D

usage

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()

options

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.

Package Sidebar

Install

npm i @juexro/markdown2html

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

7.27 kB

Total Files

4

Last publish

Collaborators

  • juexro