-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(md): try to writer markdown parser
- Loading branch information
Showing
4 changed files
with
126 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#![feature(in_band_lifetimes)] | ||
extern crate pest; | ||
#[macro_use] | ||
extern crate pest_derive; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod md_processor; | ||
pub mod md_struct; | ||
pub mod references; | ||
pub mod tokenizer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use crate::markdown::md_struct::MdStruct; | ||
use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag}; | ||
|
||
pub struct QuakeDown { | ||
pub pieces: Vec<MdStruct>, | ||
pub end_newline: bool, | ||
pub is_in_code_block: bool, | ||
} | ||
|
||
impl Default for QuakeDown { | ||
fn default() -> Self { | ||
QuakeDown { | ||
pieces: vec![], | ||
end_newline: false, | ||
is_in_code_block: false, | ||
} | ||
} | ||
} | ||
|
||
impl QuakeDown { | ||
pub fn from(content: &str) { | ||
let mut parser_options = Options::empty(); | ||
parser_options.insert(Options::ENABLE_TABLES); | ||
parser_options.insert(Options::ENABLE_FOOTNOTES); | ||
parser_options.insert(Options::ENABLE_STRIKETHROUGH); | ||
parser_options.insert(Options::ENABLE_TASKLISTS); | ||
parser_options.insert(Options::ENABLE_SMART_PUNCTUATION); | ||
let mut parser = Parser::new_ext(&content, parser_options); | ||
let mut down = QuakeDown::default(); | ||
down.transform(&mut parser); | ||
} | ||
|
||
pub fn transform(&mut self, parser: &mut Parser) { | ||
while let Some(event) = parser.into_iter().next() { | ||
match event { | ||
Event::Start(tag) => { | ||
match tag { | ||
Tag::Paragraph => {} | ||
Tag::Heading(_) => {} | ||
Tag::BlockQuote => {} | ||
Tag::CodeBlock(info) => match info { | ||
CodeBlockKind::Indented => { | ||
self.is_in_code_block = true; | ||
} | ||
CodeBlockKind::Fenced(_info) => { | ||
self.is_in_code_block = true; | ||
} | ||
}, | ||
Tag::List(_) => {} | ||
Tag::Item => {} | ||
Tag::FootnoteDefinition(_) => {} | ||
Tag::Table(_) => {} | ||
Tag::TableHead => {} | ||
Tag::TableRow => {} | ||
Tag::TableCell => {} | ||
Tag::Emphasis => {} | ||
Tag::Strong => {} | ||
Tag::Strikethrough => {} | ||
Tag::Link(_, _, _) => {} | ||
Tag::Image(_, _, _) => {} | ||
}; | ||
} | ||
Event::End(tag) => { | ||
// something here | ||
match tag { | ||
Tag::Paragraph => {} | ||
Tag::Heading(_) => {} | ||
Tag::BlockQuote => {} | ||
Tag::CodeBlock(_) => {} | ||
Tag::List(_) => {} | ||
Tag::Item => {} | ||
Tag::FootnoteDefinition(_) => {} | ||
Tag::Table(_) => {} | ||
Tag::TableHead => {} | ||
Tag::TableRow => {} | ||
Tag::TableCell => {} | ||
Tag::Emphasis => {} | ||
Tag::Strong => {} | ||
Tag::Strikethrough => {} | ||
Tag::Link(_, _, _) => {} | ||
Tag::Image(_, _, _) => {} | ||
} | ||
} | ||
Event::Text(_) => {} | ||
Event::Code(_) => {} | ||
Event::Html(_) => {} | ||
Event::FootnoteReference(_) => {} | ||
Event::SoftBreak => {} | ||
Event::HardBreak => {} | ||
Event::Rule => {} | ||
Event::TaskListMarker(_) => {} | ||
} | ||
} | ||
} | ||
} |