Skip to main content

parse_style

Function parse_style 

Source
pub fn parse_style(input: &str) -> Result<Style, CslParseError>
Expand description

Parse input as a CSL 1.0.2 style.

§Errors

Returns a CslParseError when input is not well-formed XML, the root is not <style>, the required version/class attributes are missing or invalid or unsupported, a <macro> lacks a name, a <citation>/ <bibliography> lacks its <layout>, a <text> selects no source or too many sources, a <choose> has invalid branch order, or an unsupported rendering element is encountered.

§Examples

use mos_csl::{parse_style, StyleClass};

let style = parse_style(
    r#"<style version="1.0" class="in-text">
         <info><title>Demo</title></info>
         <citation><layout><text variable="title"/></layout></citation>
       </style>"#,
)
.expect("valid CSL");
assert_eq!(style.class, StyleClass::InText);
assert!(style.citation.is_some());