首页 > 代码库 > markdown-it将md转成html

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

 

markdown-it将md转成html