Class: IsoDoc::Iso::PresentationXMLConvert

Inherits:
PresentationXMLConvert
  • Object
show all
Includes:
Init
Defined in:
lib/isodoc/iso/presentation_xref.rb,
lib/isodoc/iso/presentation_terms.rb,
lib/isodoc/iso/presentation_origin.rb,
lib/isodoc/iso/presentation_bibdata.rb,
lib/isodoc/iso/presentation_section.rb,
lib/isodoc/iso/presentation_xml_convert.rb

Constant Summary collapse

LOCALITY2SPAN =

ISO has not bothered to communicate to us what most of these span classes mean

{
  annex: "citeapp",
  dunno: "citebase",
  dunno2: "citebib",
  dunno3: "citebox",
  dunno4: "citeen",
  dunno5: "citeeq",
  figure: "citefig",
  dunno6: "citefn",
  clause: "citesec",
  dunno7: "citesection",
  table: "citetbl",
  dunno8: "citetfn",
}.freeze
ISO_PUBLISHER_XPATH =

TODO share with metanorma dir

<<~XPATH.freeze
  ./contributor[role/@type = 'publisher']/organization[abbreviation = 'ISO' or abbreviation = 'IEC' or name = 'International Organization for Standardization' or name = 'International Electrotechnical Commission']
XPATH

Instance Method Summary collapse

Methods included from Init

#amd?, #bibrenderer, #clausedelim, #i18n_conditional_set, #i18n_init, #metadata_init, #requirements_processor, #std_docid_semantic, #std_docid_semantic1, #std_docid_semantic_full, #update_i18n

Instance Method Details

#admonition1(elem) ⇒ Object



76
77
78
79
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 76

def admonition1(elem)
  super
  admonition_outside_clauses(elem)
end

#admonition_delim(elem) ⇒ Object



181
182
183
184
185
186
187
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 181

def admonition_delim(elem)
  if elem.at("./*[not(self::xmlns:name)]")&.name == "p"
    " &#x2014; "
  else
    ""
  end
end

#admonition_outside_clauses(elem) ⇒ Object



81
82
83
84
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 81

def admonition_outside_clauses(elem)
  elem.parent.name == "sections" or return
  wrap_in_bold(elem)
end

#anchor_linkend1(node) ⇒ Object



146
147
148
149
# File 'lib/isodoc/iso/presentation_xref.rb', line 146

def anchor_linkend1(node)
  locality_span_wrap(super, @xrefs.anchor(node["target"], :subtype) ||
                     @xrefs.anchor(node["target"], :type))
end

#anchor_value(id) ⇒ Object



141
142
143
144
# File 'lib/isodoc/iso/presentation_xref.rb', line 141

def anchor_value(id)
  locality_span_wrap(super, @xrefs.anchor(id, :subtype) ||
                     @xrefs.anchor(id, :type))
end

#annex(isoxml) ⇒ Object

Redo Amendment annex titles as numbered



44
45
46
47
48
# File 'lib/isodoc/iso/presentation_section.rb', line 44

def annex(isoxml)
  amd?(isoxml) and @suppressheadingnumbers = @oldsuppressheadingnumbers
  super
  amd?(isoxml) and @suppressheadingnumbers = true
end

#bibdata_i18n(bib) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 4

def bibdata_i18n(bib)
  hash_translate(bib, @i18n.get["doctype_dict"], "./ext/doctype",
                 "//presentation-metadata/doctype-alias", @lang)
  bibdata_i18n_stage(bib, bib.at(ns("./status/stage")),
                     bib.at(ns("./ext/doctype")))
  hash_translate(bib, @i18n.get["substage_dict"],
                 "./status/substage", nil, @lang)
  hash_translate(bib, @i18n.get["contributor_role_desc_dict"],
                 "./contributor/role/description", nil, @lang)
  edition_translate(bib)
end

#bibdata_i18n_stage(bib, stage, type, lang: @lang, i18n: @i18n) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 41

def bibdata_i18n_stage(bib, stage, type, lang: @lang, i18n: @i18n)
  stage or return
  i18n.get.dig("stage_dict", stage.text).is_a?(Hash) or
    return hash_translate(bib, i18n.get["stage_dict"],
                          "./status/stage", nil, lang)
  bibdata_i18n_stage1(stage, type, lang, i18n)
end

#bibdata_i18n_stage1(stage, type, lang, i18n) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 49

