1.0.2 • Published 1 year ago

r_html_to_json v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Rust based html parser(WASM).

Usage

html_to_json

import { html_to_json } from "r_html_to_json";


const html = `<!doctype html>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <title>Html parser</title>
        </head>
        <body>
            <h1 data-data="data" id="a" class="b c">Hello world</h1>
        </body>
    </html>`;

const result = await html_to_json(html);

console.log(result);

Output

{
  "tag": "html",
  "attributes": {},
  "children": [
    {
      "tag": "head",
      "attributes": {},
      "children": [
        {
          "tag": "",
          "attributes": {},
          "children": [],
          "text": "\n            "
        },
        {
          "tag": "meta",
          "attributes": {},
          "children": []
        },
        {
          "tag": "",
          "attributes": {},
          "children": [],
          "text": "\n            "
        },
        {
          "tag": "title",
          "attributes": {},
          "children": [
            {
              "tag": "",
              "attributes": {},
              "children": [],
              "text": "Html parser"
            }
          ]
        },
        {
          "tag": "",
          "attributes": {},
          "children": [],
          "text": "\n        "
        }
      ]
    },
    {
      "tag": "",
      "attributes": {},
      "children": [],
      "text": "\n        "
    },
    {
      "tag": "body",
      "attributes": {},
      "children": [
        {
          "tag": "",
          "attributes": {},
          "children": [],
          "text": "\n            "
        },
        {
          "tag": "h1",
          "attributes": {},
          "children": [
            {
              "tag": "",
              "attributes": {},
              "children": [],
              "text": "Hello world"
            }
          ]
        },
        {
          "tag": "",
          "attributes": {},
          "children": [],
          "text": "\n        \n    "
        }
      ]
    }
  ]
}

json_to_html

import { json_to_html, html_to_json } from "r_html_to_json";

const html = `<!doctype html>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <title>Html parser</title>
        </head>
        <body>
            <h1 data-data="data" id="a" class="b c">Hello world</h1>
        </body>
    </html>`;

const result = await html_to_json(html);

const resultHtml = await json_to_html(result);

console.log(resultHtml);

Output

<html lang="en"><head>
    <meta charset="utf-8"></meta>
    <title>Html parser</title>
</head>
<body>
<h1 data-data="data" class="b c" id="a">Hello world</h1>

</body></html>

To use with vite, install the plugin

vite-plugin-wasm

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.2.0

1 year ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago