Skip to content

Commit 59b3ce9

Browse files
authored
Merge pull request #9 from eScholarship/6-footnotes-endnotes-more-info
more footnote rendering logic updates
2 parents 360ee56 + 35f414b commit 59b3ce9

3 files changed

Lines changed: 79 additions & 24 deletions

File tree

batch_convert.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ fi
1717
# Create output directory if it doesn't exist
1818
mkdir -p "$OUTPUT_DIR"
1919

20+
# Copy CSS file to output directory (for uploading)
21+
if [ -f "templates/styles.css" ]; then
22+
cp templates/styles.css "$OUTPUT_DIR/styles.css"
23+
fi
24+
2025
count=0
2126
total=$(find "$INPUT_DIR" -name "*.xml" | wc -l)
2227

lib/ucpec_static/tei/elements/note.rb

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ class Note < UCPECStatic::TEI::Nodes::Element
1515

1616
on_xml_attribute!(:type) do |value|
1717
@type = value
18-
# Only capture inline footnotes, or endnotes with corresp (noteref-style)
19-
# Endnotes without corresp (secref-style) render in place
20-
@counts_as_footnote = value == "footnote"
2118
@is_endnote = value == "endnote"
2219
end
2320

@@ -29,6 +26,9 @@ class Note < UCPECStatic::TEI::Nodes::Element
2926
@corresp = value
3027
end
3128

29+
after_process_xml_attributes :set_counts_as_footnote!
30+
after_process_xml_attributes :add_acknowledgement_class!
31+
3232
# @return [String, nil]
3333
attr_reader :target
3434

@@ -43,37 +43,64 @@ class Note < UCPECStatic::TEI::Nodes::Element
4343

4444
alias is_endnote? is_endnote
4545

46-
# Capture noteref-style endnotes (with corresp) but not secref-style (without corresp)
47-
def counts_as_footnote?
48-
super || (is_endnote? && corresp.present?)
46+
# Check if this note is inside a back element
47+
def in_back_matter?
48+
ancestors.any? { |ancestor| ancestor.is_a?(BackMatter) }
4949
end
5050

51-
# Should add anchor/backlink for notes that will be captured (have backlink target)
52-
# Secref-style endnotes (without corresp) render in place without backlinks
53-
def should_add_anchor?
54-
counts_as_footnote? && has_backlink_target?
51+
# Capture inline notes that are actually referenced
52+
# Endnotes always render in place (never captured)
53+
54+
private
55+
56+
# Set counts_as_footnote based on type and corresp
57+
# Capture footnotes that should be moved to the bottom
58+
def set_counts_as_footnote!
59+
# type="footnote" - always capture (inline footnotes)
60+
# type="note" with corresp - capture (referenced notes)
61+
# type="note" without corresp - render in place (chapter acknowledgements)
62+
# type="endnote" - never capture, always render in place
63+
if type == "footnote"
64+
@counts_as_footnote = true
65+
elsif type == "note"
66+
@counts_as_footnote = corresp.present?
67+
else
68+
@counts_as_footnote = false
69+
end
70+
end
71+
72+
# Add a CSS class for acknowledgement notes (unreferenced notes)
73+
def add_acknowledgement_class!
74+
if type == "note" && corresp.blank?
75+
html_classes << "acknowledgement-note"
76+
end
5577
end
5678

57-
# Check if this note has a backlink target (corresp for endnotes, or is a footnote)
58-
def has_backlink_target?
59-
corresp.present? || type == "footnote"
79+
# Add anchor for all notes with an id (for bidirectional linking)
80+
def should_add_anchor?
81+
target.present?
6082
end
6183

62-
private
84+
# Add backlink if note has corresp OR is a captured footnote
85+
# Endnotes in back matter without corresp (secref-style) won't have backlinks
86+
def has_backlink?
87+
corresp.present? || (counts_as_footnote? && target.present?)
88+
end
6389

6490
# @return [void]
6591
def add_anchor!
6692
# :nocov:
6793
return if target.blank?
6894
# :nocov:
6995

70-
# For noteref/endnote with corresp: corresp points to the ref's id
71-
# For fnoteref/footnote: use target (same as note's id)
72-
ref_id = corresp.presence || target
73-
7496
html_builder.nav(class: "footnote--nav") do
7597
html_builder.a(nil, name: target, class: "footnote--anchor")
76-
html_builder.a("Back", href: "##{ref_id}-ref", class: "footnote--backlink", title: "Return to previous location in text")
98+
99+
# Only add backlink if corresp exists (bidirectional linking)
100+
if has_backlink?
101+
ref_id = corresp.presence || target
102+
html_builder.a("Back", href: "##{ref_id}-ref", class: "footnote--backlink", title: "Return to previous location in text")
103+
end
77104
end
78105
end
79106
end

templates/styles.css

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,28 +226,35 @@ footer.footnotes li {
226226
margin: 1.5rem 0;
227227
}
228228

229-
footer.footnotes > ul > li > aside {
229+
/* Shared styles for all notes (in footer and in-place) */
230+
footer.footnotes > ul > li > aside,
231+
aside[data-tei-tag="note"] {
230232
background: white;
231233
border-left: 4px solid;
232234
padding: 1.25rem;
233235
border-radius: 0 6px 6px 0;
234236
box-shadow: 0 2px 6px rgba(0,0,0,0.08);
235237
transition: all 0.3s ease;
238+
margin: 1.5rem 0;
236239
}
237240

238-
footer.footnotes > ul > li > aside:hover {
241+
242+
footer.footnotes > ul > li > aside:hover,
243+
aside[data-tei-tag="note"]:hover {
239244
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
240245
transform: translateX(4px);
241246
}
242247

243-
footer.footnotes aside p {
248+
footer.footnotes aside p,
249+
aside[data-tei-tag="note"] p {
244250
margin: 0.5rem 0;
245251
font-size: 0.95rem;
246252
line-height: 1.7;
247253
}
248254

249255
/* Reset nested asides to not have the border */
250-
footer.footnotes aside aside {
256+
footer.footnotes aside aside,
257+
aside[data-tei-tag="note"] aside {
251258
border-left: none;
252259
padding: 0;
253260
box-shadow: none;
@@ -265,7 +272,8 @@ footer.footnotes aside aside {
265272
}
266273

267274
/* Hide backlinks in nested asides since they point to the same footnote */
268-
footer.footnotes aside aside .footnote--nav {
275+
footer.footnotes aside aside .footnote--nav,
276+
aside[data-tei-tag="note"] aside .footnote--nav {
269277
display: none;
270278
}
271279

@@ -294,6 +302,21 @@ footer.footnotes aside aside .footnote--nav {
294302
transform: translateX(-3px);
295303
}
296304

305+
/* Special styling for acknowledgement notes */
306+
aside.acknowledgement-note {
307+
background: #f8f9fa;
308+
border-left-color: #000;
309+
font-style: italic;
310+
}
311+
312+
aside.acknowledgement-note nav {
313+
border-bottom: none;
314+
}
315+
316+
aside.acknowledgement-note p {
317+
font-size: 0.9rem;
318+
}
319+
297320
/* Footnote reference links in text */
298321
section[data-tei-tag="body"] a[data-tei-tag="ref"] {
299322
color: #e74c3c;

0 commit comments

Comments
 (0)