def bibdata_i18n_stage1(stage, type, lang, i18n)
  stagetype = i18n.get.dig("stage_dict", stage.text, type&.text) or return
  h = i18n.get.dig("stage_draft_variants", stagetype) and h.each do |k, v|
    tag_translate(stage, lang, v)
    stage.next["type"] = k
  end
  tag_translate(stage, lang, stagetype)
end

#bibrender_formattedref(formattedref, xml) ⇒ Object



93
94
95
96
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 93

def bibrender_formattedref(formattedref, xml)
  %w(techreport standard).include? xml["type"] and return
  super
end

#block(docxml) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 27

def block(docxml)
  amend docxml
  figure docxml
  sourcecode docxml
  formula docxml
  admonition docxml
  source docxml
  ul docxml
  ol docxml
  quote docxml
  permission docxml
  requirement docxml
  recommendation docxml
  requirement_render docxml
  @xrefs.anchors_previous = 
    @xrefs.anchors.transform_values(&:dup) # store old xrefs of reqts
  @xrefs.parse docxml
  # TODO move this dependency around: requirements at root should be processed before everything else
  table docxml # have table include requirements newly converted to tables
  # table feeds dl
  dl docxml
  example docxml
  note docxml
end

#bracket_eref_original(elem) ⇒ Object

is the eref corresponding to this semx a simple [n] reference?



50
51
52
53
54
55
56
57
# File 'lib/isodoc/iso/presentation_origin.rb', line 50

def bracket_eref_original(elem)
  semx = elem.document.at("//*[@id = '#{elem['source']}']") or return
  dup = elem.at(ns(".//fmt-eref | .//fmt-xref | .//fmt-origin"))
  non_locality_elems(semx).empty? or return
  /^\[\d+\]$/.match?(semx["citeas"]) or return
  %w(full short).include?(dup["style"]) and return
  semx
end

#bracket_eref_style(elem) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/isodoc/iso/presentation_origin.rb', line 38

def bracket_eref_style(elem)
  semx = bracket_eref_original(elem) or return
  if semx["style"] == "superscript"
    elem.children.wrap("<sup></sup>")
    remove_preceding_space(elem)
  else
    r = @i18n.reference
    elem.add_first_child l10n("#{r} ")
  end
end

#bracket_erefstack_style(elem) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/isodoc/iso/presentation_origin.rb', line 59

def bracket_erefstack_style(elem)
  semx, erefstack_orig = bracket_erefstack_style_prep(elem)
  semx.empty? and return
  if erefstack_orig && erefstack_orig["style"]
    elem.children.each do |e|
      e.name == "span" and e.remove
      e.text.strip.empty? and e.remove
    end
    elem.children.wrap("<sup></sup>")
    remove_preceding_space(elem)
  else
    r = @i18n.inflect(@i18n.reference, number: "pl")
    elem.add_first_child l10n("#{r} ")
  end
end

#bracket_erefstack_style_prep(elem) ⇒ Object



75
76
77
78
79
80
# File 'lib/isodoc/iso/presentation_origin.rb', line 75

def bracket_erefstack_style_prep(elem)
  semx = elem.xpath(ns(".//semx[@element = 'eref']"))
    .map { |e| bracket_eref_original(e) }.compact
  erefstack_orig = elem.document.at("//*[@id = '#{elem['source']}']")
  [semx, erefstack_orig]
end

#bracket_origin_style(elem) ⇒ Object



82
83
84
85
# File 'lib/isodoc/iso/presentation_origin.rb', line 82

def bracket_origin_style(elem)
  bracket_eref_style(elem)
  insert_biblio_callout(elem)
end

#bracketed_refs_processing(docxml) ⇒ Object

style [1] references as [Reference 1], eref or origin



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/isodoc/iso/presentation_origin.rb', line 26

def bracketed_refs_processing(docxml)
  (docxml.xpath(ns("//semx[@element = 'eref']")) -
  docxml.xpath(ns("//semx[@element = 'erefstack']//semx[@element = 'eref']")))
    .each { |n| bracket_eref_style(n) }
  docxml.xpath(ns("//semx[@element = 'erefstack']")).each do |n|
    bracket_erefstack_style(n)
  end
  docxml.xpath(ns("//semx[@element = 'origin']")).each do |n|
    bracket_origin_style(n)
  end
end

