Function parse_hyperlinks::renderer::text_rawlinks2html [−][src]
pub fn text_rawlinks2html<'a>(input: &'a str) -> String
Markup source code viewer
Markup source code viewer, that make hyperlinks clickable in your web-browser.
This function prints the input text “as it is”, but renders links with markup. Links are clickable.
Markdown
use parse_hyperlinks::renderer::text_rawlinks2html; use std::borrow::Cow; let i = r#"abc[text0](dest0 "title0")abc abc[text1][label1]abc abc[text2](dest2 "title2")abc [text3]: dest3 "title3" [label1]: dest1 "title1" abc[text3]abc "#; let expected = "\ <pre>abc<a href=\"dest0\" title=\"title0\">[text0](dest0 \"title0\")</a>abc abc<a href=\"dest1\" title=\"title1\">[text1][label1]</a>abc abc<a href=\"dest2\" title=\"title2\">[text2](dest2 \"title2\")</a>abc <a href=\"dest3\" title=\"title3\">[text3]: dest3 \"title3\"</a> <a href=\"dest1\" title=\"title1\">[label1]: dest1 \"title1\"</a> abc<a href=\"dest3\" title=\"title3\">[text3]</a>abc </pre>"; let res = text_rawlinks2html(i); assert_eq!(res, expected);
Rendered text
This is how the rendered text looks like in the browser:
abc[text0](dest0 "title0")abc abc[text1][label1]abc abc[text2](dest2 "title2")abc [text3]: dest3 "title3" [label1]: dest1 "title1" abc[text3]abc
reStructuredText
use parse_hyperlinks::renderer::text_rawlinks2html; use std::borrow::Cow; let i = r#" abc `text1 <label1_>`_abc abc text2_ abc abc text3__ abc abc text_label4_ abc abc text5__ abc .. _label1: dest1 .. _text2: dest2 .. __: dest3 __ dest5 "#; let expected = "\ <pre> abc <a href=\"dest1\" title=\"\">`text1 <label1_>`_</a>abc abc <a href=\"dest2\" title=\"\">text2_</a> abc abc <a href=\"dest3\" title=\"\">text3__</a> abc abc text_label4_ abc abc <a href=\"dest5\" title=\"\">text5__</a> abc <a href=\"dest1\" title=\"\">.. _label1: dest1</a> <a href=\"dest2\" title=\"\">.. _text2: dest2</a> <a href=\"dest3\" title=\"\">.. __: dest3</a> <a href=\"dest5\" title=\"\">__ dest5</a> </pre>"; let res = text_rawlinks2html(i); assert_eq!(res, expected);
Rendered text
This is how the rendered text look likes in the browser:
abc `text1 <label1_>`_abc abc text2_ abc abc text3__ abc abc text_label4_ abc abc text5__ abc .. _label1: dest1 .. _text2: dest2 .. __: dest3 __ dest5
Asciidoc
use parse_hyperlinks::renderer::text_rawlinks2html; use std::borrow::Cow; let i = r#"abc https://dest0[text0]abc abc link:https://dest1[text1]abc abc{label2}[text2]abc abc{label3}abc :label2: https://dest2 :label3: https://dest3 "#; let expected = "\ <pre>abc <a href=\"https://dest0\" title=\"\">https://dest0[text0]</a>abc abc <a href=\"https://dest1\" title=\"\">link:https://dest1[text1]</a>abc abc<a href=\"https://dest2\" title=\"\">{label2}[text2]</a>abc abc<a href=\"https://dest3\" title=\"\">{label3}</a>abc <a href=\"https://dest2\" title=\"\">:label2: https://dest2</a> <a href=\"https://dest3\" title=\"\">:label3: https://dest3</a> </pre>"; let res = text_rawlinks2html(i); assert_eq!(res, expected);
Rendered text
This is how the rendered text looks like in the browser:
abc https://dest0[text0]abc abc link:https://dest1[text1]abc abc{label2}[text2]abc abc{label3}abc :label2: https://dest2 :label3: https://dest3
HTML
HTML inline links are sanitized and their link source code is shown as link text.
use parse_hyperlinks::renderer::text_rawlinks2html; use std::borrow::Cow; let i = r#"abc<a href="dest1" title="title1">text1</a>abc"#; let expected = "\ <pre>abc<a href=\"dest1\" title=\"title1\">\ <a href=\"dest1\" title=\"title1\">text1</a>\ </a>abc</pre>"; let res = text_rawlinks2html(i); assert_eq!(res, expected);
Rendered text
This is how the rendered text looks like in the browser:
abc<a href="dest1" title="title1">text1</a>abc