Garados007/elm-svg-parser/1.0.0

NOTE: the latest version is 1.1.2

SvgParser

String to SVG parser

Primitives

type SvgNode
= SvgElement Element
| SvgText String
| SvgComment String

A SVG node can be one of the three: SvgElement, SvgText or SvgComment.

type alias Element =
{ name : String
, attributes : List SvgAttribute
, children : List SvgNode
}

An Element consists of a tag name, a list of attributes, a list of children nodes.

<svg xmlns="http://www.w3.org/2000/svg"></svg>

will be parsed as

Element "svg" [ ( "xmlns", "http://www.w3.org/2000/svg" ) ] []
type alias SvgAttribute =
( String, String )

A name/value pair to denote attribute.

Parsing

parse : String -> Result String (Html msg)

Parses String to Html msg. Usually this is the only function you need.

parseToNode : String -> Result String SvgNode

Parses String to SvgNode. Normally you will use parse instead of this.

parse "<svg xmlns=\"http://www.w3.org/2000/svg\"></svg>"
    == Ok (SvgElement (Element "svg" [ ( "xmlns", "http://www.w3.org/2000/svg" ) ] []))
nodeToSvg : SvgNode -> Svg msg

Convert SvgNode to Svg msg. This is useful when you want to manipulate SvgNode before conveting to Html msg.

toAttribute : SvgAttribute -> Attribute msg

Convert SvgAttribute to Attribute msg. This is useful when you want to manipulate SvgAttribute before converting to Html msg.