isodoc 2.12.0 → 2.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/isodoc.gemspec +2 -2
  3. data/lib/isodoc/convert.rb +0 -21
  4. data/lib/isodoc/function/blocks.rb +19 -48
  5. data/lib/isodoc/function/blocks_example_note.rb +75 -29
  6. data/lib/isodoc/function/cleanup.rb +3 -40
  7. data/lib/isodoc/function/inline.rb +39 -9
  8. data/lib/isodoc/function/lists.rb +5 -5
  9. data/lib/isodoc/function/references.rb +9 -133
  10. data/lib/isodoc/function/reqt.rb +2 -2
  11. data/lib/isodoc/function/section.rb +25 -28
  12. data/lib/isodoc/function/section_titles.rb +16 -13
  13. data/lib/isodoc/function/table.rb +3 -3
  14. data/lib/isodoc/function/terms.rb +21 -20
  15. data/lib/isodoc/function/to_word_html.rb +8 -5
  16. data/lib/isodoc/function/utils.rb +1 -1
  17. data/lib/isodoc/html_function/footnotes.rb +2 -1
  18. data/lib/isodoc/html_function/html.rb +1 -5
  19. data/lib/isodoc/init.rb +31 -0
  20. data/lib/isodoc/metadata.rb +9 -0
  21. data/lib/isodoc/metadata_contributor.rb +1 -1
  22. data/lib/isodoc/metadata_date.rb +1 -1
  23. data/lib/isodoc/presentation_function/autonum.rb +139 -0
  24. data/lib/isodoc/presentation_function/block.rb +95 -36
  25. data/lib/isodoc/presentation_function/docid.rb +78 -0
  26. data/lib/isodoc/presentation_function/erefs.rb +6 -4
  27. data/lib/isodoc/presentation_function/image.rb +52 -13
  28. data/lib/isodoc/presentation_function/inline.rb +6 -6
  29. data/lib/isodoc/presentation_function/math.rb +0 -14
  30. data/lib/isodoc/presentation_function/metadata.rb +0 -62
  31. data/lib/isodoc/presentation_function/refs.rb +44 -14
  32. data/lib/isodoc/presentation_function/reqt.rb +1 -1
  33. data/lib/isodoc/presentation_function/section.rb +46 -121
  34. data/lib/isodoc/presentation_function/sourcecode.rb +7 -4
  35. data/lib/isodoc/presentation_function/terms.rb +27 -2
  36. data/lib/isodoc/presentation_function/title.rb +107 -0
  37. data/lib/isodoc/presentation_function/xrefs.rb +17 -10
  38. data/lib/isodoc/presentation_xml_convert.rb +6 -2
  39. data/lib/isodoc/version.rb +1 -1
  40. data/lib/isodoc/word_function/body.rb +8 -36
  41. data/lib/isodoc/word_function/footnotes.rb +1 -1
  42. data/lib/isodoc/word_function/lists.rb +12 -10
  43. data/lib/isodoc/word_function/postprocess_cover.rb +0 -2
  44. data/lib/isodoc/word_function/postprocess_table.rb +1 -1
  45. data/lib/isodoc/word_function/table.rb +2 -2
  46. data/lib/isodoc/xref/clause_order.rb +2 -2
  47. data/lib/isodoc/xref/xref_anchor.rb +31 -16
  48. data/lib/isodoc/xref/xref_counter_types.rb +3 -2
  49. data/lib/isodoc/xref/xref_gen.rb +57 -33
  50. data/lib/isodoc/xref/xref_gen_seq.rb +145 -56
  51. data/lib/isodoc/xref/xref_sect_gen.rb +64 -47
  52. data/lib/isodoc/xref/xref_util.rb +49 -1
  53. data/lib/isodoc/xref.rb +3 -0
  54. data/lib/isodoc-yaml/i18n-ar.yaml +9 -9
  55. data/lib/isodoc-yaml/i18n-de.yaml +9 -9
  56. data/lib/isodoc-yaml/i18n-en.yaml +9 -9
  57. data/lib/isodoc-yaml/i18n-es.yaml +9 -9
  58. data/lib/isodoc-yaml/i18n-fr.yaml +9 -9
  59. data/lib/isodoc-yaml/i18n-ja.yaml +10 -10
  60. data/lib/isodoc-yaml/i18n-ru.yaml +9 -9
  61. data/lib/isodoc-yaml/i18n-zh-Hans.yaml +9 -9
  62. data/lib/nokogiri/xml/node.rb +1 -0
  63. metadata +9 -6
