pub fn text_to_html(
text: &str,
readme_path_in_pkg: &str,
base_url: Option<&str>,
pkg_path_in_vcs: Option<&str>,
) -> String
Expand description
Renders a text file to sanitized HTML. An appropriate rendering method is chosen depending
on the extension of the supplied filename
.
The returned text will not contain any harmful HTML tag or attribute (such as iframe, onclick, onmouseover, etc.).
The base_url
parameter will be used as the base for any relative links found in the
Markdown, as long as its host part is github.com, gitlab.com, or bitbucket.org. The
supplied URL will be used as a directory base whether or not the relative link is
prefixed with ‘/’. If None
is passed, relative links will be omitted.
§Examples
use cargo_registry_markdown::text_to_html;
let text = "[Rust](https://rust-lang.org/) is an awesome *systems programming* language!";
let rendered = text_to_html(text, "README.md", None, None);
assert_eq!(rendered, "<p><a href=\"https://rust-lang.org/\" rel=\"nofollow noopener noreferrer\">Rust</a> is an awesome <em>systems programming</em> language!</p>\n");