Détail du package

postsvg

JetBrains43.7kMIT2.2.7

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

posthtml, html, svg, transformations

readme

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

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.2.7 (2019-02-08)

Note: Version bump only for package postsvg

2.2.6 (2018-12-05)

Note: Version bump only for package postsvg

2.2.5 (2018-10-29)

Note: Version bump only for package postsvg

2.2.4 (2018-10-29)

Bug Fixes

  • refer to license file in readme (e34a289)

2.2.3 (2018-06-13)

Note: Version bump only for package postsvg

2.2.2 (2018-05-11)

Note: Version bump only for package postsvg

2.2.1 (2018-04-28)

Note: Version bump only for package postsvg

2.2.0 (2018-04-21)

Bug Fixes

  • processor use posthtml interop (cbb821a)

Features

  • add select and each methods to postsvg tree (fc18f4a)
  • add svg getter in result (1bccdd4)
  • posthtml interop; selectors returns all nodes if no params passed (cc3e6e3)

2.1.2 (2018-04-13)

Note: Version bump only for package postsvg

2.1.2-alpha.0 (2018-04-09)

Note: Version bump only for package postsvg

2.1.1-0 (2018-04-09)

Bug Fixes

  • restore package entrypoint (58ec666)

2.1.0 (2018-04-09)

Bug Fixes

Features

  • add clone and static createFromArray methods (c7e30d1)
  • add render method to tree (bb39522)
  • add more handy package entrypoint (987bda6)
  • return Tree wrapper from parser instead of Array (70065e2)