diff options
| author | Fuwn <[email protected]> | 2023-03-12 07:27:23 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-03-12 07:27:23 +0000 |
| commit | b41f28cb00cc38ed97ba08f681c5a6b77ebdbd70 (patch) | |
| tree | db86ec493f64bc6298d2a448976b9f35e5e84256 | |
| parent | feat(cargo): bump to 0.2.3 (diff) | |
| download | september-b41f28cb00cc38ed97ba08f681c5a6b77ebdbd70.tar.xz september-b41f28cb00cc38ed97ba08f681c5a6b77ebdbd70.zip | |
fix(to_html): normalize raw p tag
| -rw-r--r-- | src/gemini_to_html.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/gemini_to_html.rs b/src/gemini_to_html.rs index 1a81c28..f4ab38b 100644 --- a/src/gemini_to_html.rs +++ b/src/gemini_to_html.rs @@ -22,10 +22,21 @@ use germ::ast::Node; use gmi::url::Url; fn to_html(text: &str) -> String { - if text.contains('$') { + let html = if text.contains('$') { text.to_string() } else { markly::to_html(text) + }; + + if (html.ends_with("</p>") || html.ends_with("</p>\n")) + && html.starts_with("<p>") + { + html + .trim_start_matches("<p>") + .trim_end_matches("</p>") + .to_string() + } else { + html } } @@ -137,7 +148,7 @@ pub fn gemini_to_html( 3 => "h3", _ => "p", }, - to_html(text) + to_html(text), )); } Node::List(items) => html.push_str(&format!( |