#can_conflate_eref_rendering?(refs) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
# File 'lib/isodoc/iso/presentation_xref.rb', line 15

def can_conflate_eref_rendering?(refs)
  super or return false
  first = subclause?(nil, refs.first.at(ns("./locality/@type"))&.text,
                     refs.first.at(ns("./locality/referenceFrom"))&.text)
  refs.all? do |r|
    subclause?(nil, r.at(ns("./locality/@type"))&.text,
               r.at(ns("./locality/referenceFrom"))&.text) == first
  end
end

#citeas_cleanup1(citeas) ⇒ Object



216
217
218
219
220
221
222
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 216

def citeas_cleanup1(citeas)
  ret = super
  if /^\[\d+\]$/.match?(ret)
    ret = @i18n.l10n("#{@i18n.reference} #{ret}")
  end
  ret
end

#clause(docxml) ⇒ Object

Redo Amendment annex subclause titles as numbered



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/isodoc/iso/presentation_section.rb', line 51

def clause(docxml)
  super
  # docxml.xpath(ns("//annex//appendix")).each { |f| clause1(f) }
  amd?(docxml) or return
  @suppressheadingnumbers = @oldsuppressheadingnumbers
  docxml.xpath(ns("//annex//clause | //annex//appendix")).each do |f|
    f.xpath(ns("./fmt-title | ./fmt-xref-label")).each(&:remove)
    clause1(f)
  end
  @suppressheadingnumbers = true
end

#clause1(node) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/isodoc/iso/presentation_section.rb', line 63

def clause1(node)
  !node.at(ns("./title")) &&
    !%w(sections preface bibliography).include?(node.parent.name) and
    node["inline-header"] = "true"
  super
  clause1_section_prefix(node)
end

#clause1_section_prefix(node) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/isodoc/iso/presentation_section.rb', line 71

def clause1_section_prefix(node)
  if node["type"] == "section" &&
      c = node.at(ns("./fmt-title//span[@class = 'fmt-caption-delim']"))
    c.add_first_child(":")
    t = node.at(ns("./fmt-title"))
    # French l10n needs tab to be treated as space
    t.replace @i18n.l10n(to_xml(t).gsub("<tab/>", "<tab> </tab>"))
      .gsub(%r{<tab>[^<]+</tab>}, "<tab/>")
  end
end

#comments(docxml) ⇒ Object



4
5
6
7
# File 'lib/isodoc/iso/presentation_section.rb', line 4

def comments(docxml)
  (docxml)
  super
end

#concept(docxml) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/isodoc/iso/presentation_terms.rb', line 10

def concept(docxml)
  concept_term(docxml)
  (docxml.xpath(ns("//concept")) - docxml.xpath(ns("//term//concept")))
    .each do |node|
    node.ancestors("definition, source, related").empty? and
      concept_render(node, ital: "false", ref: "false",
                           linkref: "true", linkmention: "false")
  end
end

#concept1(node) ⇒ Object



53
54
55
56
57
# File 'lib/isodoc/iso/presentation_terms.rb', line 53

def concept1(node)
  node.replace(node&.at(ns("./renderterm"))&.children ||
               node&.at(ns("./refterm"))&.children ||
               node.children)
end

#concept1_ref_content(ref) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/isodoc/iso/presentation_terms.rb', line 43

def concept1_ref_content(ref)
  prev = "("
  foll = ")"
  if ref.name == "termref"
    prev, foll = @i18n.term_defined_in.split("%")
  end
  ref.previous = prev
  ref.next = foll
end

#concept_term(docxml) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/isodoc/iso/presentation_terms.rb', line 20

def concept_term(docxml)
  docxml.xpath(ns("//term")).each do |f|
    m = {}
    (f.xpath(ns(".//concept")) - f.xpath(ns(".//term//concept")))
      .each do |c|
        c.ancestors("definition, source, related").empty? and
          concept_term1(c, m)
      end
  end
end

#concept_term1(node, seen) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/isodoc/iso/presentation_terms.rb', line 31

def concept_term1(node, seen)
  term = to_xml(node.at(ns("./refterm")))
  if term && seen[term]
    concept_render(node, ital: "false", ref: "false",
                         linkref: "true", linkmention: "false")
  else concept_render(node, ital: "true", ref: "true",
                            linkref: "true", linkmention: "false")
  end
  seen[term] = true if term
  seen
end

#convert1(docxml, filename, dir) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 18

