diff --git a/lib/isodoc/html_function/postprocess_cover.rb b/lib/isodoc/html_function/postprocess_cover.rb index af426e6f..149c4c26 100644 --- a/lib/isodoc/html_function/postprocess_cover.rb +++ b/lib/isodoc/html_function/postprocess_cover.rb @@ -136,24 +136,21 @@ def html_toc_init(docxml) end def html_toc_entries(docxml, path) - xml = html_toc_entries_prep(docxml, path) + headers = html_toc_entries_prep(docxml, path) path.each_with_index.with_object([]) do |(p, i), m| - xml.xpath(p.join(" | ")).each do |h| + docxml.xpath(p.join(" | ")).each do |h| m << { entry: html_toc_entry("h#{i + 1}", h), - line: h.line } + line: headers[h["id"]] } 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| + docxml.xpath(path.join(" | ")) + .each_with_index.with_object({}) do |(h, i), m| h["id"] ||= "_#{UUIDTools::UUID.random_create}" + m[h["id"]] = i end - end - xml = Nokogiri::XML(docxml.to_xml, &:noblanks) - xml.remove_namespaces! - xml end def toc_exclude_class diff --git a/lib/isodoc/presentation_function/xrefs.rb b/lib/isodoc/presentation_function/xrefs.rb index cdaa781e..981bca2f 100644 --- a/lib/isodoc/presentation_function/xrefs.rb +++ b/lib/isodoc/presentation_function/xrefs.rb @@ -1,7 +1,12 @@ module IsoDoc class PresentationXMLConvert < ::IsoDoc::Convert - def prefix_container(container, linkend, node, _target) - l10n(@i18n.nested_xref.sub("%1", anchor_xref(node, container)) + def prefix_container(container, linkend, node, target) + prefix_container?(container, node) or return linkend + container_container = @xrefs.anchor(container, :container, false) + container_label = + prefix_container(container_container, anchor_xref(node, container), + node, target) + l10n(@i18n.nested_xref.sub("%1", container_label) .sub("%2", linkend)) end @@ -31,8 +36,7 @@ def anchor_id_postproc(node) def anchor_linkend1(node) linkend = anchor_xref(node, node["target"]) container = @xrefs.anchor(node["target"], :container, false) - prefix_container?(container, node) and - linkend = prefix_container(container, linkend, node, node["target"]) + linkend = prefix_container(container, linkend, node, node["target"]) capitalise_xref(node, linkend, anchor_value(node["target"])) end diff --git a/lib/isodoc/xref/xref_gen_seq.rb b/lib/isodoc/xref/xref_gen_seq.rb index 6087e6b9..d77de679 100644 --- a/lib/isodoc/xref/xref_gen_seq.rb +++ b/lib/isodoc/xref/xref_gen_seq.rb @@ -24,24 +24,25 @@ def subfigure_increment(idx, counter, elem) .//figure[not(@class)] | .//figure[@class = 'pseudocode'] | .//sourcecode[not(ancestor::example)] XPATH - def sequential_figure_names(clause) + def sequential_figure_names(clause, container: false) c = Counter.new j = 0 clause.xpath(ns(FIGURE_NO_CLASS)).noblank.each do |t| j = subfigure_increment(j, c, t) - sequential_figure_body(j, c, t, "figure") + sequential_figure_body(j, c, t, "figure", container: container) end - sequential_figure_class_names(clause) + sequential_figure_class_names(clause, container: container) end - def sequential_figure_class_names(clause) + def sequential_figure_class_names(clause, container: false) c = {} j = 0 clause.xpath(ns(".//figure[@class][not(@class = 'pseudocode')]")) .each do |t| c[t["class"]] ||= Counter.new j = subfigure_increment(j, c[t["class"]], t) - sequential_figure_body(j, c[t["class"]], t, t["class"]) + sequential_figure_body(j, c[t["class"]], t, t["class"], + container: container) end end @@ -50,27 +51,28 @@ def subfigure_label(subfignum) "-#{subfignum}" end - def sequential_figure_body(subfignum, counter, block, klass) + def sequential_figure_body(subfig, counter, elem, klass, container: false) label = counter.print - label &&= label + subfigure_label(subfignum) - @anchors[block["id"]] = anchor_struct( - label, nil, @labels[klass] || klass.capitalize, klass, - block["unnumbered"] + label &&= label + subfigure_label(subfig) + @anchors[elem["id"]] = anchor_struct( + label, container ? elem : nil, + @labels[klass] || klass.capitalize, klass, + elem["unnumbered"] ) end - def sequential_table_names(clause) + def sequential_table_names(clause, container: false) c = Counter.new clause.xpath(ns(".//table")).noblank.each do |t| labelled_ancestor(t) and next @anchors[t["id"]] = anchor_struct( - c.increment(t).print, nil, + c.increment(t).print, container ? t : nil, @labels["table"], "table", t["unnumbered"] ) end end - def sequential_formula_names(clause) + def sequential_formula_names(clause, container: false) c = Counter.new clause.xpath(ns(".//formula")).noblank.each do |t| @anchors[t["id"]] = anchor_struct( @@ -91,60 +93,63 @@ def sequential_formula_names(clause) ./permission | ./requirement | ./recommendation XPATH - def sequential_permission_names(clause) + def sequential_permission_names(clause, container: false) c = ReqCounter.new clause.xpath(ns(FIRST_LVL_REQ)).noblank.each do |t| m = @reqt_models.model(t["model"]) klass, label = reqt2class_label(t, m) id = c.increment(label, t).print - sequential_permission_body(id, t, label, klass, m) - sequential_permission_children(t, id) + sequential_permission_body(id, t, label, klass, m, + container: container) + sequential_permission_children(t, id, container: container) end end - def sequential_permission_children(block, lbl) + def sequential_permission_children(elem, lbl, container: false) c = ReqCounter.new - block.xpath(ns(REQ_CHILDREN)).noblank.each do |t| + elem.xpath(ns(REQ_CHILDREN)).noblank.each do |t| m = @reqt_models.model(t["model"]) klass, label = reqt2class_nested_label(t, m) id = "#{lbl}#{hierfigsep}#{c.increment(label, t).print}" - sequential_permission_body(id, t, label, klass, m) - sequential_permission_children(t, id) + sequential_permission_body(id, t, label, klass, m, + container: container) + sequential_permission_children(t, id, container: container) end end - def sequential_permission_body(id, block, label, klass, model) - @anchors[block["id"]] = model.postprocess_anchor_struct( - block, anchor_struct(id, block, - label, klass, block["unnumbered"]) + def sequential_permission_body(id, elem, label, klass, model, container: false) + @anchors[elem["id"]] = model.postprocess_anchor_struct( + elem, anchor_struct(id, elem, + label, klass, elem["unnumbered"]) ) - model.permission_parts(block, id, label, klass).each do |n| + model.permission_parts(elem, id, label, klass).each do |n| @anchors[n[:id]] = anchor_struct(n[:number], n[:elem], n[:label], n[:klass], false) end end - def reqt2class_label(block, model) + def reqt2class_label(elem, model) model.req_class_paths.each do |n| v1 = ns("/#{n[:xpath]}").sub(%r{^/}, "") - block.at("./self::#{v1}") and return [n[:klass], n[:label]] + elem.at("./self::#{v1}") and return [n[:klass], n[:label]] end [nil, nil] end - def reqt2class_nested_label(block, model) + def reqt2class_nested_label(elem, model) model.req_nested_class_paths.each do |n| v1 = ns("/#{n[:xpath]}").sub(%r{^/}, "") - block.at("./self::#{v1}") and return [n[:klass], n[:label]] + elem.at("./self::#{v1}") and return [n[:klass], n[:label]] end [nil, nil] end - def sequential_asset_names(clause) - sequential_table_names(clause) - sequential_figure_names(clause) - sequential_formula_names(clause) - sequential_permission_names(clause) + # container makes numbering be prefixed with the parent clause reference + def sequential_asset_names(clause, container: false) + sequential_table_names(clause, container: container) + sequential_figure_names(clause, container: container) + sequential_formula_names(clause, container: container) + sequential_permission_names(clause, container: container) end def hierarchical_figure_names(clause, num) diff --git a/lib/isodoc/xref/xref_sect_gen.rb b/lib/isodoc/xref/xref_sect_gen.rb index 28c773ef..34afe959 100644 --- a/lib/isodoc/xref/xref_sect_gen.rb +++ b/lib/isodoc/xref/xref_sect_gen.rb @@ -129,6 +129,10 @@ def preface_names(clause) def back_names(clause) unnumbered_names(clause) + sequential_asset_names( + Nokogiri::XML::NodeSet.new(clause.document, [clause]), + container: true, + ) end def unnumbered_names(clause) @@ -237,8 +241,8 @@ def annex_names1(clause, num, level) def reference_names(ref) ids = @klass.bibitem_ref_code(ref) identifiers = @klass.render_identifier(ids) - reference = @klass. - docid_l10n(identifiers[:metanorma] || identifiers[:sdo] || + reference = @klass + .docid_l10n(identifiers[:metanorma] || identifiers[:sdo] || identifiers[:ordinal] || identifiers[:doi]) @anchors[ref["id"]] = { xref: reference } end diff --git a/spec/isodoc/xref_numbering_spec.rb b/spec/isodoc/xref_numbering_spec.rb index f9a14cf6..501b0eda 100644 --- a/spec/isodoc/xref_numbering_spec.rb +++ b/spec/isodoc/xref_numbering_spec.rb @@ -1,7 +1,6 @@ require "spec_helper" RSpec.describe IsoDoc do -=begin it "realises subsequences" do input = <<~INPUT @@ -283,7 +282,7 @@ .at("//xmlns:foreword").to_xml)) .to be_equivalent_to xmlpp(output) end -=end + it "realises branch-numbering overrides" do input = <<~INPUT diff --git a/spec/isodoc/xref_spec.rb b/spec/isodoc/xref_spec.rb index e4600df2..d74ec35c 100644 --- a/spec/isodoc/xref_spec.rb +++ b/spec/isodoc/xref_spec.rb @@ -110,6 +110,7 @@ +

@@ -158,6 +159,11 @@ + Bibliographical Section + +

These results are based on a study carried out on three different types of kernel.

+
+
INPUT output = <<~OUTPUT @@ -171,6 +177,7 @@ Annex A.1, Note Annex A.2, Note 1 Annex A.2, Note 2 + Bibliographical Section, Note

OUTPUT @@ -196,6 +203,7 @@ +

@@ -247,6 +255,11 @@ + Bibliographical Section + +

These results are based on a study carried out on three different types of kernel.

+
+
INPUT output = <<~OUTPUT @@ -261,6 +274,7 @@ Annex A.1, Box Annex A.2, Box 1 Annex A.2, Box 2 + Bibliographical Section, Box

OUTPUT @@ -282,6 +296,7 @@ 附属書 A.1のBox 附属書 A.2のBox 1 附属書 A.2のBox 2 + Bibliographical SectionのBox

OUTPUT @@ -310,6 +325,7 @@ +

@@ -380,6 +396,12 @@ + Bibliographical Section +
+ Split-it-right sample divider + +
+
INPUT output = <<~OUTPUT @@ -397,6 +419,7 @@ Figure (??) Figure A.2 Figure A.3 + Bibliographical Section, Figure 1

OUTPUT @@ -424,6 +447,7 @@ +

@@ -494,6 +518,12 @@ + Bibliographical Section +
+ Split-it-right sample divider + +
+
INPUT output = <<~OUTPUT @@ -511,6 +541,7 @@ Plate (??) Figure A.1 Figure A.2 + Bibliographical Section, Figure 1

OUTPUT @@ -532,6 +563,9 @@ + + +

@@ -571,6 +605,18 @@ + Bibliographical Section +
+
+ Split-it-right sample divider + +
+
+ Split-it-right sample divider + +
+
+
INPUT output = <<~OUTPUT @@ -582,6 +628,9 @@ Figure A.1 Figure A.1-1 Figure A.1-2 + Bibliographical Section, Figure 1 + Bibliographical Section, Figure 1-1 + Bibliographical Section, Figure 1-2

OUTPUT @@ -605,6 +654,7 @@ +

@@ -653,6 +703,11 @@ + Bibliographical Section + +

Hello

+
+
INPUT @@ -667,6 +722,7 @@ Annex A.1, Example Annex A.2, Example (??) Annex A.2, Example 1 + Bibliographical Section, Example

OUTPUT @@ -715,6 +771,7 @@ +

@@ -763,6 +820,11 @@ + Bibliographical Section + + r = 1 % + + INPUT output = <<~OUTPUT @@ -776,6 +838,7 @@ Formula (A.1) Formula ((??)) Formula (A.2) + Bibliographical Section, Formula (1)

OUTPUT @@ -799,6 +862,7 @@ +

@@ -847,6 +911,11 @@ + Bibliographical Section + + r = 1 % + + INPUT output = <<~OUTPUT @@ -860,6 +929,7 @@ Requirement A.1 Requirement (??) Requirement A.2 + Bibliographical Section, Requirement 1

OUTPUT @@ -883,6 +953,7 @@ +

@@ -931,6 +1002,11 @@ + Bibliographical Section + + r = 1 % + + INPUT output = <<~OUTPUT @@ -944,6 +1020,7 @@ Recommendation A.1 Recommendation (??) Recommendation A.2 + Bibliographical Section, Recommendation 1

OUTPUT @@ -967,6 +1044,7 @@ +

@@ -1015,6 +1093,11 @@ + Bibliographical Section + + r = 1 % + + INPUT output = <<~OUTPUT @@ -1028,6 +1111,7 @@ Permission A.1 Permission (??) Permission A.2 + Bibliographical Section, Permission 1

OUTPUT @@ -1053,6 +1137,11 @@ + + + + +

@@ -1082,6 +1171,18 @@ + Bibliographical Section + + + + + + + + + + + INPUT output = <<~OUTPUT @@ -1097,6 +1198,11 @@ Permission A.1-1-1 Requirement A.1-1 Recommendation A.1-1 + Bibliographical Section, Permission 1 + Bibliographical Section, Permission 1-1 + Bibliographical Section, Permission 1-1-1 + Bibliographical Section, Requirement 1-1 + Bibliographical Section, Recommendation 1-1

OUTPUT @@ -1120,6 +1226,7 @@ +

@@ -1224,6 +1331,18 @@ + Bibliographical Section + + Repeatability and reproducibility of husked rice yield + + + + + + + +
Number of laboratories retained after eliminating outliers1311
+
INPUT output = <<~OUTPUT @@ -1237,6 +1356,7 @@ Table A.1 Table (??) Table A.2 + Bibliographical Section, Table 1

OUTPUT @@ -1508,11 +1628,11 @@ - + Normative References Bibliography - + Bibliography Subsection @@ -1566,6 +1686,7 @@ +

@@ -1612,6 +1733,11 @@ + Bibliographical Section +
    +

    These results are based on a study carried out on three different types of kernel.

    +
+
INPUT output = <<~OUTPUT @@ -1625,6 +1751,7 @@ Annex A.1, List Annex A.2, List 1 Annex A.2, List 2 + Bibliographical Section, List

OUTPUT @@ -1651,6 +1778,7 @@ +

@@ -1702,6 +1830,11 @@ + Bibliographical Section +
    +
  1. A

  2. +
+
INPUT output = <<~OUTPUT @@ -1717,6 +1850,7 @@ Annex A.1, A) Annex A.2, List 1 iv) Annex A.2, List 2 a) + Bibliographical Section, a)

