Function html2pango::markup_html
source · pub fn markup_html(s: &str) -> Result<String, Error>
Expand description
Converts HTML body markup to Pango Markup.
While markup
/markup_from_raw
only supports simple HTML tags such as <p>
, <b>
and
<br>
, this function tries to convert HTML body markup so that the resulting Pango Markup
will render to something that is similar to what a browser would render.
Errors
Returns an error if reading from the strings fails.
Examples
let m = markup_html("<body>this is some <font color=\"#ff0000\">red text</font>!</body>").unwrap();
assert_eq!(m, "this is some <span foreground=\"#ff0000\">red text</span>!");
let m = markup_html("<body>a nice <a href=\"https://gnome.org\">link</a>").unwrap();
assert_eq!(m, "a nice <a href=\"https://gnome.org\">link</a>");
let m = markup_html("<body>some items: <ul><li>first</li><li>second</li></ul><body").unwrap();
assert_eq!(m, "some items: \n • first\n • second\n");