mirror of
https://github.com/rust-unofficial/awesome-rust
synced 2024-11-22 03:43:03 +00:00
add a parser stub for the README.md file
This commit is contained in:
parent
58742d653d
commit
eb15075946
2 changed files with 43 additions and 0 deletions
7
Cargo.toml
Normal file
7
Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
[package]
|
||||||
|
name = "awesome-rust"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = []
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
pulldown-cmark= "0.0.8"
|
36
src/main.rs
Normal file
36
src/main.rs
Normal file
|
@ -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),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue