Skip to content

Commit c9ec01d

Browse files
committed
fix(footnote): add return link to last element of reference element
Resolves #41
1 parent 522d115 commit c9ec01d

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

content/markdown-demo.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,20 @@ wrapping the text in square brackets and the URL in parentheses.
161161
amet id laboris pariatur ea ut exercitation Lorem velit et nisi nulla
162162
occaecat voluptate
163163

164-
[^2]: Wikipedia article on a cool topic: [https://en.wikipedia.org/wiki/Isometric_projection](https://en.wikipedia.org/wiki/Isometric_projection)
164+
```rust
165+
fn main() {
166+
todo!();
167+
}
168+
```
169+
170+
[^2]:
171+
Wikipedia article on a cool topic: [https://en.wikipedia.org/wiki/Isometric_projection](https://en.wikipedia.org/wiki/Isometric_projection)
172+
173+
> Isometric projection is a method for visually representing
174+
> three-dimensional objects in two dimensions in technical and engineering
175+
> drawings. It is an axonometric projection in which the three coordinate
176+
> axes appear equally foreshortened and the angle between any two of them is
177+
> 120 degrees.
165178

166179
[^3]:
167180
Here's one with multiple paragraphs and code. This is the first paragraph

static/js/reference-return.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ document.addEventListener("DOMContentLoaded", function () {
2727
returnLink.setAttribute("role", "link");
2828
returnLink.setAttribute("tabindex", "0");
2929

30-
// Append to the last p tag
31-
const lastParagraph = fn.querySelector("p:last-of-type");
32-
if (lastParagraph) {
33-
lastParagraph.appendChild(returnLink);
30+
// Append inline to last paragraph, or after last element otherwise
31+
const lastEl = fn.lastElementChild;
32+
if (lastEl && lastEl.tagName === "P") {
33+
lastEl.appendChild(returnLink);
3434
} else {
35-
// If no paragraph, append to the footnote definition directly
3635
fn.appendChild(returnLink);
3736
}
3837
});

0 commit comments

Comments
 (0)