#svg #parser #tokenizer

svgparser

Featureful, pull-based, zero-allocation SVG parser

20 releases (8 breaking)

Uses old Rust 2015

0.8.1 Apr 21, 2018
0.7.0 Mar 11, 2018
0.6.2 Dec 16, 2017
0.5.0 Sep 26, 2017
0.1.0 Oct 9, 2016

#34 in Data formats

Download history 207/week @ 2021-08-17 236/week @ 2021-08-24 75/week @ 2021-08-31 163/week @ 2021-09-07 136/week @ 2021-09-14 144/week @ 2021-09-21 84/week @ 2021-09-28 126/week @ 2021-10-05 185/week @ 2021-10-12 115/week @ 2021-10-19 131/week @ 2021-10-26 149/week @ 2021-11-02 42/week @ 2021-11-09 82/week @ 2021-11-16 125/week @ 2021-11-23 260/week @ 2021-11-30

533 downloads per month
Used in octicons

MIT/Apache

160KB
4K SLoC

svgparser

Build Status Crates.io Documentation

DEPRECATED. Use svgtypes instead.

svgparser is a pull-based parser for SVG 1.1 Full data format without heap allocations.

It's not an XML parser since it does not only split the content into the XML nodes, but also supports SVG types parsing.

Table of Contents

Supported SVG types

See the documentation for details.

Benefits

  • Most of the common data parsed into internal representation, and not just as string (unlike typical XML parser). Tag names, attribute names, attributes value, etc.
  • Complete support of paths, so data like M10-20A5.5.3-4 110-.1 will be parsed correctly.
  • Predefined SVG values for presentation attributes, like auto, normal, none, inherit, etc. are parsed as enum, not as String.
  • Every type can be parsed separately, so you can parse just paths or transform or any other SVG value.
  • Good error processing. All error types contain position (line:column) where it occurred.
  • No heap allocations.
  • Pretty fast.

Limitations

  • All keywords must be lowercase. Case-insensitive parsing is supported only for colors (requires allocation for named colors). Still, it's extremely rare.
  • The <color> followed by the <icccolor> is not supported. As the <icccolor> itself.
  • Only ENTITY objects are parsed from the DOCTYPE. Other ignored.
  • CSS styles does not processed. You should use an external CSS parser.
  • Comments inside attributes value supported only for the style attribute.
  • System colors, like fill="AppWorkspace", are not supported.
  • There is no separate opacity-value type. It will be parsed as <number>, but will be bound to 0..1 range.
  • Implicit path commands are not supported. All commands are parsed as explicit.
  • Implicit MoveTo commands will be automatically converted into explicit LineTo.

Safety

  • The library should not panic. Any panic considered as a critical bug and should be reported.
  • The library forbids unsafe code.

Alternatives

  • svg, which has about 10% of svgparser features. Also has minimal writing capabilities, unlike svgparser, which is parser only.

If you need writing and DOM manipulations - checkout svgdom crate, which is built on top of svgparser.

If you know about other alternatives - please send a pull request.

Usage

Dependency: Rust >= 1.18

Add this to your Cargo.toml:

[dependencies]
svgparser = "0.8"

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~295KB

SZ