generated from oovm/RustTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supports recursive parsing of markdown tables
- Loading branch information
Showing
7 changed files
with
92 additions
and
100 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
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,9 +0,0 @@ | ||
use super::*; | ||
use comrak::nodes::NodeHtmlBlock; | ||
|
||
impl ToNotedown for NodeHtmlBlock { | ||
fn into_notedown(self) -> ASTNode { | ||
let html = String::from_utf8_lossy(&self.literal); | ||
ASTKind::code_block(html, "html", None) | ||
} | ||
} | ||
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,28 +1,28 @@ | ||
use super::*; | ||
use markdown::mdast::BlockQuote; | ||
use wasi_notedown::exports::notedown::core::syntax_tree::{ListEnvironment, ListItem}; | ||
|
||
impl NoteBlock for List { | ||
impl NoteBlock for BlockQuote { | ||
fn note_down_block(self, state: &mut ReadState) -> Result<RootItem, NotedownError> { | ||
let list = ListEnvironment { items: vec![], range: self.position.as_range() }; | ||
|
||
Ok(RootItem::List(list)) | ||
} | ||
} | ||
|
||
impl NoteBlock for List { | ||
fn note_down_block(self, state: &mut ReadState) -> Result<RootItem, NotedownError> { | ||
let mut items = Vec::with_capacity(self.children.len()); | ||
for x in self.children { | ||
match x { | ||
Node::ListItem(v) => { | ||
let items = root_items(v.children, state)?; | ||
ListItem { level: 0, checked: v.checked, range: v.position.as_range() }; | ||
} | ||
Node::ListItem(v) => items.extend(list_item(v, state)), | ||
_ => unreachable!(), | ||
}; | ||
} | ||
let list = ListEnvironment { items, range: self.position.as_range() }; | ||
Ok(RootItem::List(list)) | ||
} | ||
} | ||
|
||
impl NoteBlock for BlockQuote { | ||
fn note_down_block(self, state: &mut ReadState) -> Result<RootItem, NotedownError> { | ||
let list = ListEnvironment { items: vec![], range: self.position.as_range() }; | ||
|
||
Ok(RootItem::List(list)) | ||
} | ||
fn list_item(item: markdown::mdast::ListItem, state: &mut ReadState) -> Option<ListItem> { | ||
let items = root_items(item.children, state).unwrap(); | ||
Some(ListItem { level: 0, checked: item.checked, range: item.position.as_range() }) | ||
} |
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,29 +1,31 @@ | ||
use markdown::mdast::{TableCell, TableRow}; | ||
use super::*; | ||
use wasi_notedown::exports::notedown::core::syntax_tree::TableEnvironment; | ||
|
||
impl NoteBlock for Table { | ||
fn note_down_block(self, state: &mut ReadState) -> Result<RootItem, NotedownError> { | ||
let items = root_items(self.children, state)?; | ||
|
||
|
||
let table = TableEnvironment { rows: vec![], range: self.position.as_range() }; | ||
let mut rows = Vec::with_capacity(self.children.len()); | ||
for x in self.children { | ||
match x { | ||
Node::TableRow(x) => rows.extend(table_row(x, state)), | ||
_ => unreachable!(), | ||
} | ||
} | ||
let table = TableEnvironment { rows, range: self.position.as_range() }; | ||
Ok(RootItem::Table(table)) | ||
} | ||
} | ||
|
||
impl NoteBlock for TableRow { | ||
fn note_down_block(self, state: &mut ReadState) -> Result<RootItem, NotedownError> { | ||
let items = root_items(self.children, state)?; | ||
let table = TableEnvironment { rows: vec![], range: self.position.as_range() }; | ||
Ok(RootItem::Table(table)) | ||
fn table_row(row: markdown::mdast::TableRow, state: &mut ReadState) -> Option<TableRow> { | ||
let mut cells = Vec::with_capacity(row.children.len()); | ||
for x in row.children { | ||
match x { | ||
Node::TableCell(x) => cells.extend(table_cell(x, state)), | ||
_ => unreachable!(), | ||
} | ||
} | ||
Some(TableRow { cells, range: row.position.as_range() }) | ||
} | ||
|
||
impl NoteBlock for TableCell { | ||
fn note_down_block(self, state: &mut ReadState) -> Result<RootItem, NotedownError> { | ||
let items = root_items(self.children, state)?; | ||
let table = TableEnvironment { rows: vec![], range: self.position.as_range() }; | ||
Ok(RootItem::Table(table)) | ||
} | ||
fn table_cell(cell: markdown::mdast::TableCell, state: &mut ReadState) -> Option<TableCell> { | ||
let items = paragraph_items(cell.children, state).unwrap(); | ||
Some(TableCell { range: cell.position.as_range() }) | ||
} |
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