Repository: LemmyNet/lemmy (language: rust)

Issue:
[Bug]: Footnotes aren't turned into HTML
### Requirements

- [X] Is this a bug report? For questions or discussions use https://lemmy.ml/c/lemmy_support
- [X] Did you check to see if this issue already exists?
- [X] Is this only a single bug? Do not put multiple bugs in one issue.
- [X] Do you agree to follow the rules in our [Code of Conduct](https://join-lemmy.org/docs/code_of_conduct.html)?
- [X] Is this a backend issue? Use the [lemmy-ui](https://github.com/LemmyNet/lemmy-ui) repo for UI / frontend issues.

### Summary

Lemmy-ui supports markdown footnotes via [markdown-it-footnote](https://github.com/markdown-it/markdown-it-footnote), but the backend's parser doesn't.

### Steps to Reproduce

1. Make a comment with a footnote
```md
Cheese is very expensive.[^1]

[^1]: https://example.com/cheese-prices
```
2. The HTML on the resulting Note will be
```html
<p>Cheese is very expensive.[^1]</p>
<p>[^1]: <a href="https://example.com/cheese-prices">https://example.com/cheese-prices</a></p>
```

### Technical Details

n/a

### Version

0.19.7, but affects all versions

### Lemmy Instance URL

_No response_


Discussion / hints:
This could easily be supported by adding [markdown-it-footnote](https://crates.io/crates/markdown-it-footnote). PR welcome.

Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index 6f7fedfb27..3fa8ac655d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2837,6 +2837,7 @@ dependencies = [
  "lettre",
  "markdown-it",
  "markdown-it-block-spoiler",
+ "markdown-it-footnote",
  "markdown-it-ruby",
  "markdown-it-sub",
  "markdown-it-sup",
@@ -2901,7 +2902,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
 dependencies = [
  "cfg-if",
- "windows-targets 0.48.5",
+ "windows-targets 0.52.6",
 ]
 
 [[package]]
@@ -3021,6 +3022,15 @@ dependencies = [
  "markdown-it",
 ]
 
+[[package]]
+name = "markdown-it-footnote"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6679ab967fbc45b290b25fb477af7556bf6825feec208a970585e6bb9aae3be"
+dependencies = [
+ "markdown-it",
+]
+
 [[package]]
 name = "markdown-it-ruby"
 version = "1.0.0"
diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml
index ded84132ce..64f36d54a9 100644
--- a/crates/utils/Cargo.toml
+++ b/crates/utils/Cargo.toml
@@ -89,6 +89,7 @@ markdown-it-block-spoiler = "1.0.0"
 markdown-it-sub = "1.0.0"
 markdown-it-sup = "1.0.0"
 markdown-it-ruby = "1.0.0"
+markdown-it-footnote = "0.2.0"
 moka = { workspace = true, optional = true }
 
 [dev-dependencies]
diff --git a/crates/utils/src/utils/markdown/mod.rs b/crates/utils/src/utils/markdown/mod.rs
index 25ac0ffd65..58f03d9105 100644
--- a/crates/utils/src/utils/markdown/mod.rs
+++ b/crates/utils/src/utils/markdown/mod.rs
@@ -14,6 +14,7 @@ static MARKDOWN_PARSER: LazyLock<MarkdownIt> = LazyLock::new(|| {
   markdown_it_sub::add(&mut parser);
   markdown_it_sup::add(&mut parser);
   markdown_it_ruby::add(&mut parser);
+  markdown_it_footnote::add(&mut parser);
   link_rule::add(&mut parser);
 
   parser
@@ -122,6 +123,17 @@ mod tests {
         "ruby text",
         "{漢|Kan}{字|ji}",
         "<p><ruby>漢<rp>(</rp><rt>Kan</rt><rp>)</rp></ruby><ruby>字<rp>(</rp><rt>ji</rt><rp>)</rp></ruby></p>\n"
+      ),
+      (
+        "footnotes",
+        "Bold claim.[^1]\n\n[^1]: example.com",
+        "<p>Bold claim.<sup class=\"footnote-ref\"><a href=\"#fn1\" id=\"fnref1\">[1]</a></sup></p>\n\
+	 <hr class=\"footnotes-sep\" />\n\
+	 <section class=\"footnotes\">\n\
+	 <ol class=\"footnotes-list\">\n\
+	 <li id=\"fn1\" class=\"footnote-item\">\n\
+	 <p>example.com <a href=\"#fnref1\" class=\"footnote-backref\">↩︎</a></p>\n\
+	 </li>\n</ol>\n</section>\n"
       )
     ];
 


Test patch: