1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![crate_name = "markdown"]
#![deny(missing_docs)]
extern crate regex;
#[macro_use]
extern crate pipeline;
use std::fs::File;
use std::path::Path;
use std::io::{Read, Error};
mod parser;
mod html;
use parser::Block;
pub fn to_html(text : &str) -> String{
let result = parser::parse(text);
html::to_html(&result)
}
pub fn tokenize(text : &str) -> Vec<Block>{
parser::parse(text)
}
pub fn file_to_html(path : &Path) -> Result<String, Error>{
let mut file = match File::open(path) {
Ok(file) => file,
Err(e) => return Err(e)
};
let mut text = String::new();
match file.read_to_string(&mut text) {
Ok(_) => (),
Err(e) => return Err(e)
};
let result = parser::parse(&text);
Ok(html::to_html(&result))
}