码迷,mamicode.com
首页 > Web开发 > 详细

markdown-it将md转成html

时间:2016-11-30 14:16:20      阅读:305      评论:0      收藏:0      [点我收藏+]

标签:efi   read   div   node   else   down   http   mds   watch   

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‘);
        }
      });
    });
  });
});

 

markdown-it将md转成html

标签:efi   read   div   node   else   down   http   mds   watch   

原文地址:http://www.cnblogs.com/Lomio/p/6117238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!