@@ -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
0 commit comments