Skip to content

Utils for parsing and stringifying html strings

License

Notifications You must be signed in to change notification settings

sirenkovladd/html-parse-string

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>

About

Utils for parsing and stringifying html strings

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%