flatiron/
lib.rs

1//! # Flatiron
2//!
3//! `flatiron` is a parser and HTML renderer for the [Textile markup language](https://web.archive.org/web/20021226034931/http://textism.com/article/648/)
4
5use nom::combinator::complete;
6
7mod parse;
8mod render;
9mod structs;
10
11/// Convert a textile String to HTML.
12///
13/// ## Example
14///
15/// ```
16/// use flatiron::convert;
17///
18/// let textile = String::from("h1. Is this thing on?");
19/// let html = convert(textile);
20/// assert_eq!(html, String::from("<h1>Is this thing on?</h1>\n"));
21/// ```
22pub fn convert(input: String) -> String {
23    let (_, textile) = complete(parse::textile)(&input).unwrap();
24    escape_unicode(format!("{}", textile))
25}
26
27fn escape_unicode(input: String) -> String {
28    input
29        .chars()
30        .into_iter()
31        .map(|c| {
32            if !c.is_ascii() {
33                format!("&#{};", u32::from(c))
34            } else {
35                String::from(c)
36            }
37        })
38        .collect()
39}