@@ -4,7 +4,6 @@ module IsoDoc
4
4
  toc_metadata(docxml)
5
5
  fonts_metadata(docxml)
6
6
  attachments_extract(docxml)
7
- preprocess_xslt_insert(docxml)
8
7
  localized_strings(docxml)
9
8
  a = docxml.at(ns("//metanorma-extension")) or return
10
9
  a.elements.empty? and a.remove
@@ -83,67 +82,6 @@ module IsoDoc
83
82
  "</presentation-metadata>"
84
83
  end
85
84
 
86
- def preprocess_xslt_insert(docxml)
87
- content = ""
88
- p = passthrough_xslt and content += p
89
- p = preprocess_xslt_read and content += File.read(p)
90
- content.empty? and return
91
- ins = extension_insert(docxml, %w(render))
92
- ins << content
93
- end
94
-
95
- COPY_XSLT =
96
- '<xsl:copy><xsl:apply-templates select="@* | node()"/></xsl:copy>'.freeze
97
- COPY_CHILDREN_XSLT =
98
- '<xsl:apply-templates select="node()"/>'.freeze
99
-
100
- def xslt_template(content)
101
- <<~XSLT
102
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
103
- <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
104
- <xsl:template match="@* | node()">#{COPY_XSLT}</xsl:template>
105
- #{content}
106
- </xsl:stylesheet>
107
- XSLT
108
- end
109
-
110
- def passthrough_xslt
111
- @output_formats.nil? and return nil
112
- @output_formats.empty? and return nil
113
- @output_formats.each_key.with_object([]) do |k, m|
114
- m << <<~XSLT
115
- <preprocess-xslt format="#{k}">
116
- #{xslt_template(<<~XSLT1)
117
- <xsl:template match="*[local-name() = 'passthrough']">
118
- <xsl:if test="contains(@formats,',#{k},')"> <!-- delimited -->
119
- #{COPY_XSLT}
120
- </xsl:if>
121
- </xsl:template>
122
- XSLT1
123
- }
124
- </preprocess-xslt>
125
- XSLT
126
- m << <<~XSLT
127
- <preprocess-xslt format="#{k}">
128
- #{xslt_template(<<~XSLT1)
129
- <xsl:template match="*[local-name() = 'math-with-linebreak']">
130
- #{k == 'pdf' ? COPY_CHILDREN_XSLT : ''}
131
- </xsl:template>
132
- <xsl:template match="*[local-name() = 'math-no-linebreak']">
133
- #{k == 'pdf' ? '' : COPY_CHILDREN_XSLT}
134
- </xsl:template>
135
- XSLT1
136
- }
137
- </preprocess-xslt>
138
- XSLT
139
- end.join("\n")
140
- end
141
-
142
- # read in from file, but with `<preprocess-xslt @format="">` wrapper
143
- def preprocess_xslt_read
144
- html_doc_path("preprocess.xslt")
145
- end
146
-
147
85
  def i18n_tag(key, value)
148
86
  "<localized-string key='#{key}' language='#{@lang}'>#{value}" \
149
87
  "</localized-string>"
@@ -1,3 +1,5 @@
1
+ require_relative "docid"
2
+
1
3
  module IsoDoc
2
4
  class PresentationXMLConvert < ::IsoDoc::Convert
3
5
  def references(docxml)
@@ -5,10 +7,24 @@ module IsoDoc
5
7
  renderings = references_render(docxml)
6
8
  docxml.xpath(ns("//references/bibitem")).each do |x|
