0.0.9 • Published 1 year ago

html-parse-string v0.0.9

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

html-parse-string

HTML parse and stringify utils

Installation

npm install html-parse-string

IDom

basic data structure

export interface IDom {
  type: string;
  content ? : string;
  voidElement: boolean;
  name: string;
  attrs: { [key: string]: any };
  children: IDom[];
}

parse

parse html to idom array

const { parse, stringify } = require('html-parse-string');
const t = `<div>this is div</div>`;
console.log(parse(t));

get idom array

[
  {
    type: "tag",
    name: "div",
    voidElement: false,
    attrs: {},
    children: [
      {
        type: "text",
        content: "this is div",
      },
    ],
  },
];

stringify

stringify idom array to html

const { parse, stringify } = require('html-parse-string');
const t = `<div>this is div</div>`;
const ast = parse(t);
console.log(stringify(ast));

get html string

<div>this is div</div>
0.0.9

1 year ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

3 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

6 years ago

0.0.1

6 years ago