HDU2049 is not easy to series (4) -Baiden Kaojiu During the National Day, the provincial capital HZ has just held a grand collective wedding. In order to enrich the wedding, the emcee has temporarily came up with an interesting program, called “Groom”, and the specific operation is:

2023-02-04   ES  

The monitoring MD file changes, the change is changed to take the MD file, and the library is used to convert it to HTML;

  1. Supervisor: FS.Watchfile (FILENAME, (CUR, Pre) = <{})
  2. Read: fs.readfile;
  3. Distening to whether it changes: Cur.mtime /Pre.mtime; // Cur and Pre are all instances of fs.stats; both have stats attributes;
  4. conversion: Use the Marked library to install Install Marked – Save
  5. Converted successfully, spelling HTML code
  6. Write into the HTML file;
  7. Add style;
  8. automatic refresh

    const fs = require("fs");
    const path = require("path");
    const marked = require("marked");
    
    const filepath= path.join(__dirname, process.argv[2]);
    
    const template = `<!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    </head>
    <body>
        <div>{
         {
         {content}}} </div> 
     </body> 
     </html> ` 
    
     FS.Watchfile (FilePath, (Cur, Pre) => {// Options: Surveillance failure, etc. 
         if (Cur.mtime! == Pre.mtime) { 
    
             // Read the file and convert to write 
             fs.readfile (Filepath, "UTF8", (ERR, DATA) => { 
                 if (err) {console.log (err); Return;} 
                 let html = marked (data); 
    
                 // Because the md file is converted to HTML without body and other labels, you need to replace the addition 
                 template = html.replace ("{{{{{
         {content}}} ", html); 
    
                 // Write in html 
                 fs.writefile (path.join (__diRNAME, "Watch.html"), template, "utf8"); 
             }) 
         } 
     })

can also download the MD style table file, replace it to the page; it is best to add the style label instead of link, because the link method file path dynamic changes will make an error;


automatic refresh

Use Broswer-Sync Library
1. Install Browser-Sync-Save 
 2. Watch.js starts the Browser service at the beginning 
     Var Browsersync = Require ("Browser-Sync"); 
     browsersync ({server: __dirname}); 

 3. After writing the file, execute the Browser Relaod command;

After the completion of the MD file, the browser automatically opens the localhost page; enter the name of the HTML file; you can dynamically monitor the modification

source

Related Posts

“Programmer Installation B Guide”

Anroid about setting the highlights of the MPChart mid -folding line or pillar chart

STM32F030CT86 timer 3 channel 1 to verify the PWM front and rear cut mode

MVVM’s beginner in Android

HDU2049 is not easy to series (4) -Baiden Kaojiu During the National Day, the provincial capital HZ has just held a grand collective wedding. In order to enrich the wedding, the emcee has temporarily came up with an interesting program, called “Groom”, and the specific operation is:

Random Posts

Hangdian ACM2089 Do not 62JOHN

Center7 modify Locale as zhcn.utf-8

POJ 2762 (Weak Unicom: Qiang Liantong+Shining point+topology sorting) Weiguang

yuv420p to RGB24mirinda

OPENCV training classifier Make XML document