Skip to content

Commit

Permalink
improve detection of line number ordering when compiling HTML TOC: me…
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Nov 15, 2023
1 parent f6025d1 commit 2d3c1a1
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/isodoc/html_function/postprocess_cover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,24 @@ def html_toc_init(docxml)
end

def html_toc_entries(docxml, path)
xml = html_toc_entries_prep(docxml, path)
path.each_with_index.with_object([]) do |(p, i), m|
xml.xpath(p.join(" | ")).each do |h|
m << { entry: html_toc_entry("h#{i + 1}", h),
line: h.line }
end
end.sort_by { |k| k[:line] }
end

def html_toc_entries_prep(docxml, path)
path.each do |p|
docxml.xpath(p.join(" | ")).each do |h|
h["id"] ||= "_#{UUIDTools::UUID.random_create}"
m << { entry: html_toc_entry("h#{i + 1}", h),
line: h.line, level: i + 1 }
end
end.sort_by { |k| [k[:line], k[:level]] }
end
xml = Nokogiri::XML(docxml.to_xml, &:noblanks)
xml.remove_namespaces!
xml
end

def toc_exclude_class
Expand Down

0 comments on commit 2d3c1a1

Please sign in to comment.