From eb15075946ac0073961ef450fb6f9dc8c35bc3db Mon Sep 17 00:00:00 2001 From: kud1ing Date: Sat, 10 Dec 2016 18:07:07 +0100 Subject: [PATCH] add a parser stub for the README.md file --- Cargo.toml | 7 +++++++ src/main.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..38962d6 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "awesome-rust" +version = "0.1.0" +authors = [] + +[dependencies] +pulldown-cmark= "0.0.8" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..326b812 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,36 @@ +extern crate pulldown_cmark; + +use pulldown_cmark::{Parser, Event}; +use std::error::Error; +use std::fs::File; +use std::io::Read; +use std::path::Path; + +fn main() { + let path = Path::new("README.md"); + + let display = path.display(); + + let mut file = match File::open(&path) { + Err(why) => panic!("couldn't open {}: {}", display, why.description()), + Ok(file) => file, + }; + + let mut readme_content = String::new(); + + match file.read_to_string(&mut readme_content) { + Err(why) => panic!("couldn't read {}: {}", display, why.description()), + Ok(_) => print!("{} contains:\n{}", display, readme_content), + } + + let mut parser = Parser::new(&readme_content); + + while let Some(event) = parser.next() { + match event { + Event::Start(tag) => println!("start: {:?}", tag), + Event::End(tag) => println!("end: {:?}", tag), + Event::Text(text) => println!("text: {:?}", text), + _ => (), + } + } +}