7
9
  bibitem(x, renderings)
10
+ reference_name(x)
8
11
  end
9
12
  hidden_items(docxml)
10
13
  move_norm_ref_to_sections(docxml)
11
- @xrefs.parse_inclusions(refs: true).parse(docxml)
14
+ end
15
+
16
+ def reference_names(docxml)
17
+ docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
18
+ reference_name(ref)
19
+ end
20
+ end
21
+
22
+ def reference_name(ref)
23
+ ids = bibitem_ref_code(ref)
24
+ identifiers = render_identifier(ids)
25
+ reference = docid_l10n(identifiers[:metanorma] || identifiers[:sdo] ||
26
+ identifiers[:ordinal] || identifiers[:doi])
27
+ @xrefs.get[ref["id"]] = { xref: reference }
12
28
  end
13
29
 
14
30
  def move_norm_ref_to_sections(docxml)
@@ -56,7 +72,7 @@ module IsoDoc
56
72
  end
57
73
 
58
74
  def bibitem(xml, renderings)
59
- @xrefs.klass.implicit_reference(xml) and xml["hidden"] = "true"
75
+ implicit_reference(xml) and xml["hidden"] = "true"
60
76
  bibrender_item(xml, renderings)
61
77
  end
62
78
 
@@ -81,7 +97,7 @@ module IsoDoc
81
97
  end
82
98
 
83
99
  def bibliography_bibitem_number_skip(bibitem)
84
- @xrefs.klass.implicit_reference(bibitem) ||
100
+ implicit_reference(bibitem) ||
85
101
  bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) ||
86
102
  bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
87
103
  bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
@@ -92,7 +108,7 @@ module IsoDoc
92
108
  docxml.xpath(ns("//references[@normative = 'false']/bibitem")).each do |b|
93
109
  i = bibliography_bibitem_number1(b, i)
94
110
  end
95
- @xrefs.references docxml
111
+ reference_names docxml
96
112
  bibliography_bibitem_tag(docxml)
97
113
  end
98
114
 
@@ -122,12 +138,6 @@ module IsoDoc
122
138
  ins
123
139
  end
124
140
 
125
- def docid_prefixes(docxml)
126
- docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
127
- i.children = @xrefs.klass.docid_prefix(i["type"], to_xml(i.children))
128
- end
129
- end
130
-
131
141
  def bibliography_bibitem_tag(docxml)
132
142
  [true, false].each do |norm|
133
143
  i = 0
@@ -139,17 +149,17 @@ module IsoDoc
139
149
 
140
150
  def bibliography_bibitem_tag1(ref, idx, norm)
141
151
  ref.xpath(ns("./bibitem")).each do |b|
142
- @xrefs.klass.implicit_reference(b) and next
152
+ implicit_reference(b) and next
143
153
  idx += 1 unless b["hidden"]
144
- insert_biblio_tag(b, idx, !norm, @xrefs.klass.standard?(b))
154
+ insert_biblio_tag(b, idx, !norm, standard?(b))
145
155
  end
146
156
  idx
147
157
  end
148
158
 
149
159
  def insert_biblio_tag(bib, ordinal, biblio, standard)
150
160
  datefn = date_note_process(bib)
151
- ids = @xrefs.klass.bibitem_ref_code(bib)
152
- idents = @xrefs.klass.render_identifier(ids)
161
+ ids = bibitem_ref_code(bib)
162
+ idents = render_identifier(ids)
153
163
  ret = if biblio then biblio_ref_entry_code(ordinal, idents, ids,
154
164
  standard, datefn, bib)