def convert1(docxml, filename, dir)
  @iso_class = instance_of?(IsoDoc::Iso::PresentationXMLConvert)
  if amd?(docxml)
    @oldsuppressheadingnumbers = @suppressheadingnumbers
    @suppressheadingnumbers = true
  end
  super
end

#convert_i18n_init(docxml) ⇒ Object



13
14
15
16
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 13

def convert_i18n_init(docxml)
  super
  update_i18n(docxml)
end

#edition_printing_date(bibdata) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 24

def edition_printing_date(bibdata)
  @i18n.get["date_printing"] &&
    pd = bibdata.at(ns("//metanorma-extension/presentation-metadata/" \
                       "printing-date[1]")) or return
  x = @i18n.populate("date_printing", { "var1" => pd.text.to_i })
  bibdata.at(ns("./ext")) << "<date-printing>#{x}</date-printing>"
end

#edition_replacement(bibdata) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 32

def edition_replacement(bibdata)
  e = bibdata.at(ns("./edition[not(@language) or @language = '']"))&.text
  if /^\d+$/.match?(e) && e.to_i > 1
    h = { "var1" => e.to_i, "var2" => e.to_i - 1 }
    x = @i18n.populate("edition_replacement", h)
    bibdata.at(ns("./ext")) << "<edn-replacement>#{x}</edn-replacement>"
  end
end

#edition_translate(bibdata) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 16

def edition_translate(bibdata)
  super
  @lang == "fr" and e = bibdata.at(ns("./edition[@language = 'fr']")) and
    e.children = e.text.sub(/(\d+)(\p{L}+)/, "\\1<sup>\\2</sup>")
  @docscheme == "1951" and edition_replacement(bibdata)
  edition_printing_date(bibdata)
end

#enable_indexsectObject



148
149
150
# File 'lib/isodoc/iso/presentation_section.rb', line 148

def enable_indexsect
  true
end

#eref_delim(delim, type) ⇒ Object



9
10
11
12
13
# File 'lib/isodoc/iso/presentation_xref.rb', line 9

def eref_delim(delim, type)
  if delim == ";" then ";"
  else type == "list" ? " " : delim
  end
end

#eref_localities1(opt) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/isodoc/iso/presentation_xref.rb', line 95

def eref_localities1(opt)
  opt[:type] == "anchor" and return nil
  opt[:type] = opt[:type].downcase
  %w(zh ko ja).include?(opt[:lang]) and
    return l10n(eref_localities1_zh(opt))
  ret = ""
  opt[:node]["droploc"] != "true" &&
    !subclause?(opt[:target], opt[:type], opt[:from]) and
    ret = eref_locality_populate(opt[:type], opt[:node], opt[:number])
  ret += " #{opt[:from]}" if opt[:from]
  ret += "&#x2013;#{opt[:upto]}" if opt[:upto]
  ret += ")" if opt[:type] == "list"
  ret = l10n(ret)
  locality_span_wrap(ret, opt[:type])
end

#eref_localities1_zh(opt) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/isodoc/iso/presentation_xref.rb', line 85

def eref_localities1_zh(opt)
  ret = " 第<esc>#{opt[:from]}</esc>" if opt[:from]
  ret += "&#x2013;<esc>#{opt[:upto]}</esc>" if opt[:upto]
  opt[:node]["droploc"] != "true" &&
    !subclause?(opt[:target], opt[:type], opt[:from]) and
    ret += eref_locality_populate(opt[:type], opt[:node], "sg")
  ret += ")" if opt[:type] == "list"
  locality_span_wrap(ret, opt[:type])
end

#eref_localities_conflated(refs, target, node) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/isodoc/iso/presentation_xref.rb', line 30

def eref_localities_conflated(refs, target, node)
  droploc = node["droploc"]
  node["droploc"] = true
  ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
                                                      node))
  node["droploc"] = droploc
  eref_localities1({ target:, number: "pl",
                     type: prefix_clause(target,
                                         refs.first.at(ns("./locality"))),
                     from: l10n(ret[1..].join),
                     node:, lang: @lang })
end

#example_span_label(_node, div, name) ⇒ Object



69
70
71
72
73
74
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 69

def example_span_label(_node, div, name)
  name.nil? and return
  div.span class: "example_label" do |_p|
    name.children.each { |n| parse(n, div) }
  end
end

#expand_citeas(text) ⇒ Object



