pub fn markup_from_raw(s: &str) -> String
Expand description

Converts simple HTML markup to Pango Markup.

This will convert the input string to Pango Markup and replace URIs by links.

Currently it support conversion of the following HTML tags:

  • <p> and </p> => ""
  • <i>, <em> and </i>, </em> => <i> and </i>
  • <b>, <strong> and </b>, </strong> => <b> and </b>
  • <code> and </code> => <tt> and </tt>
  • <sub> and </sub> => <sub> and </sub>
  • <sup> and </sup> => <sup> and </sup>
  • <br> => \n

It will also convert the following characters and HTML entities:

  • < => &lt
  • > => &gt
  • &nbsp; =>   (non breaking space)

Examples

let m = markup_from_raw("this is parsed");
assert_eq!(m, "this is parsed");

let m = markup_from_raw("<b>this <i>is &ssd<f;</i></b>");
assert_eq!(m, "<b>this <i>is &ssd&lt;f;</i></b>");

let m = markup_from_raw("this is <span>parsed</span>");
assert_eq!(m, "this is &lt;span&gt;parsed&lt;/span&gt;");

let m = markup_from_raw("with links: http://gnome.org");
assert_eq!(m, "with links: <a href=\"http://gnome.org\">http://gnome.org</a>");