ignore whole lines that start with html tag

This commit is contained in:
Crispy 2024-07-06 15:28:13 +02:00
parent e36e222f23
commit 9dd590ab86

View file

@ -60,8 +60,13 @@ pub fn convert_document(markdown: &str) -> String {
state = S::P; state = S::P;
html += "<p>\n"; html += "<p>\n";
} }
html += &convert_line(line); if line.starts_with('<') {
html += "<br>\n"; html += line;
html += "\n";
} else {
html += &convert_line(line);
html += "<br>\n";
}
} }
} }
html html
@ -73,7 +78,6 @@ fn convert_line(source: &str) -> String {
let mut is_b = false; let mut is_b = false;
let mut is_code = false; let mut is_code = false;
let mut is_ul = false; let mut is_ul = false;
let mut is_html_tag = false;
let toggle = |state: bool, tag: &str| { let toggle = |state: bool, tag: &str| {
if state { if state {
format!("<{tag}>") format!("<{tag}>")
@ -86,13 +90,6 @@ fn convert_line(source: &str) -> String {
let mut chars = source.chars().peekable(); let mut chars = source.chars().peekable();
while let Some(c) = chars.next() { while let Some(c) = chars.next() {
if is_html_tag {
out.push(c);
if c == '>' {
is_html_tag = false;
}
continue;
}
if let Some(link_c) = &mut link { if let Some(link_c) = &mut link {
match link_c { match link_c {
(link_text, None) => { (link_text, None) => {
@ -136,9 +133,6 @@ fn convert_line(source: &str) -> String {
} else if c == '_' { } else if c == '_' {
is_ul = !is_ul; is_ul = !is_ul;
out += &toggle(is_ul, "u"); out += &toggle(is_ul, "u");
} else if c == '<' {
out.push(c);
is_html_tag = true;
} else { } else {
out.push(c); out.push(c);
} }