htmlstr-parse

1.0.6 • Public • Published

html-parse

transform htmlStr to object with Array

npm i htmlstr-parse

const parser = require("htmlstr-parse");
const fs = require("fs");

fs.writeFileSync('./demo.text', JSON.stringify(
  parser(`
  <html>
    <body>
      <span id="root" style="color:red;">我是span标签</span>
    </body>
  </html>
`)
))

结果

{
    "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":"  "
                }
            ]
        }
    ]
}

Readme

Keywords

none

Package Sidebar

Install

npm i htmlstr-parse

Weekly Downloads

1

Version

1.0.6

License

ISC

Unpacked Size

20.8 kB

Total Files

9

Last publish

Collaborators

  • zuolung