postsvg
A tiny wrapper over posthml with the same API optimized for working with SVG
Last updated a year ago by kisenka .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install postsvg 
SYNC missed versions from official npm registry.

PostSVG

A tiny wrapper over posthtml with the same API optimized for working with SVG.

Differences from PostHTML

  • Content is parsed in xml mode.
  • Properly renders SVG self-closing tags (<path />, <line /> etc).
  • Processing result is instance of Tree class which is wrapper around Array and backward compatible with posthtml parser.

Tree

PostSVG tree has several useful methods for work with AST:

const { parse } = require('postsvg');

const tree = parse('<svg><path /><path class="qwe" /></svg>');

/**
 * `root` getter returns <svg> node
 * @return {Node}
 */ 
tree.root;

/**
 * Find all <path/> nodes
 * @return {Array<Node>}
 */
tree.select('path'); 

/**
 * Select only nodes with class="qwe"
 * @return {Array<Node>}
 */
tree.select('.qwe');

/**
 * Fill each <path/> node with red color 
 */
tree.each('path', node => node.attrs.fill = 'red');

Node has following structure:

Node<{
  tag: string,
  attrs?: Object,
  content?: Array<Node>
}>

LICENSE

MIT

Current Tags

  • 2.1.2-alpha.0                                ...           alpha (2 years ago)
  • 2.2.0-alpha.10475b37                                ...           canary (2 years ago)
  • 2.2.7                                ...           latest (a year ago)

16 Versions

  • 2.2.7                                ...           a year ago
  • 2.2.6                                ...           2 years ago
  • 2.2.5                                ...           2 years ago
  • 2.2.4                                ...           2 years ago
  • 2.2.3                                ...           2 years ago
  • 2.2.2                                ...           2 years ago
  • 2.2.1                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.2                                ...           2 years ago
  • 2.1.2-alpha.0                                ...           2 years ago
  • 2.2.0-alpha.10475b37                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.0                                ...           3 years ago
  • 0.0.3                                ...           4 years ago
  • 0.0.2                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 8
This Week 40
This Month 202
Last Day 27
Last Week 106
Last Month 495
Dependencies (6)
Dev Dependencies (0)
None

Copyright 2014 - 2016 © taobao.org |