How to write a plug-in that converts MD to HTML?
The fs, path, and process modules are used in node. After reading the MD source file, marked plug-in was used to extract and convert the MD file content, and browser-Sync plug-in was used to monitor and update the MD content in real time. The core code is as follows:
let mdPath = path.join(__dirname, process.argv[2]) let cssPath = path.resolve('github.css') let htmlPath = mdPath.replace(path.extname(mdPath), '.html') fs.watchFile(mdPath, (curr, prev) => { if (curr.mtime ! == prev.mtime) { fs.readFile(mdPath, 'utf-8', (err, HTML let htmlStr = marked(data) fs.readFile(cssPath, 'utF-8 ', (err, Replace ('{{style}}', data) => {let retHtml = temp.replace('{{content}}', htmlStr). Replace ('{{style}}', data) Write the above to the specified HTML file, Fs.writefile (htmlPath, retHtml, (err) => {console.log(' HTML generated successfully ')})})})}) browsersync.init ({browser: ', server: __dirname, watch: true, index: path.basename(htmlPath) })Copy the code
How to communicate with hardware devices
See note.youdao.com/s/JLZ3EEDv