|
5 | 5 | //// approach so other source formats can be added as sibling submodules. |
6 | 6 |
|
7 | 7 | import blogatto/config/post.{type Components, type PostConfig} |
| 8 | +import blogatto/internal/builder/post/footnote |
8 | 9 | import frontmatter as fm_extractor |
9 | 10 | import gleam/dict.{type Dict} |
10 | 11 | import gleam/int |
@@ -63,47 +64,14 @@ fn render_footnotes( |
63 | 64 | footnotes: Dict(String, List(jot.Container)), |
64 | 65 | ctx: Context(msg), |
65 | 66 | ) -> List(Element(msg)) { |
66 | | - let items = |
67 | | - ordered_refs |
68 | | - |> list.filter_map(fn(reference) { |
69 | | - use containers <- result.map(dict.get(footnotes, reference)) |
70 | | - let number = |
71 | | - ctx.footnote_numbers |> dict.get(reference) |> result.unwrap(0) |
72 | | - render_footnote_item(number, containers, ctx) |
73 | | - }) |
74 | | - case items { |
75 | | - [] -> [] |
76 | | - _ -> [ |
77 | | - element.element("section", [attribute.class("footnotes")], [ |
78 | | - element.element("ol", [], items), |
79 | | - ]), |
80 | | - ] |
81 | | - } |
82 | | -} |
83 | | - |
84 | | -/// Render a single footnote definition as an `<li id="fn-N">` containing the |
85 | | -/// definition body followed by a back-link to its reference site. |
86 | | -fn render_footnote_item( |
87 | | - number: Int, |
88 | | - containers: List(jot.Container), |
89 | | - ctx: Context(msg), |
90 | | -) -> Element(msg) { |
91 | | - let num = int.to_string(number) |
92 | | - let body = list.map(containers, render_container(_, ctx, jot.Loose)) |
93 | | - let backlink = |
94 | | - element.element( |
95 | | - "a", |
96 | | - [ |
97 | | - attribute.href("#fnref-" <> num), |
98 | | - attribute.class("footnote-backref"), |
99 | | - ], |
100 | | - [element.text("↩")], |
101 | | - ) |
102 | | - element.element( |
103 | | - "li", |
104 | | - [attribute.id("fn-" <> num)], |
105 | | - list.append(body, [backlink]), |
106 | | - ) |
| 67 | + ordered_refs |
| 68 | + |> list.filter_map(fn(reference) { |
| 69 | + use containers <- result.map(dict.get(footnotes, reference)) |
| 70 | + let number = ctx.footnote_numbers |> dict.get(reference) |> result.unwrap(0) |
| 71 | + let body = list.map(containers, render_container(_, ctx, jot.Loose)) |
| 72 | + footnote.item(number, body) |
| 73 | + }) |
| 74 | + |> footnote.section |
107 | 75 | } |
108 | 76 |
|
109 | 77 | /// Assign a footnote number to each reference in order of first appearance. |
@@ -316,18 +284,10 @@ fn render_inline(inline: jot.Inline, ctx: Context(msg)) -> Element(msg) { |
316 | 284 | ctx.footnote_numbers |
317 | 285 | |> dict.get(reference) |
318 | 286 | |> result.unwrap(0) |
319 | | - let num = int.to_string(number) |
320 | | - // Render the marker directly: it must carry both an `id` (the back-link |
321 | | - // target) and an `href` to the definition, which the `footnote` |
322 | | - // component (number + children only) cannot express. The visible text is |
323 | | - // the number, not the raw reference key (jot keeps its leading `^`). |
324 | | - element.element("sup", [], [ |
325 | | - element.element( |
326 | | - "a", |
327 | | - [attribute.id("fnref-" <> num), attribute.href("#fn-" <> num)], |
328 | | - [element.text(num)], |
329 | | - ), |
330 | | - ]) |
| 287 | + // The visible marker text is the number, not the raw reference key (jot |
| 288 | + // keeps its leading `^`). The default `footnote` component renders it as |
| 289 | + // a link to the definition. |
| 290 | + ctx.components.footnote(number, [element.text(int.to_string(number))]) |
331 | 291 | } |
332 | 292 | jot.Code(content: text) -> ctx.components.code(None, [element.text(text)]) |
333 | 293 | jot.MathInline(content: latex) -> |
|
0 commit comments