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
These results are based on a study carried out on three different types of kernel.
+These results are based on a study carried out on three different types of kernel.
+Hello
+Number of laboratories retained after eliminating outliers | +13 | +11 | +
These results are based on a study carried out on three different types of kernel.
+A
These results are based on a study carried out on three different types of kernel.
+A
+