135
136
137
138
139
# File 'lib/isodoc/iso/presentation_xref.rb', line 135

def expand_citeas(text)
  ret = super or return
  ret.include?("<span") and return ret
  std_docid_semantic(super)
end

#figure_delim(elem) ⇒ Object



56
57
58
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 56

def figure_delim(elem)
  elem.at("./ancestor::xmlns:figure") ? "&#xa0; " : "&#xa0;&#x2014; "
end

#figure_label?(_elem) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 65

def figure_label?(_elem)
  true
end

#figure_name(elem) ⇒ Object



60
61
62
63
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 60

def figure_name(elem)
  elem.at("./ancestor::xmlns:figure") and return ""
  super
end

#fmt_origin_cite_full?(elem) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/isodoc/iso/presentation_origin.rb', line 17

def fmt_origin_cite_full?(elem)
  sem_xml_descendant?(elem) and return
  id = elem["bibitemid"] or return
  b = @bibitem_lookup[id] or return
  b["type"] != "standard" ||
    !b.at(ns("./docidentifier[not(@type = 'metanorma' or @type = 'metanorma-ordinal')]"))
end

#fn_ref_label(fnote) ⇒ Object



206
207
208
209
210
211
212
213
214
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 206

def fn_ref_label(fnote)
  if fnote.ancestors("table, figure").empty? ||
      !fnote.ancestors("name, fmt-name").empty?
    "<sup>#{fn_label(fnote)}" \
      "<span class='fmt-label-delim'>)</span></sup>"
  else
    super
  end
end

#formula_where(dlist) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 113

def formula_where(dlist)
  dlist.nil? and return
  dlist.xpath(ns("./dt")).size == 1 &&
    dlist.at(ns("./dd"))&.elements&.size == 1 &&
    dlist.at(ns("./dd/p")) or return super
  formula_where_one(dlist)
end

#formula_where_one(dlist) ⇒ Object



121
122
123
124
125
126
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 121

def formula_where_one(dlist)
  dt = to_xml(dlist.at(ns("./dt")).children)
  dd = to_xml(dlist.at(ns("./dd/p")).children)
  dlist.previous = "<p>#{@i18n.where_one} #{dt} #{dd}</p>"
  dlist.remove
end

#implicit_reference(bib) ⇒ Object



170
171
172
173
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 170

def implicit_reference(bib)
  bib.at(ns("./docidentifier"))&.text == "IEV" and return true
  super
end

#insert_biblio_callout(elem) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/isodoc/iso/presentation_origin.rb', line 92

def insert_biblio_callout(elem)
  semx = elem.document.at("//*[@id = '#{elem['source']}']") or return
  if ref = @bibitem_lookup[semx["bibitemid"]]
    ref.at(ns(ISO_PUBLISHER_XPATH)) and return
    # is this reference cited with a [n],
    # even if it has its own SDO identifier?
    citeas = ref.at(ns("./docidentifier[@type = 'metanorma-ordinal']")) ||
      ref.at(ns("./docidentifier[@type = 'metanorma']")) ||
      ref.at(ns("./docidentifier[@scope = 'biblio-tag']"))
    citeas = citeas.text
  else
    citeas = semx["citeas"]
  end
  /^\[\d+\]$/.match?(citeas) or return
  elem << <<~XML
    <fmt-xref target='#{semx['bibitemid']}'><sup>#{citeas}</sup></fmt-xref>
  XML
end

#insertall_after_here(node, insert, name) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/isodoc/iso/presentation_terms.rb', line 59

def insertall_after_here(node, insert, name)
  node.children.each do |n|
    n.name == name or next
    insert.next = n.remove
    insert = n
  end
  insert
end

#labelled_ancestor(elem, exceptions = []) ⇒ Object



160
161
162
163
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 160

def labelled_ancestor(elem, exceptions = [])
  elem["class"] == "modspec" and return false
  super
end

#locality_delimiter(loc) ⇒ Object



25
26
27
28
# File 'lib/isodoc/iso/presentation_xref.rb', line 25

def locality_delimiter(loc)
  loc&.next_element&.attribute("type")&.text == "list" and return " "
  super
end

#locality_span_wrap(ret, type) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/isodoc/iso/presentation_xref.rb', line 76

