Skip to content

ofzo/wxml

This branch is 14 commits ahead of, 5 commits behind vivaxy/WXML:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
roadup
Jun 19, 2020
07222a0 Â· Jun 19, 2020
Jun 19, 2020
May 20, 2020
Jun 19, 2020
Jun 19, 2020
Jan 23, 2020
Sep 8, 2018
Aug 8, 2018
May 5, 2020
Aug 8, 2018
Aug 16, 2019
Aug 8, 2018
Jun 19, 2020
Aug 8, 2018
Jun 12, 2020
Jun 19, 2020
Jun 19, 2020
May 9, 2020
Jan 23, 2020
May 19, 2020

Repository files navigation

WXML

wxml parser and serializer.

Build Status NPM Version NPM Downloads MIT License Standard Version Codecov

Install

yarn add wxml or npm i wxml --save

Usage

import * as wxml from 'wxml';
const parsed = wxml.parse('<view></view>');
wxml.traverse(parsed, function visitor(node, parent) {
  const type = node.type;
  const parentNode = node.parentNode;

  if (type === wxml.NODE_TYPES.ELEMENT) {
    // handle element node
    const tagName = node.tagName;
    const attributes = node.attributes; // an object represents the attributes
    const childNodes = node.childNodes;
    const selfClosing = node.selfClosing; // if a node is self closing, like `<tag />`
  } else if (type === wxml.NODE_TYPES.TEXT) {
    // handle text node
    const textContent = node.textContent;
  } else if (type === wxml.NODE_TYPES.COMMENT) {
    // handle comment node
    const comment = node.comment;
  }
});
const serialized = wxml.serialize(parsed);

API

parse

(input: string) => AST

traverse

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

serialize

(node: Node) => string

About

wxml parser and serializer.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%