markdown-it将md转成html

https://github.com/markdown-it/markdown-it

 

'use strict';
const md = require('markdown-it')();
const fs = require('fs');
fs.watchFile('./txt/1.md', (curr, prev) => {
  let mdStr = fs.readFile('./txt/1.md', 'utf-8', (err, data) => {
    let mdData = md.render(data);
    let htmlTemplate = fs.readFile('./txt/index.html', 'utf-8', (err, data) => {
      let html = data.replace('{{content}}', mdData);
      console.log(mdData);
      fs.writeFile('./txt/nodejs.html', html, 'utf-8', (err, data) => {
        if (err) {
          throw err;
        } else {
          console.log('OK');
        }
      });
    });
  });
});

 

posted @ 2016-11-30 12:24  Lomio  阅读(2590)  评论(0编辑  收藏  举报