Nibbling Pastry Monster

    html-parser-n

    1.0.4 • Public • Published

    html-parse

    transform htmlStr to object with Array

    npm i htmlstr-parser-n

    const { htmlObjParser, htmlStrParser } = require("html-parser-n");
    const fs = require("fs");
    
    fs.writeFileSync('./demo.json', JSON.stringify(
      htmlStrParser(`
      <html>
        <body>
          <span id="root" style="color:red;">我是span标签</span>
        </body>
      </html>
    `)
    ))
    
    console.log(htmlObjParser(require("./demo.json")))
    

    结果

    {
        "nodeName":"root",
        "children":[
            {
                "nodeName":"html",
                "children":[
                    {
                        "nodeName":"body",
                        "children":[
                            {
                                "nodeName":"div",
                                "children":[],
                                "text":"我是div标签"
                            },
                            {
                                "nodeName":"span",
                                "children":[],
                                "id":"root",
                                "style":{
                                    "color":"red"
                                },
                                "text":"我是span标签"
                            }
                        ],
                        "text":"  "
                    }
                ]
            }
        ]
    }
    

    Keywords

    none

    Install

    npm i html-parser-n

    DownloadsWeekly Downloads

    6

    Version

    1.0.4

    License

    ISC

    Unpacked Size

    21.7 kB

    Total Files

    11

    Last publish

    Collaborators

    • zuolung