def locality_span_wrap(ret, type)
  type or return ret
  m = /\A(\s*)(?=\S)(.+?)(\s*)\Z/m.match(ret) or return ret
  ret = [m[1], m[2], m[3]]
  spanclass = LOCALITY2SPAN[type.to_sym] and
    ret[1] = "<span class='#{spanclass}'>#{ret[1]}</span>"
  ret.join
end

#middle_title_amdObject



131
132
133
134
135
136
137
138
# File 'lib/isodoc/iso/presentation_section.rb', line 131

def middle_title_amd
  <<~OUTPUT
    {% if doctitleamdlabel %}<p class='zzSTDTitle2'>{{ doctitleamdlabel -}}
      {% if doctitleamd %}: {{doctitleamd}}{% endif -%}
      </p>{% endif %}
    {% if doctitlecorrlabel %}<p class='zzSTDTitle2'>{{ doctitlecorrlabel }}</p>{% endif %}
  OUTPUT
end

#middle_title_amdxObject

KILL



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/isodoc/iso/presentation_section.rb', line 119

def middle_title_amdx
  ret = ""
  if a = @meta.get[:doctitleamdlabel]
    ret += "<p class='zzSTDTitle2'>#{a}"
    a = @meta.get[:doctitleamd] and ret += ": #{a}"
    ret += "</p>"
  end
  a = @meta.get[:doctitlecorrlabel] and
    ret += "<p class='zzSTDTitle2'>#{a}</p>"
  ret
end

#middle_title_mainObject



87
88
89
90
91
92
93
94
# File 'lib/isodoc/iso/presentation_section.rb', line 87

def middle_title_main
  <<~OUTPUT
    <p class='zzSTDTitle1'><span class='boldtitle'>{{ doctitleintro -}}
    {% if doctitleintro and doctitlemain %} &#x2014; {% endif %}{{ doctitlemain -}}
    {% if doctitlemain %}{% if doctitlepart or doctitlecomplementary %} &#x2014; {% endif %}{% endif -%}
    </span>#{middle_title_part}</p>
  OUTPUT
end

#middle_title_partObject



109
110
111
112
113
114
115
116
# File 'lib/isodoc/iso/presentation_section.rb', line 109

def middle_title_part
  <<~OUTPUT.strip
    {% if doctitlecomplementary %}<span class='boldtitle'>{{ doctitlecomplementary }}</span>
    {% elsif doctitlepart -%}
      {% if doctitlepartlabel %}<span class='nonboldtitle'>{{ doctitlepartlabel }}:</span>{% endif -%}
    <span class='boldtitle'>{{ doctitlepart }}</span>{% endif %}
  OUTPUT
end

#middle_title_partxObject

KILL



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/isodoc/iso/presentation_section.rb', line 97

def middle_title_partx
  ret = ""
  if a = @meta.get[:doctitlecomplementary]
    ret += "<span class='boldtitle'>#{a}</span>"
  elsif a = @meta.get[:doctitlepart]
    b = @meta.get[:doctitlepartlabel] and
      ret += "<span class='nonboldtitle'>#{b}:</span> "
    ret += "<span class='boldtitle'>#{a}</span>"
  end
  ret
end

#middle_title_templateObject



140
141
142
# File 'lib/isodoc/iso/presentation_section.rb', line 140

def middle_title_template
  middle_title_main + middle_title_amd
end

#move_norm_ref_to_sections(docxml) ⇒ Object



144
145
146
# File 'lib/isodoc/iso/presentation_section.rb', line 144

def move_norm_ref_to_sections(docxml)
  amd?(docxml) or super
end

#note1(elem) ⇒ Object



103
104
105
106
107
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 103

def note1(elem)
  elem["type"] == "units" and return
  elem["type"] == "requirement" and return requirement_note1(elem)
  super
end

#ol_depth(node) ⇒ Object



98
99
100
101
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 98

def ol_depth(node)
  depth = node.ancestors(@iso_class ? "ol" : "ul, ol").size + 1
  @counter.ol_type(node, depth)
end

#ol_label_template(_elem) ⇒ Object



197
198
199
200
201
202
203
204
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 197

def ol_label_template(_elem)
  ret = super
  @docscheme == "1951" and
    ret[:alphabet] = <<~SPAN.strip
      <span class="fmt-label-delim">(</span>%<span class="fmt-label-delim">)</span>
    SPAN
  ret
end

#origin(docxml) ⇒ Object



4
5
6
7
8
# File 'lib/isodoc/iso/presentation_origin.rb', line 4

