From 2d3c1a1f0bb4e0a16549e2d0d1ae68e163c02e2c Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Wed, 15 Nov 2023 23:20:48 +1100 Subject: [PATCH] improve detection of line number ordering when compiling HTML TOC: https://github.com/metanorma/metanorma-ogc/issues/597 --- lib/isodoc/html_function/postprocess_cover.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/isodoc/html_function/postprocess_cover.rb b/lib/isodoc/html_function/postprocess_cover.rb index 30f87405..af426e6f 100644 --- a/lib/isodoc/html_function/postprocess_cover.rb +++ b/lib/isodoc/html_function/postprocess_cover.rb @@ -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