项目作者: vivaxy

项目描述 :
See https://github.com/oft/wxml.
高级语言: TypeScript
项目地址: git://github.com/vivaxy/WXML.git
创建时间: 2018-08-08T02:48:36Z
项目社区:https://github.com/vivaxy/WXML

开源协议:MIT License

下载


WXML

🌇WXML parser and serializer.

Build Status
@vivaxy/wxml"">NPM Version
@vivaxy/wxml"">NPM Downloads
MIT License
Standard Version
Codecov
DOI

Install

yarn add @vivaxy/wxml or npm i @vivaxy/wxml --save

Usage

  1. import * as wxml from '@vivaxy/wxml';
  2. const parsed = wxml.parse('<view></view>');
  3. wxml.traverse(parsed, function visitor(node, parent) {
  4. const type = node.type;
  5. const parentNode = node.parentNode;
  6. if (type === wxml.NODE_TYPES.ELEMENT) {
  7. // handle element node
  8. const tagName = node.tagName;
  9. const attributes = node.attributes; // an object represents the attributes
  10. const childNodes = node.childNodes;
  11. const selfClosing = node.selfClosing; // if a node is self closing, like `<tag ></tag>`
  12. } else if (type === wxml.NODE_TYPES.TEXT) {
  13. // handle text node
  14. const textContent = node.textContent;
  15. } else if (type === wxml.NODE_TYPES.COMMENT) {
  16. // handle comment node
  17. const comment = node.comment;
  18. }
  19. });
  20. const serialized = wxml.serialize(parsed);

API

parse

(input: string) => AST

traverse

(node: Node, visitor: (node: Node, parent: Node) => void) => void

serialize

(node: Node) => string