OUTPUT @@ -1739,6 +1873,7 @@ 附属書 A.1のA) 附属書 A.2のリスト 1のiv) 附属書 A.2のリスト 2のa) + Bibliographical Sectionのa)

OUTPUT @@ -1839,6 +1974,7 @@ +

@@ -1885,6 +2021,11 @@ + Bibliographical Section +
+

These results are based on a study carried out on three different types of kernel.

+
+
INPUT output = <<~OUTPUT @@ -1898,6 +2039,7 @@ Annex A.1, Definition List Annex A.2, Definition List 1 Annex A.2, Definition List 2 + Bibliographical Section, Definition List

OUTPUT @@ -1921,6 +2063,7 @@ +

@@ -1967,6 +2110,11 @@ + Bibliographical Section +
+

A

+
+
INPUT output = <<~OUTPUT @@ -1980,6 +2128,7 @@ Annex A.1, Definition List: A Annex A.2, Definition List 1: A Annex A.2, Definition List 2: A + Bibliographical Section, Definition List: A

OUTPUT @@ -2055,6 +2204,7 @@ +

@@ -2102,6 +2252,11 @@

+ Bibliographical Section +

+ +

+
INPUT output = <<~OUTPUT @@ -2115,6 +2270,7 @@ Annex A.1 Figure A.1 Annex A.2 + Bibliographical Section

OUTPUT