Function html2pango::block::markup_html

source ·
pub fn markup_html(s: &str) -> Result<Vec<HtmlBlock>, Error>
Expand description

Converts HTML body markup into a list of HTML blocks.

Calls markup_html_ignore_tags to do the actual work instructing it to ignore the <body> and mx-reply (for Matrix) tags.

For more details on what is actually converted, see the module documentation.

Errors

Returns an error if reading from the string fails or if parsing fails.

Examples

Some HTML markup of a heading and an unordered list:

let blks =
    markup_html("<body><h1>Heading 1</h1><ul><li>First</li><li>Second</li><body>").unwrap();
assert_eq!(blks[0], HtmlBlock::Heading(1, String::from("Heading 1")));
assert_eq!(blks[1], HtmlBlock::UList(vec![String::from("First"), String::from("Second")]));

Pango Markup is applied, paragraphs are handled but merged:

let blks =
    markup_html("<body><p>This is <em>nice</em>!</p><p>Second paragraph.</p></body>").unwrap();
assert_eq!(
    blks[0],
    HtmlBlock::Text(String::from("This is <i>nice</i>!\n\nSecond paragraph."))
);

URIs are replaced by links:

let blks =
    markup_html("<body>Go to https://gnome.org</body>").unwrap();
assert_eq!(
    blks[0],
    HtmlBlock::Text(String::from("Go to <a href=\"https://gnome.org\">https://gnome.org</a>"))
);