155
165
  else norm_ref_entry_code(ordinal, idents, ids, standard, datefn,
@@ -199,5 +209,25 @@ module IsoDoc
199
209
  ret = bib.at(ns("./docidentifier//fn")) or return ""
200
210
  to_xml(ret.remove)
201
211
  end
212
+
213
+ # reference not to be rendered because it is deemed implicit
214
+ # in the standards environment
215
+ def implicit_reference(bib)
216
+ bib["hidden"] == "true"
217
+ end
218
+
219
+ SKIP_DOCID = <<~XPATH.strip.freeze
220
+ @type = 'DOI' or @type = 'doi' or @type = 'ISSN' or @type = 'issn' or @type = 'ISBN' or @type = 'isbn' or starts-with(@type, 'ISSN.') or starts-with(@type, 'ISBN.') or starts-with(@type, 'issn.') or starts-with(@type, 'isbn.')
221
+ XPATH
222
+
223
+ def standard?(bib)
224
+ ret = false
225
+ bib.xpath(ns("./docidentifier")).each do |id|
226
+ id["type"].nil? ||
227
+ id.at(".//self::*[#{SKIP_DOCID} or @type = 'metanorma']") and next
228
+ ret = true
229
+ end
230
+ ret
231
+ end
202
232
  end
203
233
  end
@@ -24,7 +24,7 @@ module IsoDoc
24
24
  def recommendation1(elem, type)
25
25
  lbl = @reqt_models.model(elem["model"])
26
26
  .recommendation_label(elem, type, xrefs)
27
- prefix_name(elem, "", l10n(lbl), "name")
27
+ prefix_name(elem, {}, l10n(lbl), "name")
28
28
  end
29
29
 
30
30
  def requirement_render_preprocessing(docxml); end
@@ -1,17 +1,12 @@
1
1
  require_relative "refs"
2
+ require_relative "title"
2
3
 
3
4
  module IsoDoc
4
5
  class PresentationXMLConvert < ::IsoDoc::Convert
5
- def middle_title(docxml)
6
- s = docxml.at(ns("//sections")) or return
7
- t = @meta.get[:doctitle]
8
- t.nil? || t.empty? and return
9
- s.add_first_child "<p class='zzSTDTitle1'>#{t}</p>"
10
- end
11
-
12
6
  def clause(docxml)
13
- docxml.xpath(ns("//clause | " \
14
- "//terms | //definitions | //references"))
7
+ docxml.xpath(ns("//clause | //terms | //definitions | //references | " \
8
+ "//introduction | //foreword | //preface/abstract | " \
9
+ "//acknowledgements | //colophon | //indexsect "))
15
10
  .each do |f|
16
11
  f.parent.name == "annex" &&
17
12
  @xrefs.klass.single_term_clause?(f.parent) and next
@@ -25,32 +20,23 @@ module IsoDoc
25
20
  elem.at("./ancestor::*[@unnumbered = 'true']")
26
21
  end
27
22
 
23
+ def clausedelim
24
+ ret = super
25
+ ret && !ret.empty? or return ret
26
+ "<span class='fmt-autonum-delim'>#{ret}</span>"
27
+ end
28
+
28
29
  def clause1(elem)
29
30
  level = @xrefs.anchor(elem["id"], :level, false) ||
30
31
  (elem.ancestors("clause, annex").size + 1)
31
- t = elem.at(ns("./title")) and t["depth"] = level
32
- unnumbered_clause?(elem) and return
33
- lbl = @xrefs.anchor(elem["id"], :label,
34
- elem.parent.name != "sections") or return
35
- prefix_name(elem, "<tab/>", "#{lbl}#{clausedelim}", "title")
36
- end
37
-
38
- def floattitle(docxml)
39
- p = "//clause | //annex | //appendix | //introduction | //foreword | " \
40
- "//preface/abstract | //acknowledgements | //terms | " \
41
- "//definitions | //references | //colophon | //indexsect"
42
- docxml.xpath(ns(p)).each { |f| floattitle1(f) }
43
- # top-level
44
- docxml.xpath(ns("//sections | //preface | //colophon"))
45
- .each { |f| floattitle1(f) }
46
- end
47
-
48
- # TODO not currently doing anything with the @depth attribute of floating-title
49
- def floattitle1(elem)
50
- elem.xpath(ns(".//floating-title")).each do |p|
51
- p.name = "p"
52
- p["type"] = "floating-title"
32
+ lbl = @xrefs.anchor(elem["id"], :label, elem.parent.name != "sections")
33
+ if unnumbered_clause?(elem) || !lbl
34
+ prefix_name(elem, {}, nil, "title")
35
+ else
36
+ prefix_name(elem, { caption: "<tab/>" }, "#{lbl}#{clausedelim}",
37
+ "title")
53
38
  end
39
+ t = elem.at(ns("./fmt-title")) and t["depth"] = level
54
40
  end
55
41
 
56
42
  def annex(docxml)
@@ -64,10 +50,18 @@ module IsoDoc
64
50
 
65
51
  def annex1(elem)
66
52
  lbl = @xrefs.anchor(elem["id"], :label)
53
+ # TODO: do not alter title, alter semx/@element = title
67
54
  t = elem.at(ns("./title")) and
68
55
  t.children = "<strong>#{to_xml(t.children)}</strong>"
69
- unnumbered_clause?(elem) and return
70
- prefix_name(elem, "<br/><br/>", lbl, "title")
56
+ if unnumbered_clause?(elem)
57
+ prefix_name(elem, {}, nil, "title")
58
+ else
59
+ prefix_name(elem, { caption: annex_delim(elem) }, lbl, "title")
60
+ end
61
+ end
62
+
63
+ def annex_delim(_elem)
64
+ "<br/><br/>"
71
65
  end
72
66
 
73
67
  def single_term_clause_retitle(elem)
@@ -82,28 +76,22 @@ module IsoDoc
82
76
  t = elem.at(ns("./terms | ./definitions | ./references"))
83
77
  t.xpath(ns(".//clause | .//terms | .//definitions | .//references"))
84
78
  .each do |c|
85
- tit = c.at(ns("./title")) or return
79
+ tit = c.at(ns("./fmt-title")) or next
86
80
  tit["depth"] = tit["depth"].to_i - 1 unless tit["depth"] == "1"
87
81
  end
88
82
  end
89
83
 
90
- def term(docxml)
91
- docxml.xpath(ns("//term")).each do |f|
92
- term1(f)
93
- end
94
- end
95
-
96
- def term1(elem)
97
- lbl = @xrefs.anchor(elem["id"], :label) or return
98
- prefix_name(elem, "", "#{lbl}#{clausedelim}", "name")
99
- end
100
-
101
84
  def index(docxml)
102
85
  docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove)