def origin(docxml)
  short_style_origin(docxml)
  super
  bracketed_refs_processing(docxml)
end

#prefix_clause(target, loc) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/isodoc/iso/presentation_xref.rb', line 43

def prefix_clause(target, loc)
  loc["type"] == "clause" or return loc["type"]

  if subclause?(target, loc["type"],
                loc&.at(ns("./referenceFrom"))&.text)
    ""
  else "clause"
  end
end

#prefix_container(container, linkend, node, target) ⇒ Object

7 a) : Clause 7 a), but Clause 7 List 1 a)



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/isodoc/iso/presentation_xref.rb', line 112

def prefix_container(container, linkend, node, target)
  prefix_container?(container, node) or return linkend
  container_container = @xrefs.anchor(container, :container, false)
  nested_xref, container_label =
    prefix_container_template(container, node, target)
  container_label = prefix_container(container_container,
                                     container_label, node, target)
  l10n(connectives_spans(nested_xref
    .sub("%1", "<span class='fmt-xref-container'><esc>#{container_label}</esc></span>")
    .sub("%2", "<esc>#{linkend}</esc>")))
end

#prefix_container_template(container, node, target) ⇒ Object



124
125
126
127
128
129
130
131
132
133
# File 'lib/isodoc/iso/presentation_xref.rb', line 124

def prefix_container_template(container, node, target)
  nested_xref = @i18n.nested_xref
  container_label = anchor_xref(node, container)
  if @xrefs.anchor(target, :type) == "listitem" &&
      !@xrefs.anchor(target, :refer_list)
    nested_xref = "%1 %2"
    # n = @xrefs.anchor(container, :label) and container_label = n
  end
  [nested_xref, container_label]
end

#related1(node) ⇒ Object



81
82
83
# File 'lib/isodoc/iso/presentation_terms.rb', line 81

def related1(node)
  node.remove
end

#remove_preceding_space(elem) ⇒ Object



111
112
113
114
115
116
# File 'lib/isodoc/iso/presentation_origin.rb', line 111

def remove_preceding_space(elem)
  # Find the preceding text node that has actual content
  prec = elem.at("./preceding-sibling::text()" \
    "[normalize-space(.) != ''][1]") or return
  prec.content.end_with?(" ") and prec.content = prec.content.rstrip
end

#render_identifier(ident) ⇒ Object



175
176
177
178
179
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 175

def render_identifier(ident)
  ret = super
  ret[:sdo] = std_docid_semantic(ret[:sdo])
  ret
end

#requirement_note1(elem) ⇒ Object



109
110
111
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 109

def requirement_note1(elem)
  elem["unnumbered"] = "true"
end

#short_style_origin(docxml) ⇒ Object



10
11
12
13
14
15
# File 'lib/isodoc/iso/presentation_origin.rb', line 10

def short_style_origin(docxml)
  docxml.xpath(ns("//fmt-origin")).each do |o|
    xref_empty?(o) or next
    fmt_origin_cite_full?(o) and o["style"] ||= "short"
  end
end

#subclause?(target, type, from) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'lib/isodoc/iso/presentation_xref.rb', line 53

def subclause?(target, type, from)
  (from&.include?(".") && type == "clause") ||
    type == "list" ||
    target&.gsub(/<[^<>]+>/, "")&.match(/^IEV$|^IEC 60050-/)
end

#subfigure_delimObject



52
53
54
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 52

def subfigure_delim
  "<span class='fmt-label-delim'>)</span>"
end

#table1(elem) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 128

def table1(elem)
  table1_key(elem)
  if elem["class"] == "modspec"
    if n = elem.at(ns(".//fmt-name"))
      n.remove.name = "name"
      elem.add_first_child(n)
    end
    elem.at(ns("./thead"))&.remove
    super
    elem.at(ns("./name"))&.remove
    table1_fmt_xref_modspec(elem)
  else super
  end
end

#table1_fmt_xref_modspec(elem) ⇒ Object



143
144
145
146
147
148
149
150
151
152
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 143

def table1_fmt_xref_modspec(elem)
  p = elem.parent.parent.at(ns("./fmt-xref-label")) or return
  t = elem.at(ns("./fmt-xref-label"))&.remove or return
  n = t.at(ns("./span[@class='fmt-element-name'][2]")) or return
  while i = n.next
    i.remove
  end
  n.remove
  p.children.first.previous = to_xml(t.children)
