mirror of
https://github.com/rust-unofficial/awesome-rust.git
synced 2025-01-19 05:49:19 +02:00
add a parser stub for the README.md file
This commit is contained in:
parent
58742d653d
commit
eb15075946
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…
x
Reference in New Issue
Block a user