Module: Uniword::Docx::Reconciler::Notes
- Included in:
- Uniword::Docx::Reconciler
- Defined in:
- lib/uniword/docx/reconciler/notes.rb
Overview
Footnote and endnote reconciliation.
Ensures notes are structurally valid with separators, proper ordering and sequential IDs. Creates missing notes/settings pairs and strips invalid types.
Instance Method Summary collapse
Instance Method Details
#reconcile_endnotes ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/uniword/docx/reconciler/notes.rb', line 56 def reconcile_endnotes reconcile_notes_type( notes: package.endnotes, notes_setter: ->(v) { package.endnotes = v }, has_pr: package.settings&.endnote_pr, type: :endnote, create_message: "Created endnotes.xml to match endnotePr in settings", pr_message: "Added endnotePr to settings to match endnotes.xml", ) end |
#reconcile_footnotes ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/uniword/docx/reconciler/notes.rb', line 45 def reconcile_footnotes reconcile_notes_type( notes: package.footnotes, notes_setter: ->(v) { package.footnotes = v }, has_pr: package.settings&.footnote_pr, type: :footnote, create_message: "Created footnotes.xml to match footnotePr in settings", pr_message: "Added footnotePr to settings to match footnotes.xml", ) end |
#reconcile_note_references ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/uniword/docx/reconciler/notes.rb', line 12 def reconcile_note_references [:footnote, :endnote].each do |type| ref_ids = collect_note_ids(type) next if ref_ids.empty? current = notes_collection_for(type) if current.nil? ensure_notes_part(type) current = notes_collection_for(type) end defined_set = note_entries_for(current, type).map(&:id).to_set missing = ref_ids.reject { |id| defined_set.include?(id) } next if missing.empty? entries = note_entries_for(current, type) missing.each do |id| entries << entry_class(type).new( id: id, paragraphs: [Wordprocessingml::Paragraph.new( runs: [Wordprocessingml::Run.new( text: Wordprocessingml::Text.new(content: " ") )] )], ) end record_fix(FixCodes::NOTE_DEFINITION_CREATED, "Created missing #{type}note definitions for ids=#{missing.join(', ')}") end end |