end

#table1_key(elem) ⇒ Object



154
155
156
157
158
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 154

def table1_key(elem)
  elem.xpath(ns(".//dl[@key = 'true'][not(./name)]")).each do |dl|
    dl.add_first_child "<name>#{@i18n.key}</name>"
  end
end

#termexamples_before_termnotes(node) ⇒ Object



68
69
70
71
72
# File 'lib/isodoc/iso/presentation_terms.rb', line 68

def termexamples_before_termnotes(node)
  insert = node.at(ns("./definition")) or return
  insert = insertall_after_here(node, insert, "termexample")
  insertall_after_here(node, insert, "termnote")
end

#terms(docxml) ⇒ Object



74
75
76
77
78
79
# File 'lib/isodoc/iso/presentation_terms.rb', line 74

def terms(docxml)
  docxml.xpath(ns("//term[termnote][termexample]")).each do |node|
    termexamples_before_termnotes(node)
  end
  super
end

#termsource_status(status) ⇒ Object



85
86
87
88
89
90
# File 'lib/isodoc/iso/presentation_terms.rb', line 85

def termsource_status(status)
  case status
  when "modified", "adapted"
    @i18n.modified
  end
end

#toc_title(docxml) ⇒ Object



82
83
84
85
# File 'lib/isodoc/iso/presentation_section.rb', line 82

def toc_title(docxml)
  %w(amendment technical-corrigendum).include?(@doctype) and return
  super
end

#twitter_cldr_localiser_symbolsObject



165
166
167
168
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 165

def twitter_cldr_localiser_symbols
  { group: "&#xA0;", fraction_group: "&#xA0;",
    fraction_group_digits: 3, decimal: "," }
end

#ul_label_list(_elem) ⇒ Object



189
190
191
192
193
194
195
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 189

def ul_label_list(_elem)
  if @docscheme == "1951"
    %w(&#x2013;)
  else
    %w(&#x2014;)
  end
end

#warning_for_missing_metadata(docxml) ⇒ Object



9
10
11
12
13
14
# File 'lib/isodoc/iso/presentation_section.rb', line 9

def (docxml)
  @meta.get[:unpublished] or return
  ret = (docxml)
  ret.empty? and return
  (docxml, ret)
end

#warning_for_missing_metadata_create(docxml) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/isodoc/iso/presentation_section.rb', line 16

def (docxml)
  ret = ""
  docxml.at(ns("//bibdata//contributor/role[description = 'secretariat']")) or
    ret += "<p>Secretariat is missing.</p>"
  docxml.at(ns("//bibdata//contributor/role[description = 'committee']")) or
    ret += "<p>Editorial groups are missing.</p>"
  docxml.at(ns("//bibdata/date[@type = 'published' or @type = 'issued' " \
               "or @type = 'created']")) ||
    docxml.at(ns("//bibdata/version/revision-date")) or
    ret += "<p>Document date is missing.</p>"
  ret
end

#warning_for_missing_metadata_post(docxml, ret) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/isodoc/iso/presentation_section.rb', line 29

def (docxml, ret)
  from = docxml.at(ns("//sections/*/@id"))&.text or return
  ret = <<~REVIEW
    <annotation date='#{Date.today}' reviewer='Metanorma' #{add_id_text} from='#{from}' to='#{from}'>
    <p><strong>Metadata warnings:</strong></p> #{ret}
    </annotation>
  REVIEW
  unless ins = docxml.at(ns("//annotation-container"))
    docxml.root << "<annotation-container></annotation-container>"
    ins = docxml.at(ns("//annotation-container"))
  end
  ins.add_first_child ret
end

#wrap_in_bold(cell) ⇒ Object



86
87
88
89
90
91
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 86

def wrap_in_bold(cell)
  cell.text? && cell.text.strip.empty? and return
  cell.text? and cell.swap("<strong>#{cell.to_xml}</strong>")
  %w(strong fn).include?(cell.name) and return
  cell.children.each { |p| wrap_in_bold(p) }
end

#xref_init(lang, script, _klass, labels, options) ⇒ Object



4
5
6
7
# File 'lib/isodoc/iso/presentation_xref.rb', line 4

def xref_init(lang, script, _klass, labels, options)
  html = HtmlConvert.new(language: @lang, script: @script)
  @xrefs = Xref.new(lang, script, html, labels, options)
end