From 6cf911a526303072117f1106b448c8d454c0d2ea Mon Sep 17 00:00:00 2001 From: Florian Dieminger Date: Wed, 9 Oct 2024 15:48:20 +0200 Subject: [PATCH] fix(html): don't remove p's in li's (#19) depends on https://github.com/mdn/yari/pull/11930 --- crates/rari-doc/src/html/rewriter.rs | 4 ---- crates/rari-md/src/li.rs | 21 --------------------- crates/rari-md/src/lib.rs | 13 ++++--------- 3 files changed, 4 insertions(+), 34 deletions(-) delete mode 100644 crates/rari-md/src/li.rs diff --git a/crates/rari-doc/src/html/rewriter.rs b/crates/rari-doc/src/html/rewriter.rs index 56af95f2..13cc6c76 100644 --- a/crates/rari-doc/src/html/rewriter.rs +++ b/crates/rari-doc/src/html/rewriter.rs @@ -136,10 +136,6 @@ pub fn post_process_html( el.set_attribute("loading", "lazy")?; Ok(()) }), - element!("li > p", |el| { - el.remove_and_keep_content(); - Ok(()) - }), element!("a[href]", |el| { let original_href = el.get_attribute("href").expect("href was required"); if original_href.starts_with('/') diff --git a/crates/rari-md/src/li.rs b/crates/rari-md/src/li.rs deleted file mode 100644 index 23b7a118..00000000 --- a/crates/rari-md/src/li.rs +++ /dev/null @@ -1,21 +0,0 @@ -use comrak::nodes::{AstNode, NodeValue}; - -pub(crate) fn remove_p<'a>(list: &'a AstNode<'a>) { - for child in list.children() { - if let Some(i) = child.first_child() { - if !matches!(i.data.borrow().value, NodeValue::Paragraph) { - continue; - } - i.detach(); - if let Some(new_first) = child.first_child() { - for sub in i.children() { - new_first.insert_before(sub); - } - } else { - for sub in i.children() { - child.append(sub); - } - } - } - } -} diff --git a/crates/rari-md/src/lib.rs b/crates/rari-md/src/lib.rs index b7237fad..e50efe7a 100644 --- a/crates/rari-md/src/lib.rs +++ b/crates/rari-md/src/lib.rs @@ -11,15 +11,12 @@ pub(crate) mod dl; pub mod error; pub(crate) mod ext; pub(crate) mod html; -pub(crate) mod li; pub mod node_card; pub(crate) mod p; use dl::{convert_dl, is_dl}; use html::format_document; -use self::li::remove_p; - fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &F) where F: Fn(&'a AstNode<'a>), @@ -45,15 +42,13 @@ pub fn m2h(input: &str, locale: Locale) -> Result { let root = parse_document(&arena, input, &options); iter_nodes(root, &|node| { - let (dl, li, templs_p, empty_p) = match node.data.borrow().value { - NodeValue::List(_) => (is_dl(node), true, false, false), - NodeValue::Paragraph => (false, false, is_escaped_templ_p(node), is_empty_p(node)), - _ => (false, false, false, false), + let (dl, templs_p, empty_p) = match node.data.borrow().value { + NodeValue::List(_) => (is_dl(node), false, false), + NodeValue::Paragraph => (false, is_escaped_templ_p(node), is_empty_p(node)), + _ => (false, false, false), }; if dl { convert_dl(node); - } else if li { - remove_p(node); } if templs_p || empty_p { fix_p(node)