From da5c4c496a74b813f4d344717459cafce2c55d9a Mon Sep 17 00:00:00 2001 From: mscherer Date: Sat, 5 Nov 2022 20:30:35 +0100 Subject: [PATCH] Filter more than 1 footnote in summary (#2017) If the summary contains more than 1 footnote, only the 1st is removed, and so dangling links exists for all the others. --- components/content/src/page.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/components/content/src/page.rs b/components/content/src/page.rs index 73769d2b1..1fca26a58 100644 --- a/components/content/src/page.rs +++ b/components/content/src/page.rs @@ -229,7 +229,7 @@ impl Page { self.summary = res .summary_len .map(|l| &res.body[0..l]) - .map(|s| FOOTNOTES_RE.replace(s, "").into_owned()); + .map(|s| FOOTNOTES_RE.replace_all(s, "").into_owned()); self.content = res.body; self.toc = res.toc; self.external_links = res.external_links; @@ -515,13 +515,17 @@ Hello world +++ This page use 1.5 and has footnotes, here's one. [^1] +Here's another. [^2] + -And here's another. [^2] +And here's another. [^3] [^1]: This is the first footnote. -[^2]: This is the second footnote."# +[^2]: This is the secund footnote. + +[^3]: This is the third footnote."# .to_string(); let res = Page::parse(Path::new("hello.md"), &content, &config, &PathBuf::new()); assert!(res.is_ok()); @@ -536,7 +540,7 @@ And here's another. [^2] .unwrap(); assert_eq!( page.summary, - Some("

This page use 1.5 and has footnotes, here\'s one.

\n".to_string()) + Some("

This page use 1.5 and has footnotes, here\'s one.

\n

Here's another.

\n".to_string()) ); }