Removed styled text in tables and add support to code into tables
parent
fc2d95137f
commit
f427ab127f
46
src/lib.rs
46
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::Table(_)) => state.start_table_building(),
|
||||||
md::Event::Start(md::Tag::TableHead) => state.add_table_row(),
|
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::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::Emphasis) => state.toggle_emphasis(),
|
||||||
md::Event::Start(md::Tag::Strong) => state.toggle_strong(),
|
md::Event::Start(md::Tag::Strong) => state.toggle_strong(),
|
||||||
md::Event::Start(md::Tag::Strikethrough) => unimplemented!("strikethrough disabled"),
|
md::Event::Start(md::Tag::Strikethrough) => unimplemented!("strikethrough disabled"),
|
||||||
|
@ -150,12 +150,20 @@ impl State {
|
||||||
self.table.push(vec![]);
|
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) {
|
fn start_block_quote(&mut self) {
|
||||||
self.pending_node_type = NodeType::Quote;
|
self.pending_node_type = NodeType::Quote;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_code_block(&mut self) {
|
fn start_code_block(&mut self) {
|
||||||
self.pending_node_type = NodeType::Preformatted;
|
if !self.building_table {
|
||||||
|
self.pending_node_type = NodeType::Preformatted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_list_item(&mut self) {
|
fn start_list_item(&mut self) {
|
||||||
|
@ -163,11 +171,15 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_emphasis(&mut self) {
|
fn toggle_emphasis(&mut self) {
|
||||||
self.add_text("_");
|
if !self.building_table {
|
||||||
|
self.add_text("_");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_strong(&mut self) {
|
fn toggle_strong(&mut self) {
|
||||||
self.add_text("**");
|
if !self.building_table {
|
||||||
|
self.add_text("**");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_link(&mut self) {
|
fn start_link(&mut self) {
|
||||||
|
@ -191,7 +203,7 @@ impl State {
|
||||||
self.building_table = false;
|
self.building_table = false;
|
||||||
self.table = vec![];
|
self.table = vec![];
|
||||||
|
|
||||||
self.finish_node();
|
self.pending_node_type = NodeType::Preformatted;
|
||||||
self.pending_node_content += &table.to_string();
|
self.pending_node_content += &table.to_string();
|
||||||
self.finish_node();
|
self.finish_node();
|
||||||
}
|
}
|
||||||
|
@ -245,7 +257,9 @@ impl State {
|
||||||
fn add_text(&mut self, text: &str) {
|
fn add_text(&mut self, text: &str) {
|
||||||
if self.building_table {
|
if self.building_table {
|
||||||
if let Some(last_row) = self.table.last_mut() {
|
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 {
|
} else {
|
||||||
for link_text in &mut self.link_text_stack {
|
for link_text in &mut self.link_text_stack {
|
||||||
|
@ -256,9 +270,23 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_inline_code(&mut self, code: &str) {
|
fn add_inline_code(&mut self, code: &str) {
|
||||||
self.pending_node_content += "`";
|
if self.building_table {
|
||||||
self.pending_node_content += code;
|
if let Some(last_row) = self.table.last_mut() {
|
||||||
self.pending_node_content += "`";
|
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) {
|
fn add_rule(&mut self) {
|
||||||
|
|
Loading…
Reference in New Issue