1.0.3 • Published 5 years ago

@juexro/markdown2html v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

markdown2html

npm.io npm.io

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()
NameTypeDescription
cleanDirBooleanremove outputPath directory at first
filePathArray|Stringfile path or directory
outputPathStringoutput directory
beforeOutputFunction@param {*} [{outputFilePath, meta, content}={}, md], you can use md.render to render your markdown template.