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

 

转载于:https://www.cnblogs.com/Lomio/p/6117238.html

你可能感兴趣的:(markdown-it将md转成html)