103
86
  end
104
87
 
88
+ def skip_display_order?(node)
89
+ node.name == "floating-title"
90
+ end
91
+
105
92
  def display_order_at(docxml, xpath, idx)
106
93
  c = docxml.at(ns(xpath)) or return idx
94
+ skip_display_order?(c) and return idx
107
95
  idx += 1
108
96
  idx = preceding_floating_titles(c, idx)
109
97
  c["displayorder"] = idx
@@ -112,6 +100,7 @@ module IsoDoc
112
100
 
113
101
  def display_order_xpath(docxml, xpath, idx)
114
102
  docxml.xpath(ns(xpath)).each do |c|
103
+ skip_display_order?(c) and next
115
104
  idx += 1
116
105
  idx = preceding_floating_titles(c, idx)
117
106
  c["displayorder"] = idx
@@ -119,19 +108,6 @@ module IsoDoc
119
108
  idx
120
109
  end
121
110
 
122
- def preceding_floating_titles(node, idx)
123
- out = node.xpath("./preceding-sibling::*")
124
- .reverse.each_with_object([]) do |p, m|
125
- %w(note admonition p).include?(p.name) or break m
126
- m << p
127
- end
128
- out.reject { |c| c["displayorder"] }.reverse_each do |c|
129
- c["displayorder"] = idx
130
- idx += 1
131
- end
132
- idx
133
- end
134
-
135
111
  def display_order(docxml)
136
112
  i = 0
137
113
  d = @xrefs.clause_order(docxml)
@@ -145,46 +121,26 @@ module IsoDoc
145
121
  end
146
122
  end
147
123
 
