Removed styled text in tables and add support to code into tables
parent
fc2d95137f
commit
f427ab127f
34
src/lib.rs
34
src/lib.rs
|
@ -27,7 +27,7 @@ pub fn convert(markdown_text: &str) -> String {
|
|||
md::Event::Start(md::Tag::Table(_)) => state.start_table_building(),
|
||||
md::Event::Start(md::Tag::TableHead) => state.add_table_row(),
|
||||
md::Event::Start(md::Tag::TableRow) => state.add_table_row(),
|
||||
md::Event::Start(md::Tag::TableCell) => (),
|
||||
md::Event::Start(md::Tag::TableCell) => state.add_table_cell(),
|
||||
md::Event::Start(md::Tag::Emphasis) => state.toggle_emphasis(),
|
||||
md::Event::Start(md::Tag::Strong) => state.toggle_strong(),
|
||||
md::Event::Start(md::Tag::Strikethrough) => unimplemented!("strikethrough disabled"),
|
||||
|
@ -150,25 +150,37 @@ impl State {
|
|||
self.table.push(vec![]);
|
||||
}
|
||||
|
||||
fn add_table_cell(&mut self) {
|
||||
if let Some(last) = self.table.last_mut() {
|
||||
last.push(String::new());
|
||||
}
|
||||
}
|
||||
|
||||
fn start_block_quote(&mut self) {
|
||||
self.pending_node_type = NodeType::Quote;
|
||||
}
|
||||
|
||||
fn start_code_block(&mut self) {
|
||||
if !self.building_table {
|
||||
self.pending_node_type = NodeType::Preformatted;
|
||||
}
|
||||
}
|
||||
|
||||
fn start_list_item(&mut self) {
|
||||
self.pending_node_type = NodeType::ListItem;
|
||||
}
|
||||
|
||||
fn toggle_emphasis(&mut self) {
|
||||
if !self.building_table {
|
||||
self.add_text("_");
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_strong(&mut self) {
|
||||
if !self.building_table {
|
||||
self.add_text("**");
|
||||
}
|
||||
}
|
||||
|
||||
fn start_link(&mut self) {
|
||||
self.link_text_stack.push(String::new());
|
||||
|
@ -191,7 +203,7 @@ impl State {
|
|||
self.building_table = false;
|
||||
self.table = vec![];
|
||||
|
||||
self.finish_node();
|
||||
self.pending_node_type = NodeType::Preformatted;
|
||||
self.pending_node_content += &table.to_string();
|
||||
self.finish_node();
|
||||
}
|
||||
|
@ -245,7 +257,9 @@ impl State {
|
|||
fn add_text(&mut self, text: &str) {
|
||||
if self.building_table {
|
||||
if let Some(last_row) = self.table.last_mut() {
|
||||
last_row.push(text.to_string());
|
||||
if let Some(last_cell) = last_row.last_mut() {
|
||||
last_cell.push_str(&text.split("<br>").collect::<Vec<&str>>().join("\n"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for link_text in &mut self.link_text_stack {
|
||||
|
@ -256,10 +270,24 @@ impl State {
|
|||
}
|
||||
|
||||
fn add_inline_code(&mut self, code: &str) {
|
||||
if self.building_table {
|
||||
if let Some(last_row) = self.table.last_mut() {
|
||||
if let Some(last_cell) = last_row.last_mut() {
|
||||
last_cell.push_str(
|
||||
&code
|
||||
.replace("\\_", "_")
|
||||
.split("<br>")
|
||||
.collect::<Vec<&str>>()
|
||||
.join("\n"),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.pending_node_content += "`";
|
||||
self.pending_node_content += code;
|
||||
self.pending_node_content += "`";
|
||||
}
|
||||
}
|
||||
|
||||
fn add_rule(&mut self) {
|
||||
self.add_text("-----");
|
||||
|
|
Loading…
Reference in New Issue