项目作者: renminghao

项目描述 :
html的AST解析
高级语言: JavaScript
项目地址: git://github.com/renminghao/html-ast.git
创建时间: 2016-11-12T10:21:15Z
项目社区:https://github.com/renminghao/html-ast

开源协议:

下载


html-ast

html的AST解析

parse

dom只能有一个根节点

  1. import {Parse} from '../dist/index';
  2. const result = Parse(`htmlString`)

result

  1. {
  2. "name": tagName,
  3. "attr": [{}...],
  4. "closeSelf": boolean,
  5. "status": start|end,
  6. "children": [{}...]
  7. }

compile

parse的结果作为入参

  1. import {Compile} from '../dist/index';
  2. Compile(data);

result

  1. <form name='searchTop' action='//list.tmall.com/search_product.htm' class='mallSearch-form clearfix' target='_top' acceptCharset='gbk' ><fieldset ><legend > 天猫搜索</legend><div class='mallSearch-input clearfix' ><label for='mq' > 搜索 天猫 商品/品牌/店铺</label><div class='s-combobox' ><div class='s-combobox-input-wrap' ><input type='text' name='q' accesskey='s' autocomplete='off' x-webkit-speech='' x-webkit-grammar='builtin:translate' value='' id='mq' autocomplete='off' ></input></div></div><button type='submit' > 搜索<s ></s></button><input id='J_Type' type='hidden' name='type' value='p' ></input><input id='J_MallSearchStyle' type='hidden' name='style' value='' ></input><input id='J_Cat' type='hidden' name='cat' value='all' ></input><input type='hidden' name='vmarket' value='' ></input></div></fieldset><a href='//tmall.com' ><span > test</span></a></form>