148
- def clausetitle(docxml)
149
- cjk_extended_title(docxml)
150
- end
151
-
152
- def cjk_search
153
- lang = %w(zh ja ko).map { |x| "@language = '#{x}'" }.join(" or ")
154
- %(Hans Hant Jpan Hang Kore).include?(@script) and
155
- lang += " or not(@language)"
156
- lang
157
- end
158
-
159
- def cjk_extended_title(docxml)
160
- l = cjk_search
161
- docxml.xpath(ns("//bibdata/title[#{l}] | //floating-title[#{l}] | " \
162
- "//title[@depth = '1' or not(@depth)][#{l}]")).each do |t|
163
- t.text.size < 4 or next
164
- t.elements.empty? or next # can't be bothered
165
- t.children = @i18n.cjk_extend(t.text)
166
- end
167
- end
168
-
169
124
  def preface_rearrange(doc)
170
- preface_move(doc.at(ns("//preface/abstract")),
125
+ preface_move(doc.xpath(ns("//preface/abstract")),
171
126
  %w(foreword introduction clause acknowledgements), doc)
172
- preface_move(doc.at(ns("//preface/foreword")),
127
+ preface_move(doc.xpath(ns("//preface/foreword")),
173
128
  %w(introduction clause acknowledgements), doc)
174
- preface_move(doc.at(ns("//preface/introduction")),
129
+ preface_move(doc.xpath(ns("//preface/introduction")),
175
130
  %w(clause acknowledgements), doc)
176
- preface_move(doc.at(ns("//preface/acknowledgements")),
131
+ preface_move(doc.xpath(ns("//preface/acknowledgements")),
177
132
  %w(), doc)
178
133
  end
179
134
 
180
- def preface_move(clause, after, _doc)
181
- clause or return
182
- preface = clause.parent
135
+ def preface_move(clauses, after, _doc)
136
+ clauses.empty? and return
137
+ preface = clauses.first.parent
138
+ clauses.each do |clause|
183
139
  float = preceding_floats(clause)
184
- prev = nil
185
140
  xpath = after.map { |n| "./self::xmlns:#{n}" }.join(" | ")
186
141
  xpath.empty? and xpath = "./self::*[not(following-sibling::*)]"
187
- preface_move1(clause, preface, float, prev, xpath)
142
+ preface_move1(clause, preface, float, nil, xpath)
143
+ end
188
144
  end
189
145
 
190
146
  def preface_move1(clause, preface, float, prev, xpath)
@@ -194,48 +150,17 @@ module IsoDoc
194
150
  x.at(xpath) or next
195
151
  clause == prev and break
196
152
  prev ||= preface.children.first
197
- float << clause
153
+ prev.next = clause
198
154
  float.each { |n| prev.next = n }
199
155
  break
200
156
  end
201
157
  end
202
158
 
203
- def preceding_floats(clause)
204
- ret = []
205
- p = clause
206
- while prev = p.previous_element
207
- if prev.name == "floating-title"
208
- ret << prev
209
- p = prev
210
- else break
211
- end
212
- end
213
- ret
214
- end
215
-
216
159
  def rearrange_clauses(docxml)
217
160
  preface_rearrange(docxml) # feeds toc_title
218
161
  toc_title(docxml)
219
162
  end
220
163
 
221
- def toc_title(docxml)
222
- docxml.at(ns("//preface/clause[@type = 'toc']")) and return
223
- ins = toc_title_insert_pt(docxml) or return
224
- id = UUIDTools::UUID.random_create.to_s
225
- ins.previous = <<~CLAUSE
226
- <clause type = 'toc' id='_#{id}'><title depth='1'>#{@i18n.table_of_contents}</title></clause>
227
- CLAUSE
228
- end
229
-
230
- def toc_title_insert_pt(docxml)
231
- ins = docxml.at(ns("//preface")) ||
232
- docxml.at(ns("//sections | //annex | //bibliography"))
233
- &.before("<preface> </preface>")
234
- &.previous_element or return nil
235
- ins.children.empty? and ins << " "
236
- ins.children.first
237
- end
238
-
239
164
  def toc(docxml)
240
165
  toc_refs(docxml)
241
166
  end
@@ -243,7 +168,7 @@ module IsoDoc
243
168
  def toc_refs(docxml)
244
169
  docxml.xpath(ns("//toc//xref[text()]")).each do |x|
245
170
  lbl = @xrefs.anchor(x["target"], :label) or next
246
- x.add_first_child "#{lbl}<tab/>"
171
+ x.add_first_child "#{lbl}<span class='fmt-caption-delim'><tab/></span>"
247
172
  end
248
173
  end
249
174
  end
@@ -150,10 +150,13 @@ module IsoDoc
150
150
  end
151
151
 
152
152
  def source_label(elem)
153
- labelled_ancestor(elem) and return
154
- lbl = @xrefs.anchor(elem["id"], :label, false) or return
155
- prefix_name(elem, block_delim,
156
- l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
153
+ if !labelled_ancestor(elem) && # do not number if labelled_ancestor
154
+ lbl = @xrefs.anchor(elem["id"], :label, false)
155
+ #a = autonum(elem["id"], lbl)
156
+ #s = "<span class='fmt-element-name'>#{lower2cap @i18n.figure}</span> #{a}"
157
+ s = labelled_autonum(lower2cap(@i18n.figure), elem["id"], lbl)&.strip
158
+ end
159
+ prefix_name(elem, { caption: block_delim }, s, "name")
157
160
  end
158
161
  end
159
162
  end
@@ -109,9 +109,17 @@ module IsoDoc
109
109
  docxml.xpath(ns("//termnote")).each { |f| termnote1(f) }
110
110
  end
111
111
 
112
+ def termnote_delim(_elem)
113
+ l10n(": ")
114
+ end
115
+
112
116
  def termnote1(elem)
113
- lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
114
- prefix_name(elem, "", lower2cap(lbl), "name")
117
+ lbl = termnote_label(elem)
118
+ prefix_name(elem, { label: termnote_delim(elem) }, lower2cap(lbl), "name")
119
+ end
120
+
121
+ def termnote_label(elem)
122
+ @xrefs.anchor(elem["id"], :label) || "???"
115
123
  end
116
124
 
117
125
  def termdefinition(docxml)
@@ -123,6 +131,7 @@ module IsoDoc
123
131
  def termdefinition1(elem)
124
132
  unwrap_definition(elem)
125
133
  multidef(elem) if elem.xpath(ns("./definition")).size > 1
134
+ termdomain(elem)
126
135
  end
127
136
 
128
137
  def multidef(elem)
@@ -144,6 +153,13 @@ module IsoDoc
144
153
  end
145
154
  end
146
155
 
156
+ def termdomain(elem)
157
+ d = elem.at(ns(".//domain")) or return
158
+ p = elem.at(ns(".//definition//p")) or return
159
+ p.add_first_child "&lt;#{d.to_xml}&gt; "
160
+ d["hidden"] = true
161
+ end
162
+
147
163
  def termsource(docxml)
148
164
  docxml.xpath(ns("//termsource")).each { |f| termsource_modification(f) }
149
165
  docxml.xpath(ns("//termsource")).each { |f| termsource1(f) }
@@ -176,5 +192,14 @@ module IsoDoc
176
192
  when "adapted" then @i18n.adapted
177
193
  end
178
194
  end
195
+
196
+ def term(docxml)
197
+ docxml.xpath(ns("//term")).each { |f| term1(f) }
198
+ end
199
+
200
+ def term1(elem)
201
+ lbl = @xrefs.anchor(elem["id"], :label) or return
202
+ prefix_name(elem, {}, "#{lbl}#{clausedelim}", "name")
203
+ end
179
204
  end
180
205
  end
@@ -0,0 +1,107 @@
1
+ require_relative "refs"
2
+
3
+ module IsoDoc
4
+ class PresentationXMLConvert < ::IsoDoc::Convert
5
+ def middle_title(docxml)
6
+ s = docxml.at(ns("//sections")) or return
7
+ t = @meta.get[:doctitle]
8
+ t.nil? || t.empty? and return
9
+ s.add_first_child "<p class='zzSTDTitle1'>#{t}</p>"
10
+ end
11
+
12
+ def missing_title(docxml)
13
+ docxml.xpath(ns("//definitions[not(./title)]")).each do |d|
14
+ # should only be happening for subclauses
15
+ d.add_first_child "<title>#{@i18n.symbols}</title>"
16
+ end
17
+ docxml.xpath(ns("//foreword[not(./title)]")).each do |d|
18
+ d.add_first_child "<title>#{@i18n.foreword}</title>"
19
+ end
20
+ end
21
+
22
+ def floattitle(docxml)
23
+ docxml.xpath(ns(".//floating-title")).each { |f| floattitle1(f) }
24
+ end
25
+
26
+ # TODO not currently doing anything with the @depth attribute of floating-title
27
+ def floattitle1(elem)
28
+ elem["id"] ||= "_#{UUIDTools::UUID.random_create}"
29
+ p = elem.dup
30
+ p.children = "<semx element='floating-title' source='#{elem['id']}'>" \
31
+ "#{to_xml(p.children)}</semx>"
32
+ elem.next = p
33
+ p.name = "p"
34
+ p["type"] = "floating-title"
35
+ transfer_id(elem, p)
36
+ end
37
+
38
+ def preceding_floating_titles(node, idx)
39
+ out = node.xpath("./preceding-sibling::*")
40
+ .reverse.each_with_object([]) do |p, m|
41
+ %w(note admonition p floating-title).include?(p.name) or break m
42
+ m << p
43
+ end
44
+ #require 'debug'; out.empty? or binding.b
45
+ out.reject { |c| c["displayorder"] }.reverse_each do |c|
46
+ skip_display_order?(c) and next
47
+ c["displayorder"] = idx
48
+ idx += 1
49
+ end
50
+ idx
51
+ end
52
+
53
+ def clausetitle(docxml)
54
+ cjk_extended_title(docxml)
55
+ end
56
+
57
+ def cjk_search
58
+ lang = %w(zh ja ko).map { |x| "@language = '#{x}'" }.join(" or ")
59
+ %(Hans Hant Jpan Hang Kore).include?(@script) and
60
+ lang += " or not(@language)"
61
+ lang
62
+ end
63
+
64
+ def cjk_extended_title(doc)
65
+ l = cjk_search
66
+ doc.xpath(ns("//bibdata/title[#{l}] | //floating-title[#{l}] | " \
67
+ "//fmt-title[@depth = '1' or not(@depth)][#{l}]"))
68
+ .each do |t|
69
+ t.text.size < 4 or next
70
+ t.traverse do |n|
71
+ n.text? or next
72
+ n.replace(@i18n.cjk_extend(n.text))
73
+ end
74
+ end
75
+ end
76
+
77
+ def preceding_floats(clause)
78
+ ret = []
79
+ p = clause
80
+ while prev = p.previous_element
81
+ if prev.name == "floating-title"
82
+ ret << prev
83
+ p = prev
84
+ else break end
85
+ end
86
+ ret
87
+ end
88
+
89
+ def toc_title(docxml)
90
+ docxml.at(ns("//preface/clause[@type = 'toc']")) and return
91
+ ins = toc_title_insert_pt(docxml) or return
92
+ id = UUIDTools::UUID.random_create.to_s
93
+ ins.previous = <<~CLAUSE
94
+ <clause type = 'toc' id='_#{id}'><fmt-title depth='1'>#{@i18n.table_of_contents}</fmt-title></clause>
95
+ CLAUSE
96
+ end
97
+
98
+ def toc_title_insert_pt(docxml)
99
+ ins = docxml.at(ns("//preface")) ||
100
+ docxml.at(ns("//sections | //annex | //bibliography"))
101
+ &.before("<preface> </preface>")
102
+ &.previous_element or return nil
103
+ ins.children.empty? and ins << " "
104
+ ins.children.first
105
+ end
106
+ end
107
+ end