metanorma-plateau 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ require_relative "init"
2
+
3
+ module IsoDoc
4
+ module Plateau
5
+ class PresentationXMLConvert < IsoDoc::JIS::PresentationXMLConvert
6
+ def toc_title_insert_pt(docxml)
7
+ i = preface_init_insert_pt(docxml) or return nil
8
+ a = i.at(ns("./abstract[last()] | ./clause[@type = 'revhistory']")) and
9
+ return a.after(" ").next
10
+ i.children.first
11
+ end
12
+
13
+ def preface_init_insert_pt(docxml)
14
+ ret = docxml.at(ns("//preface")) ||
15
+ docxml.at(ns("//sections | //annex | //bibliography"))
16
+ &.add_previous_sibling("<preface> </preface>")&.first
17
+ ret.nil? and return nil
18
+ ret.children.empty? and ret << " "
19
+ ret
20
+ end
21
+
22
+ def source(docxml)
23
+ super
24
+ docxml.xpath(ns("//p/source")).each { |f| parasource(f) }
25
+ docxml.xpath(ns("//ul/source")).each { |f| listsource(f) }
26
+ docxml.xpath(ns("//ol/source")).each { |f| listsource(f) }
27
+ docxml.xpath(ns("//dl/source")).each { |f| listsource(f) }
28
+ end
29
+
30
+ def parasource(elem)
31
+ source1(elem)
32
+ # if we haven't already removed it...
33
+ elem.parent or return
34
+ elem.name = "p"
35
+ elem.delete("status")
36
+ elem.parent.next = elem
37
+ end
38
+
39
+ def listsource(elem)
40
+ source1(elem)
41
+ elem.parent or return
42
+ elem.name = "p"
43
+ elem.delete("status")
44
+ elem.parent.next = elem
45
+ end
46
+
47
+ def middle_title(docxml); end
48
+
49
+ def rearrange_clauses(docxml)
50
+ super
51
+ revhistory(docxml)
52
+ end
53
+
54
+ def revhistory(docxml)
55
+ a = docxml.at(ns("//clause[@type = 'revhistory']"))&.remove or return
56
+ pref = preface_init_insert_pt(docxml) or return nil
57
+ ins = if b = pref.at(ns("./abstract[last()]"))
58
+ b.after(" ").next
59
+ else pref.children.first
60
+ end
61
+ ins.previous = a
62
+ end
63
+
64
+ def commentary_title_hdr(elem)
65
+ ret = <<~COMMENTARY
66
+ <p class="CommentaryStandardNumber">#{@meta.get[:docnumber_undated]}
67
+ COMMENTARY
68
+ yr = @meta.get[:docyear] and
69
+ ret += ": <span class='CommentaryEffectiveYear'>#{yr}</span>"
70
+ elem.previous = ret
71
+ end
72
+
73
+ include Init
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,107 @@
1
+ module IsoDoc
2
+ module Plateau
3
+ class Counter < IsoDoc::XrefGen::Counter
4
+ end
5
+
6
+ class Xref < IsoDoc::JIS::Xref
7
+ def clause_order_main(_docxml)
8
+ [
9
+ {
10
+ path: "//sections/introduction | //sections/clause | " \
11
+ "//sections/terms | //sections/definitions | " \
12
+ "//sections/references", multi: true
13
+ },
14
+ ]
15
+ end
16
+
17
+ def middle_section_asset_names(doc)
18
+ middle_sections =
19
+ "//clause[@type = 'scope'] | #{@klass.norm_ref_xpath} | " \
20
+ "//sections/terms | //preface/* | " \
21
+ "//sections/definitions | //clause[parent::sections]"
22
+ # sequential_asset_names(doc.xpath(ns(middle_sections)))
23
+ middle_asset_names(doc.xpath(ns(middle_sections)))
24
+ end
25
+
26
+ def hiersep
27
+ "-"
28
+ end
29
+
30
+ # container makes numbering be prefixed with the parent clause reference
31
+ def middle_asset_names(clause, container: false)
32
+ sequential_formula_names(clause, container:)
33
+ sequential_permission_names(clause, container:)
34
+ clause.each do |c|
35
+ num = @anchors.dig(c["id"], :label) || @anchors.dig(c["id"], :xref) ||
36
+ c.at(ns("./title"))&.text
37
+ hierarchical_table_names(c, num)
38
+ hierarchical_figure_names(c, num)
39
+ end
40
+ end
41
+
42
+ def section_name_anchors(clause, num, level)
43
+ super
44
+ if level >= 4 && level <= 6
45
+ label, xref = section_name_anchors_deep(num, level)
46
+ @anchors[clause["id"]][:label] = label
47
+ @anchors[clause["id"]][:xref] = l10n(xref)
48
+ end
49
+ end
50
+
51
+ def section_name_anchors_deep(num, level)
52
+ numparts = num.split(".")
53
+ core = numparts[0..2].join(".")
54
+ (4..level).each do |l|
55
+ core += " #{section_name_label_deep(numparts[l - 1], l)}"
56
+ end
57
+ [section_name_label_deep(numparts[-1], level), l10n(core)]
58
+ end
59
+
60
+ def section_name_label_deep(num, level)
61
+ case level
62
+ when 4 then l10n("(#{num})")
63
+ when 5 then l10n("#{num})")
64
+ when 6
65
+ ("" << (num.to_i + 0x245f))
66
+ end
67
+ end
68
+
69
+ def annex_name_anchors1(clause, num, level)
70
+ super
71
+ if level >= 4 && level <= 6
72
+ label, xref = section_name_anchors_deep(num, level)
73
+ @anchors[clause["id"]][:label] = label
74
+ @anchors[clause["id"]][:xref] = l10n(xref)
75
+ end
76
+ end
77
+
78
+ def hierarchical_figure_names(clause, num)
79
+ c = IsoDoc::XrefGen::Counter.new
80
+ j = 0
81
+ clause.xpath(ns(FIGURE_NO_CLASS)).noblank.each do |t|
82
+ labelled_ancestor(t, %w(figure)) and next # do not label nested figure
83
+ j = subfigure_increment(j, c, t)
84
+ label = "#{num}#{hiersep}#{c.print}"
85
+ sublabel = subfigure_label(j)
86
+ figure_anchor(t, sublabel, label, "figure")
87
+ end
88
+ hierarchical_figure_class_names(clause, num)
89
+ end
90
+
91
+ def hierarchical_figure_class_names(clause, num)
92
+ c = {}
93
+ j = 0
94
+ clause.xpath(ns(".//figure[@class][not(@class = 'pseudocode')]"))
95
+ .noblank.each do |t|
96
+ c[t["class"]] ||= IsoDoc::XrefGen::Counter.new
97
+ labelled_ancestor(t, %w(figure)) and next
98
+ j = subfigure_increment(j, c[t["class"]], t)
99
+ label = "#{num}#{hiersep}#{c.print}"
100
+ sublabel = j.zero? ? nil : "#{(j + 96).chr})"
101
+ figure_anchor(t, sublabel, label, t["class"])
102
+ end
103
+ end
104
+
105
+ end
106
+ end
107
+ end