pub fn links2html(input: &str) -> String
Expand description

Text to HTML renderer that prints only links with markup as a list, one per line. Links are clickable and only their link text is shown (the part enclosed with <a> and </a>).

Markdown

use parse_hyperlinks::renderer::links2html;
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 = "\
<a href=\"dest0\" title=\"title0\">text0</a>
<a href=\"dest1\" title=\"title1\">text1</a>
<a href=\"dest2\" title=\"title2\">text2</a>
<a href=\"dest3\" title=\"title3\">text3</a>
";
let res = links2html(i);
assert_eq!(res, expected);

Rendered text

This is how the rendered text looks like in the browser:

text0 text1 text2 text3

reStructuredText

use parse_hyperlinks::renderer::links2html;
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 = "\
<a href=\"dest1\" title=\"\">text1</a>
<a href=\"dest2\" title=\"\">text2</a>
<a href=\"dest3\" title=\"\">text3</a>
<a href=\"dest5\" title=\"\">text5</a>
";

let res = links2html(i);
assert_eq!(res, expected);

Rendered text

This is how the rendered text looks like in the browser:

text1 text2 text3 text5

Asciidoc

use parse_hyperlinks::renderer::links2html;
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 = "\
<a href=\"https://dest0\" title=\"\">text0</a>
<a href=\"https://dest1\" title=\"\">text1</a>
<a href=\"https://dest2\" title=\"\">text2</a>
<a href=\"https://dest3\" title=\"\">https:&#x2F;&#x2F;dest3</a>
";

let res = links2html(i);
assert_eq!(res, expected);

Rendered text

This is how the rendered text looks like in the browser:

text0 text1 text2 https://dest3

Wikitext

use parse_hyperlinks::renderer::links2html;
use std::borrow::Cow;

let i = r#"abc[https://dest0 text0]abc
"#;

let expected = "\
<a href=\"https://dest0\" title=\"\">text0</a>
";

let res = links2html(i);
assert_eq!(res, expected);

Rendered text

This is how the rendered text looks like in the browser:

text0

HTML

HTML inline links are sanitized and listed, one per line.

use parse_hyperlinks::renderer::links2html;
use std::borrow::Cow;

let i = r#"abc<a href="dest1" title="title1">text1</a>abc
abc<a href="dest2" title="title2">text2</a>abc"#;

let expected = "\
<a href=\"dest1\" title=\"title1\">text1</a>
<a href=\"dest2\" title=\"title2\">text2</a>
";

let res = links2html(i);
assert_eq!(res, expected);

Rendered text

This is how the rendered text looks like in the browser:

text1 text2