isodoc 2.4.3 → 2.4.5

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/isodoc.gemspec +0 -1
  3. data/lib/isodoc/class_utils.rb +5 -2
  4. data/lib/isodoc/convert.rb +3 -6
  5. data/lib/isodoc/function/blocks_example_note.rb +5 -5
  6. data/lib/isodoc/function/section.rb +22 -9
  7. data/lib/isodoc/function/table.rb +12 -9
  8. data/lib/isodoc/function/to_word_html.rb +5 -4
  9. data/lib/isodoc/init.rb +9 -0
  10. data/lib/isodoc/metadata_contributor.rb +7 -9
  11. data/lib/isodoc/presentation_function/block.rb +18 -9
  12. data/lib/isodoc/presentation_function/image.rb +2 -2
  13. data/lib/isodoc/presentation_function/math.rb +1 -1
  14. data/lib/isodoc/presentation_function/refs.rb +11 -8
  15. data/lib/isodoc/presentation_function/section.rb +6 -4
  16. data/lib/isodoc/presentation_function/sourcecode.rb +13 -5
  17. data/lib/isodoc/presentation_function/terms.rb +8 -9
  18. data/lib/isodoc/presentation_xml_convert.rb +14 -5
  19. data/lib/isodoc/version.rb +1 -1
  20. data/lib/isodoc/word_function/table.rb +8 -4
  21. data/lib/isodoc/xref/xref_anchor.rb +5 -3
  22. data/lib/isodoc/xref/xref_gen.rb +25 -14
  23. data/lib/isodoc/xref/xref_gen_seq.rb +9 -9
  24. data/lib/isodoc/xref/xref_sect_gen.rb +6 -4
  25. data/lib/isodoc/xref.rb +1 -1
  26. data/lib/isodoc-yaml/i18n-ar.yaml +1 -0
  27. data/lib/isodoc-yaml/i18n-de.yaml +1 -0
  28. data/lib/isodoc-yaml/i18n-en.yaml +1 -0
  29. data/lib/isodoc-yaml/i18n-es.yaml +1 -0
  30. data/lib/isodoc-yaml/i18n-fr.yaml +1 -0
  31. data/lib/isodoc-yaml/i18n-ru.yaml +1 -0
  32. data/lib/isodoc-yaml/i18n-zh-Hans.yaml +1 -0
  33. data/lib/isodoc.rb +2 -1
  34. metadata +4 -18
  35. /data/lib/relaton/{render → render-isodoc}/config.yml +0 -0
  36. /data/lib/relaton/{render → render-isodoc}/general.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0720c3026536785125b4c6c495e4f2573dfa7b2186094c0f36efa9c20a1fbd3
4
- data.tar.gz: 9ea3325d067e417956b865edd0baf70dff9a5cb80008e6dfe5fbfbdaaaf16ff4
3
+ metadata.gz: 9cbb9d45ce42c28917d84ebd31912cd4218cd47f633d27cf58f1060396c14d67
4
+ data.tar.gz: 25872abe5383206f171fadb766688bd46e751cb83852fa0c09848cdb8a4a45a6
5
5
  SHA512:
6
- metadata.gz: 2e97827c7adacaa26ef823222897672413056219fba5a3e0a6dee92079ac680cd50a9f1dde9cb7c40fddf23ef000fcb0478709a95916a4e6b222bf3d4e94ca54
7
- data.tar.gz: 888734821add95629f8709aac1e5ac8b95b372b6a33d43e366e78e0c4ec6a3957dc9264a86015501458ca2752b881f44053e1f7a3997c5d0fb1b43ec816abc74
6
+ metadata.gz: 8734f21809f2c71d90bbb291c2da8e703cf25e06bebeb83cf3db464d2b97179dd2744be793e11b2657435309c2faf8a08d4d8d48a16c2fad34bdc8fe628a3b1d
7
+ data.tar.gz: ebbcfc1ca95fe1b7d3c8ec89a73823176ae72ad0cd3b43cdc9061a9eafc6dce8612832c0a6dc1fc3f3be4948367567e74fc8c78eb90d5e234a8bd6fbd9cd467a
data/isodoc.gemspec CHANGED
@@ -40,7 +40,6 @@ Gem::Specification.new do |spec|
40
40
  spec.add_dependency "metanorma-utils", "~> 1.4.5"
41
41
  spec.add_dependency "mn2pdf"
42
42
  spec.add_dependency "mn-requirements", "~> 0.3.1"
43
- spec.add_dependency "relaton-cli"
44
43
  spec.add_dependency "relaton-render", "~> 0.5.2"
45
44
  spec.add_dependency "roman-numerals"
46
45
  spec.add_dependency "rouge", "~> 4.0"
@@ -76,8 +76,11 @@ module IsoDoc
76
76
 
77
77
  # node is at the start of sentence in a Metanorma XML context
78
78
  def start_of_sentence(node)
79
- prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
80
- node.xpath("./preceding::text()")
79
+ prec = [] # all text nodes before node
80
+ nearest_block_parent(node).traverse do |x|
81
+ x == node and break
82
+ x.text? and prec << x
83
+ end
81
84
  prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map(&:text).join)
82
85
  end
83
86
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "isodoc/common"
4
2
  require "fileutils"
5
3
  require "tempfile"
@@ -161,10 +159,8 @@ module IsoDoc
161
159
  end
162
160
 
163
161
  def init_toc(options)
164
- @wordToClevels = (options[:doctoclevels] || options[:toclevels]).to_i
165
- @wordToClevels = 2 if @wordToClevels.zero?
166
- @htmlToClevels = (options[:htmltoclevels] || options[:toclevels]).to_i
167
- @htmlToClevels = 2 if @htmlToClevels.zero?
162
+ @htmlToClevels = 2
163
+ @wordToClevels = 2
168
164
  @tocfigures = options[:tocfigures]
169
165
  @toctables = options[:toctables]
170
166
  @tocrecommendations = options[:tocrecommendations]
@@ -218,6 +214,7 @@ module IsoDoc
218
214
  convert_i18n_init(docxml)
219
215
  metadata_init(@lang, @script, @locale, @i18n)
220
216
  xref_init(@lang, @script, self, @i18n, { locale: @locale })
217
+ toc_init(docxml)
221
218
  [docxml, filename, dir]
222
219
  end
223
220
 
@@ -4,7 +4,7 @@ module IsoDoc
4
4
  def example_label(_node, div, name)
5
5
  return if name.nil?
6
6
 
7
- div.p **{ class: "example-title" } do |_p|
7
+ div.p class: "example-title" do |_p|
8
8
  name.children.each { |n| parse(n, div) }
9
9
  end
10
10
  end
@@ -29,7 +29,7 @@ module IsoDoc
29
29
 
30
30
  def example_table_attr(node)
31
31
  attr_code(id: node["id"], class: "example",
32
- style: "border-collapse:collapse;border-spacing:0;"\
32
+ style: "border-collapse:collapse;border-spacing:0;" \
33
33
  "#{keep_style(node)}")
34
34
  end
35
35
 
@@ -60,7 +60,7 @@ module IsoDoc
60
60
  def note_p_parse(node, div)
61
61
  name = node&.at(ns("./name"))&.remove
62
62
  div.p do |p|
63
- name and p.span **{ class: "note_label" } do |s|
63
+ name and p.span class: "note_label" do |s|
64
64
  name.children.each { |n| parse(n, s) }
65
65
  s << note_delim
66
66
  end
@@ -73,7 +73,7 @@ module IsoDoc
73
73
  def note_parse1(node, div)
74
74
  name = node&.at(ns("./name"))&.remove
75
75
  name and div.p do |p|
76
- p.span **{ class: "note_label" } do |s|
76
+ p.span class: "note_label" do |s|
77
77
  name.children.each { |n| parse(n, s) }
78
78
  s << note_delim
79
79
  end
@@ -117,7 +117,7 @@ module IsoDoc
117
117
  end
118
118
 
119
119
  def admonition_name_parse(_node, div, name)
120
- div.p **{ class: "AdmonitionTitle", style: "text-align:center;" } do |p|
120
+ div.p class: "AdmonitionTitle", style: "text-align:center;" do |p|
121
121
  name.children.each { |n| parse(n, p) }
122
122
  end
123
123
  end
@@ -58,7 +58,7 @@ module IsoDoc
58
58
  num
59
59
  end
60
60
 
61
- TERM_CLAUSE = "//sections/terms | "\
61
+ TERM_CLAUSE = "//sections/terms | " \
62
62
  "//sections/clause[descendant::terms]".freeze
63
63
 
64
64
  def terms_defs(isoxml, out, num)
@@ -100,7 +100,7 @@ module IsoDoc
100
100
  def introduction(isoxml, out)
101
101
  f = isoxml.at(ns("//introduction")) || return
102
102
  page_break(out)
103
- out.div **{ class: "Section3", id: f["id"] } do |div|
103
+ out.div class: "Section3", id: f["id"] do |div|
104
104
  clause_name(nil, f.at(ns("./title")), div, { class: "IntroTitle" })
105
105
  f.elements.each do |e|
106
106
  parse(e, div) unless e.name == "title"
@@ -122,7 +122,7 @@ module IsoDoc
122
122
  f = isoxml.at(ns("//acknowledgements")) || return
123
123
  title_attr = { class: "IntroTitle" }
124
124
  page_break(out)
125
- out.div **{ class: "Section3", id: f["id"] } do |div|
125
+ out.div class: "Section3", id: f["id"] do |div|
126
126
  clause_name(nil, f&.at(ns("./title")), div, title_attr)
127
127
  f.elements.each do |e|
128
128
  parse(e, div) unless e.name == "title"
@@ -140,10 +140,23 @@ module IsoDoc
140
140
  end
141
141
 
142
142
  def preface(isoxml, out)
143
- isoxml.xpath(ns("//preface/clause | //preface/references | "\
143
+ isoxml.xpath(ns("//preface/clause | //preface/references | " \
144
144
  "//preface/definitions | //preface/terms")).each do |f|
145
145
  page_break(out)
146
- out.div **{ class: "Section3", id: f["id"] } do |div|
146
+ out.div class: "Section3", id: f["id"] do |div|
147
+ clause_name(nil, f&.at(ns("./title")), div, { class: "IntroTitle" })
148
+ f.elements.each do |e|
149
+ parse(e, div) unless e.name == "title"
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ def colophon(isoxml, out)
156
+ isoxml.at(ns("//colophon")) or return
157
+ page_break(out)
158
+ isoxml.xpath(ns("//colophon/clause")).each do |f|
159
+ out.div class: "Section3", id: f["id"] do |div|
147
160
  clause_name(nil, f&.at(ns("./title")), div, { class: "IntroTitle" })
148
161
  f.elements.each do |e|
149
162
  parse(e, div) unless e.name == "title"
@@ -174,7 +187,7 @@ module IsoDoc
174
187
  def copyright_parse(node, out)
175
188
  return if @bare
176
189
 
177
- out.div **{ class: "boilerplate-copyright" } do |div|
190
+ out.div class: "boilerplate-copyright" do |div|
178
191
  node.children.each { |n| parse(n, div) }
179
192
  end
180
193
  end
@@ -182,7 +195,7 @@ module IsoDoc
182
195
  def license_parse(node, out)
183
196
  return if @bare
184
197
 
185
- out.div **{ class: "boilerplate-license" } do |div|
198
+ out.div class: "boilerplate-license" do |div|
186
199
  node.children.each { |n| parse(n, div) }
187
200
  end
188
201
  end
@@ -190,7 +203,7 @@ module IsoDoc
190
203
  def legal_parse(node, out)
191
204
  return if @bare
192
205
 
193
- out.div **{ class: "boilerplate-legal" } do |div|
206
+ out.div class: "boilerplate-legal" do |div|
194
207
  node.children.each { |n| parse(n, div) }
195
208
  end
196
209
  end
@@ -198,7 +211,7 @@ module IsoDoc
198
211
  def feedback_parse(node, out)
199
212
  return if @bare
200
213
 
201
- out.div **{ class: "boilerplate-feedback" } do |div|
214
+ out.div class: "boilerplate-feedback" do |div|
202
215
  node.children.each { |n| parse(n, div) }
203
216
  end
204
217
  end
@@ -3,7 +3,7 @@ module IsoDoc
3
3
  module Table
4
4
  def table_title_parse(node, out)
5
5
  name = node.at(ns("./name")) or return
6
- out.p **{ class: "TableTitle", style: "text-align:center;" } do |p|
6
+ out.p class: "TableTitle", style: "text-align:center;" do |p|
7
7
  name&.children&.each { |n| parse(n, p) }
8
8
  end
9
9
  end
@@ -56,7 +56,7 @@ module IsoDoc
56
56
  return unless node["summary"]
57
57
 
58
58
  table.caption do |c|
59
- c.span **{ style: "display:none" } do |s|
59
+ c.span style: "display:none" do |s|
60
60
  s << node["summary"]
61
61
  end
62
62
  end
@@ -66,7 +66,7 @@ module IsoDoc
66
66
  colgroup = node.at(ns("./colgroup")) or return
67
67
  table.colgroup do |cg|
68
68
  colgroup.xpath(ns("./col")).each do |c|
69
- cg.col **{ style: "width: #{c['width']};" }
69
+ cg.col style: "width: #{c['width']};"
70
70
  end
71
71
  end
72
72
  end
@@ -75,16 +75,19 @@ module IsoDoc
75
75
  @in_table = true
76
76
  table_title_parse(node, out)
77
77
  out.table **table_attrs(node) do |t|
78
- tcaption(node, t)
79
- colgroup(node, t)
80
- thead_parse(node, t)
81
- tbody_parse(node, t)
82
- tfoot_parse(node, t)
78
+ table_parse_core(node, t)
83
79
  (dl = node.at(ns("./dl"))) && parse(dl, out)
84
80
  node.xpath(ns("./note")).each { |n| parse(n, out) }
85
81
  end
86
82
  @in_table = false
87
- # out.p { |p| p << "&#xa0;" }
83
+ end
84
+
85
+ def table_parse_core(node, out)
86
+ tcaption(node, out)
87
+ colgroup(node, out)
88
+ thead_parse(node, out)
89
+ tbody_parse(node, out)
90
+ tfoot_parse(node, out)
88
91
  end
89
92
 
90
93
  SW = "solid windowtext".freeze
@@ -69,21 +69,21 @@ module IsoDoc
69
69
  end
70
70
 
71
71
  def make_body1(body, _docxml)
72
- body.div **{ class: "title-section" } do |div1|
72
+ body.div class: "title-section" do |div1|
73
73
  div1.p { |p| p << "&#xa0;" } # placeholder
74
74
  end
75
75
  section_break(body)
76
76
  end
77
77
 
78
78
  def make_body2(body, _docxml)
79
- body.div **{ class: "prefatory-section" } do |div2|
79
+ body.div class: "prefatory-section" do |div2|
80
80
  div2.p { |p| p << "&#xa0;" } # placeholder
81
81
  end
82
82
  section_break(body)
83
83
  end
84
84
 
85
85
  def make_body3(body, docxml)
86
- body.div **{ class: "main-section" } do |div3|
86
+ body.div class: "main-section" do |div3|
87
87
  boilerplate docxml, div3
88
88
  preface_block docxml, div3
89
89
  abstract docxml, div3
@@ -125,13 +125,14 @@ module IsoDoc
125
125
  clause isoxml, out
126
126
  annex isoxml, out
127
127
  bibliography isoxml, out
128
+ colophon isoxml, out
128
129
  end
129
130
 
130
131
  def boilerplate(node, out)
131
132
  return if @bare
132
133
 
133
134
  boilerplate = node.at(ns("//boilerplate")) or return
134
- out.div **{ class: "authority" } do |s|
135
+ out.div class: "authority" do |s|
135
136
  boilerplate.children.each do |n|
136
137
  if n.name == "title"
137
138
  s.h1 do |h|
data/lib/isodoc/init.rb CHANGED
@@ -17,5 +17,14 @@ module IsoDoc
17
17
  def l10n(expr, lang = @lang, script = @script, locale = @locale)
18
18
  @i18n.l10n(expr, lang, script, locale)
19
19
  end
20
+
21
+ def toc_init(docxml)
22
+ x = "//metanorma-extension/presentation-metadata" \
23
+ "[name[text() = 'TOC Heading Levels']]/value"
24
+ n = docxml.at(ns(x.sub(/TOC/, "DOC TOC"))) and
25
+ @wordToClevels = n.text.to_i
26
+ n = docxml.at(ns(x.sub(/TOC/, "HTML TOC"))) and
27
+ @htmlToClevels = n.text.to_i
28
+ end
20
29
  end
21
30
  end
@@ -20,16 +20,14 @@ module IsoDoc
20
20
 
21
21
  def extract_person_affiliations(authors)
22
22
  authors.reduce([]) do |m, a|
23
+ pos = a.at(ns("./affiliation/name"))&.text
23
24
  name = a.at(ns("./affiliation/organization/name"))&.text
24
- subdivs = a.xpath(ns("./affiliation/organization/subdivision"))&.map(&:text)&.join(", ")
25
- name and subdivs and !subdivs.empty? and
26
- name = l10n("#{name}, #{subdivs}")
27
- location = a.at(ns("./affiliation/organization/address/formattedAddress"))&.text
28
- m << (if !name.nil? && !location.nil?
29
- l10n("#{name}, #{location}")
30
- else
31
- (name || location || "")
32
- end)
25
+ subdivs = a.xpath(ns("./affiliation/organization/subdivision"))
26
+ &.map(&:text)&.join(", ")
27
+ location =
28
+ a.at(ns("./affiliation/organization/address/formattedAddress"))&.text
29
+ m << l10n([pos, name, subdivs, location].map { |x| x&.empty? ? nil : x }
30
+ .compact.join(", "))
33
31
  m
34
32
  end
35
33
  end
@@ -15,8 +15,7 @@ module IsoDoc
15
15
  end
16
16
 
17
17
  def prefix_name(node, delim, number, elem)
18
- return if number.nil? || number.empty?
19
-
18
+ number.nil? || number.empty? and return
20
19
  unless name = node.at(ns("./#{elem}"))
21
20
  (node.children.empty? and node.add_child("<#{elem}></#{elem}>")) or
22
21
  node.children.first.previous = "<#{elem}></#{elem}>"
@@ -54,12 +53,12 @@ module IsoDoc
54
53
  end
55
54
 
56
55
  def note1(elem)
57
- elem.parent.name == "bibitem" || elem["notag"] == "true" and return
56
+ %w(bibdata bibitem).include?(elem.parent.name) ||
57
+ elem["notag"] == "true" and return
58
58
  n = @xrefs.get[elem["id"]]
59
- lbl = if n.nil? || n[:label].nil? || n[:label].empty?
60
- @i18n.note
61
- else l10n("#{@i18n.note} #{n[:label]}")
62
- end
59
+ lbl = @i18n.note
60
+ (n.nil? || n[:label].nil? || n[:label].empty?) or
61
+ lbl = l10n("#{lbl} #{n[:label]}")
63
62
  prefix_name(elem, "", lbl, "name")
64
63
  end
65
64
 
@@ -68,8 +67,18 @@ module IsoDoc
68
67
  end
69
68
 
70
69
  def admonition1(elem)
71
- elem.at(ns("./name")) || elem["notag"] == "true" and return
72
- prefix_name(elem, "", @i18n.admonition[elem["type"]]&.upcase, "name")
70
+ if elem["type"] == "box"
71
+ admonition_numbered1(elem)
72
+ else
73
+ elem["notag"] == "true" || elem.at(ns("./name")) and return
74
+ prefix_name(elem, "", @i18n.admonition[elem["type"]]&.upcase, "name")
75
+ end
76
+ end
77
+
78
+ def admonition_numbered1(elem)
79
+ elem["unnumbered"] && !elem.at(ns("./name")) and return
80
+ n = @xrefs.anchor(elem["id"], :label, false)
81
+ prefix_name(elem, block_delim, l10n("#{@i18n.box} #{n}"), "name")
73
82
  end
74
83
 
75
84
  def recommendation(docxml)
@@ -16,8 +16,8 @@ module IsoDoc
16
16
  def svg_wrap(elem)
17
17
  return if elem.parent.name == "image"
18
18
 
19
- elem.replace("<image src='' mimetype='image/svg+xml' height='auto' "\
20
- "width='auto'>#{elem.to_xml}</image>")
19
+ elem.wrap("<image src='' mimetype='image/svg+xml' height='auto' " \
20
+ "width='auto'></image>")
21
21
  end
22
22
 
23
23
  def svgmap_extract(elem)
@@ -106,7 +106,7 @@ module IsoDoc
106
106
  def mathml_style_inherit(node)
107
107
  node.at("./ancestor::xmlns:strong") or return
108
108
  node.children =
109
- "<mstyle fontweight='bold'>#{node.children.to_xml}</mstyle>"
109
+ "<mstyle mathvariant='bold'>#{node.children.to_xml}</mstyle>"
110
110
  end
111
111
 
112
112
  def mathml_number_to_number(node)
@@ -1,5 +1,3 @@
1
- require_relative "../../relaton/render/general"
2
-
3
1
  module IsoDoc
4
2
  class PresentationXMLConvert < ::IsoDoc::Convert
5
3
  def references(docxml)
@@ -8,11 +6,16 @@ module IsoDoc
8
6
  docxml.xpath(ns("//references/bibitem")).each do |x|
9
7
  bibitem(x, renderings)
10
8
  end
9
+ hidden_items(docxml)
10
+ @xrefs.parse_inclusions(refs: true).parse(docxml)
11
+ end
12
+
13
+ def hidden_items(docxml)
11
14
  docxml.xpath(ns("//references[bibitem/@hidden = 'true']")).each do |x|
12
15
  x.at(ns("./bibitem[not(@hidden = 'true')]")) and next
16
+ x.elements.map(&:name).any? { |n| n != "bibitem" } and next
13
17
  x["hidden"] = "true"
14
18
  end
15
- @xrefs.parse_inclusions(refs: true).parse(docxml)
16
19
  end
17
20
 
18
21
  def references_render(docxml)
@@ -127,13 +130,13 @@ module IsoDoc
127
130
  ids = @xrefs.klass.bibitem_ref_code(bib)
128
131
  idents = @xrefs.klass.render_identifier(ids)
129
132
  ret = if biblio then biblio_ref_entry_code(ordinal, idents, ids,
130
- standard, datefn)
131
- else norm_ref_entry_code(ordinal, idents, ids, standard, datefn)
133
+ standard, datefn, bib)
134
+ else norm_ref_entry_code(ordinal, idents, ids, standard, datefn, bib)
132
135
  end
133
136
  bib << "<biblio-tag>#{ret}</biblio-tag>"
134
137
  end
135
138
 
136
- def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn)
139
+ def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib)
137
140
  ret = (idents[:ordinal] || idents[:metanorma] || idents[:sdo]).to_s
138
141
  (idents[:ordinal] || idents[:metanorma]) && idents[:sdo] and
139
142
  ret += ", #{idents[:sdo]}"
@@ -145,8 +148,8 @@ module IsoDoc
145
148
 
146
149
  # if ids is just a number, only use that ([1] Non-Standard)
147
150
  # else, use both ordinal, as prefix, and ids
148
- def biblio_ref_entry_code(ordinal, ids, _id, standard, datefn)
149
- standard and id = nil
151
+ def biblio_ref_entry_code(ordinal, ids, _id, standard, datefn, _bib)
152
+ #standard and id = nil
150
153
  ret = (ids[:ordinal] || ids[:metanorma] || "[#{ordinal}]")
151
154
  if ids[:sdo]
152
155
  ret = prefix_bracketed_ref(ret)
@@ -17,7 +17,7 @@ module IsoDoc
17
17
  level = @xrefs.anchor(elem["id"], :level, false) ||
18
18
  (elem.ancestors("clause, annex").size + 1)
19
19
  t = elem.at(ns("./title")) and t["depth"] = level
20
- return if !elem.ancestors("boilerplate").empty? ||
20
+ return if !elem.ancestors("boilerplate, metanorma-extension").empty? ||
21
21
  @suppressheadingnumbers || elem["unnumbered"]
22
22
 
23
23
  lbl = @xrefs.anchor(elem["id"], :label,
@@ -28,12 +28,13 @@ module IsoDoc
28
28
  def floattitle(docxml)
29
29
  docxml.xpath(ns("//clause | //annex | //appendix | //introduction | " \
30
30
  "//foreword | //preface/abstract | //acknowledgements | " \
31
- "//terms | //definitions | //references"))
31
+ "//terms | //definitions | //references | //colophon"))
32
32
  .each do |f|
33
33
  floattitle1(f)
34
34
  end
35
35
  # top-level
36
- docxml.xpath(ns("//sections | //preface")).each { |f| floattitle1(f) }
36
+ docxml.xpath(ns("//sections | //preface | //colophon"))
37
+ .each { |f| floattitle1(f) }
37
38
  end
38
39
 
39
40
  def floattitle1(elem)
@@ -119,7 +120,8 @@ module IsoDoc
119
120
  i = display_order_xpath(docxml, @xrefs.klass.middle_clause(docxml), i)
120
121
  i = display_order_xpath(docxml, "//annex", i)
121
122
  i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i)
122
- display_order_xpath(docxml, "//indexsect", i)
123
+ i = display_order_xpath(docxml, "//indexsect", i)
124
+ display_order_xpath(docxml, "//colophon/*", i)
123
125
  end
124
126
 
125
127
  def clausetitle(docxml); end
@@ -1,16 +1,23 @@
1
1
  module IsoDoc
2
2
  class PresentationXMLConvert < ::IsoDoc::Convert
3
3
  def sourcehighlighter_css(docxml)
4
- @sourcehighlighter or return
4
+ ret = custom_css(docxml)
5
+ ret.empty? and return
5
6
  ins = docxml.at(ns("//metanorma-extension")) ||
6
7
  docxml.at(ns("//bibdata")).after("<metanorma-extension/>").next_element
7
- ins << "<source-highlighter-css>#{sourcehighlighter_css_file}" \
8
+ ins << "<source-highlighter-css>#{ret}" \
8
9
  "</source-highlighter-css>"
9
10
  end
10
11
 
11
- def sourcehighlighter_css_file
12
- File.read(File.join(File.dirname(__FILE__), "..", "base_style",
13
- "rouge.css"))
12
+ def custom_css(docxml)
13
+ ret = ""
14
+ @sourcehighlighter and
15
+ ret += File.read(File.join(File.dirname(__FILE__), "..", "base_style",
16
+ "rouge.css"))
17
+ a = docxml.at(ns("//metanorma-extension/" \
18
+ "clause[title = 'user-css']/sourcecode")) and
19
+ ret += "\n#{to_xml(a.children)}"
20
+ ret
14
21
  end
15
22
 
16
23
  def sourcehighlighter
@@ -109,6 +116,7 @@ module IsoDoc
109
116
  Rouge::Lexer.find("plaintext"))
110
117
  l = Rouge::Lexers::Escape.new(start: "{^^{", end: "}^^}", lang: lexer)
111
118
  source = to_xml(elem.children).gsub(/</, "{^^{<").gsub(/>/, ">}^^}")
119
+ l.lang.reset!
112
120
  l.lex(@c.decode(source))
113
121
  end
114
122
 
@@ -56,23 +56,22 @@ module IsoDoc
56
56
  def concept1_ref(_node, ref, opts)
57
57
  ref.nil? and return
58
58
  opts[:ref] == "false" and return ref.remove
59
- r = concept1_ref_content(ref)
60
- ref = r.at("./descendant-or-self::xmlns:xref | " \
61
- "./descendant-or-self::xmlns:eref | " \
62
- "./descendant-or-self::xmlns:termref")
63
- %w(xref eref).include? ref&.name and get_linkend(ref)
64
- opts[:linkref] == "false" && %w(xref eref).include?(ref&.name) and
59
+ concept1_ref_content(ref)
60
+ %w(xref eref).include? ref.name and get_linkend(ref)
61
+ opts[:linkref] == "false" && %w(xref eref).include?(ref.name) and
65
62
  ref.replace(ref.children)
66
63
  end
67
64
 
68
65
  def concept1_ref_content(ref)
66
+ prev = "["
67
+ foll = "]"
69
68
  if non_locality_elems(ref).select do |c|
70
69
  !c.text? || /\S/.match(c)
71
70
  end.empty?
72
- ref.replace(@i18n.term_defined_in.sub(/%/,
73
- to_xml(ref)))
74
- else ref.replace("[#{to_xml(ref)}]")
71
+ prev, foll = @i18n.term_defined_in.split("%")
75
72
  end
73
+ ref.previous = prev
74
+ ref.next = foll
76
75
  end
77
76
 
78
77
  def related(docxml)
@@ -87,10 +87,11 @@ module IsoDoc
87
87
 
88
88
  def semantic_xml_insert(xml)
89
89
  @semantic_xml_insert or return
90
- embed = to_xml(embedable_semantic_xml(xml))
90
+ embed = embedable_semantic_xml(xml)
91
91
  ins = metanorma_extension_insert_pt(xml)
92
92
  ins = ins.at(ns("./metanorma")) || ins.add_child("<metanorma/>").first
93
- ins << "<source>#{embed}</source>"
93
+ ins = ins.add_child("<source/>").first
94
+ ins << embed
94
95
  end
95
96
 
96
97
  def metanorma_extension_insert_pt(xml)
@@ -107,14 +108,22 @@ module IsoDoc
107
108
  end
108
109
 
109
110
  def embedable_semantic_xml_tags(xml)
110
- Nokogiri::XML(to_xml(xml).gsub(%r{(</?)([[:alpha:]])},
111
- "\\1semantic__\\2")).root
111
+ ret = to_xml(xml)
112
+ .sub(/ xmlns=['"][^"']+['"]/, "") # root XMLNS
113
+ .split(/(?=[<> \t\r\n\f\v])/).map do |x|
114
+ case x
115
+ when /^<[^:]+:/ then x.sub(/:/, ":semantic__")
116
+ when /^<[^:]+$/ then x.sub(%r{(</?)([[:alpha:]])},
117
+ "\\1semantic__\\2")
118
+ else x end
119
+ end
120
+ Nokogiri::XML(ret.join).root
112
121
  end
113
122
 
114
123
  def embedable_semantic_xml_attributes(xml)
115
124
  Metanorma::Utils::anchor_attributes.each do |(tag_name, attr_name)|
116
125
  tag_name == "*" or tag_name = "semantic__#{tag_name}"
117
- xml.xpath(ns("//#{tag_name}[@#{attr_name}]")).each do |elem|
126
+ xml.xpath("//#{tag_name}[@#{attr_name}]").each do |elem|
118
127
  elem.attributes[attr_name].value =
119
128
  "semantic__#{elem.attributes[attr_name].value}"
120
129
  end
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.4.3".freeze
2
+ VERSION = "2.4.5".freeze
3
3
  end
@@ -89,16 +89,20 @@ module IsoDoc
89
89
  table_title_parse(node, out)
90
90
  out.div align: "center", class: "table_container" do |div|
91
91
  div.table **table_attrs(node) do |t|
92
- colgroup(node, t)
93
- thead_parse(node, t)
94
- tbody_parse(node, t)
95
- tfoot_parse(node, t)
92
+ table_parse_core(node, out)
96
93
  (dl = node.at(ns("./dl"))) && parse(dl, out)
97
94
  node.xpath(ns("./note")).each { |n| parse(n, out) }
98
95
  end
99
96
  end
100
97
  @in_table = false
101
98
  end
99
+
100
+ def table_parse_core(node, out)
101
+ colgroup(node, out)
102
+ thead_parse(node, out)
103
+ tbody_parse(node, out)
104
+ tfoot_parse(node, out)
105
+ end
102
106
  end
103
107
  end
104
108
  end
@@ -4,10 +4,12 @@ module IsoDoc
4
4
  module XrefGen
5
5
  module Anchor
6
6
  class SeenAnchor
7
- include Singleton
8
-
9
- def initialize
7
+ def initialize(xmldoc)
10
8
  @seen = {}
9
+ # ignore all metanorma-extension ids
10
+ xmldoc.xpath("//xmlns:metanorma-extension//*[@id]").each do |x|
11
+ add(x["id"])
12
+ end
11
13
  end
12
14
 
13
15
  def seen(elem)
@@ -92,14 +92,15 @@ module IsoDoc
92
92
  SECTIONS_XPATH
93
93
  end
94
94
 
95
- CHILD_NOTES_XPATH =
95
+ def child_asset_path(asset)
96
96
  "./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and " \
97
- "not(self::xmlns:terms) and not(self::xmlns:definitions)]//xmlns:note | " \
98
- "./xmlns:note".freeze
97
+ "not(self::xmlns:terms) and not(self::xmlns:definitions)]//xmlns:X | " \
98
+ "./xmlns:X".gsub("X", asset)
99
+ end
99
100
 
100
101
  def note_anchor_names(sections)
101
102
  sections.each do |s|
102
- notes = s.xpath(CHILD_NOTES_XPATH) -
103
+ notes = s.xpath(child_asset_path("note")) -
103
104
  s.xpath(ns(".//figure//note | .//table//note"))
104
105
  note_anchor_names1(notes, Counter.new)
105
106
  note_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
@@ -107,26 +108,35 @@ module IsoDoc
107
108
  end
108
109
 
109
110
  def note_anchor_names1(notes, counter)
110
- notes.each do |n|
111
- next if @anchors[n["id"]] || blank?(n["id"])
112
-
111
+ notes.noblank.each do |n|
113
112
  @anchors[n["id"]] =
114
113
  anchor_struct(increment_label(notes, n, counter), n,
115
114
  @labels["note_xref"], "note", false)
116
115
  end
117
116
  end
118
117
 
119
- CHILD_EXAMPLES_XPATH =
120
- "./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and " \
121
- "not(self::xmlns:terms) and not(self::xmlns:definitions)]//" \
122
- "xmlns:example | ./xmlns:example".freeze
123
-
124
118
  CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | " \
125
119
  "./references".freeze
126
120
 
121
+ def admonition_anchor_names(sections)
122
+ sections.each do |s|
123
+ notes = s.xpath(child_asset_path("admonition[@type = 'box']"))
124
+ admonition_anchor_names1(notes, Counter.new)
125
+ admonition_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
126
+ end
127
+ end
128
+
129
+ def admonition_anchor_names1(notes, counter)
130
+ notes.noblank.each do |n|
131
+ @anchors[n["id"]] ||=
132
+ anchor_struct(increment_label(notes, n, counter), n,
133
+ @labels["box"], "admonition", n["unnumbered"])
134
+ end
135
+ end
136
+
127
137
  def example_anchor_names(sections)
128
138
  sections.each do |s|
129
- notes = s.xpath(CHILD_EXAMPLES_XPATH)
139
+ notes = s.xpath(child_asset_path("example"))
130
140
  example_anchor_names1(notes, Counter.new)
131
141
  example_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
132
142
  end
@@ -154,7 +164,8 @@ module IsoDoc
154
164
  end
155
165
  end
156
166
 
157
- def list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list)
167
+ def list_item_anchor_names(list, list_anchor, depth, prev_label,
168
+ refer_list)
158
169
  c = Counter.new(list["start"] ? list["start"].to_i - 1 : 0)
159
170
  list.xpath(ns("./li")).each do |li|
160
171
  label = c.increment(li).listlabel(list, depth)
@@ -45,10 +45,14 @@ module IsoDoc
45
45
  end
46
46
  end
47
47
 
48
+ def subfigure_label(subfignum)
49
+ subfignum.zero? and return ""
50
+ "-#{subfignum}"
51
+ end
52
+
48
53
  def sequential_figure_body(subfignum, counter, block, klass)
49
54
  label = counter.print
50
- label &&= label + (subfignum.zero? ? "" : "-#{subfignum}")
51
-
55
+ label &&= label + subfigure_label(subfignum)
52
56
  @anchors[block["id"]] = anchor_struct(
53
57
  label, nil, @labels[klass] || klass.capitalize, klass,
54
58
  block["unnumbered"]
@@ -58,8 +62,7 @@ module IsoDoc
58
62
  def sequential_table_names(clause)
59
63
  c = Counter.new
60
64
  clause.xpath(ns(".//table")).noblank.each do |t|
61
- next if labelled_ancestor(t)
62
-
65
+ labelled_ancestor(t) and next
63
66
  @anchors[t["id"]] = anchor_struct(
64
67
  c.increment(t).print, nil,
65
68
  @labels["table"], "table", t["unnumbered"]
@@ -117,7 +120,6 @@ module IsoDoc
117
120
  block, anchor_struct(id, block,
118
121
  label, klass, block["unnumbered"])
119
122
  )
120
-
121
123
  model.permission_parts(block, id, label, klass).each do |n|
122
124
  @anchors[n[:id]] = anchor_struct(n[:number], n[:elem], n[:label],
123
125
  n[:klass], false)
@@ -171,8 +173,7 @@ module IsoDoc
171
173
 
172
174
  def hierarchical_figure_body(num, subfignum, counter, block, klass)
173
175
  label = "#{num}#{hiersep}#{counter.print}" +
174
- (subfignum.zero? ? "" : "#{hierfigsep}#{subfignum}")
175
-
176
+ subfigure_label(subfignum)
176
177
  @anchors[block["id"]] =
177
178
  anchor_struct(label, nil, @labels[klass] || klass.capitalize,
178
179
  klass, block["unnumbered"])
@@ -181,8 +182,7 @@ module IsoDoc
181
182
  def hierarchical_table_names(clause, num)
182
183
  c = Counter.new
183
184
  clause.xpath(ns(".//table")).noblank.each do |t|
184
- next if labelled_ancestor(t)
185
-
185
+ labelled_ancestor(t) and next
186
186
  @anchors[t["id"]] =
187
187
  anchor_struct("#{num}#{hiersep}#{c.increment(t).print}",
188
188
  nil, @labels["table"], "table", t["unnumbered"])
@@ -1,17 +1,18 @@
1
1
  module IsoDoc
2
2
  module XrefGen
3
3
  module Sections
4
- def back_anchor_names(docxml)
4
+ def back_anchor_names(xml)
5
5
  if @parse_settings.empty? || @parse_settings[:clauses]
6
6
  i = Counter.new("@")
7
- docxml.xpath(ns("//annex")).each do |c|
7
+ xml.xpath(ns("//annex")).each do |c|
8
8
  annex_names(c, i.increment(c).print)
9
9
  end
10
- docxml.xpath(ns(@klass.bibliography_xpath)).each do |b|
10
+ xml.xpath(ns(@klass.bibliography_xpath)).each do |b|
11
11
  preface_names(b)
12
12
  end
13
+ xml.xpath(ns("//colophon/clause")).each { |b| preface_names(b) }
13
14
  end
14
- references(docxml) if @parse_settings.empty? || @parse_settings[:refs]
15
+ references(xml) if @parse_settings.empty? || @parse_settings[:refs]
15
16
  end
16
17
 
17
18
  def references(docxml)
@@ -45,6 +46,7 @@ module IsoDoc
45
46
  termexample_anchor_names(doc)
46
47
  note_anchor_names(doc.xpath(ns("//table | //figure")))
47
48
  note_anchor_names(doc.xpath(ns(sections_xpath)))
49
+ admonition_anchor_names(doc.xpath(ns(sections_xpath)))
48
50
  example_anchor_names(doc.xpath(ns(sections_xpath)))
49
51
  list_anchor_names(doc.xpath(ns(sections_xpath)))
50
52
  deflist_anchor_names(doc.xpath(ns(sections_xpath)))
data/lib/isodoc/xref.rb CHANGED
@@ -49,7 +49,6 @@ module IsoDoc
49
49
  return nil if ident.nil? || ident.empty?
50
50
 
51
51
  if warning && !@anchors[ident]
52
- @seen ||= SeenAnchor.instance
53
52
  @seen.seen(ident) or warn "No label has been processed for ID #{ident}"
54
53
  @seen.add(ident)
55
54
  return "[#{ident}]"
@@ -59,6 +58,7 @@ module IsoDoc
59
58
 
60
59
  # extract names for all anchors, xref and label
61
60
  def parse(docxml)
61
+ @seen = SeenAnchor.new(docxml)
62
62
  amend_preprocess(docxml) if @parse_settings.empty?
63
63
  initial_anchor_names(docxml)
64
64
  back_anchor_names(docxml)
@@ -55,6 +55,7 @@ table: جدول
55
55
  requirement: مطلب
56
56
  recommendation: توصية
57
57
  permission: إذن
58
+ box: الإطار
58
59
  key: مفتاح
59
60
  example: مثال
60
61
  example_xref: مثال
@@ -61,6 +61,7 @@ table: Tabelle
61
61
  requirement: Anforderung
62
62
  recommendation: Empfehlung
63
63
  permission: Erlaubnis
64
+ box: Kasten
64
65
  key: Taste
65
66
  example: BEISPIEL
66
67
  example_xref: Beispiel
@@ -61,6 +61,7 @@ table: Table
61
61
  requirement: Requirement
62
62
  recommendation: Recommendation
63
63
  permission: Permission
64
+ box: Box
64
65
  # Modspec
65
66
  recommendationtest: Recommendation test
66
67
  requirementtest: Requirement test
@@ -61,6 +61,7 @@ table: Tabla
61
61
  requirement: Requerimiento
62
62
  recommendation: Recomendación
63
63
  permission: Permiso
64
+ box: Recuadro
64
65
  key: Clave
65
66
  example: EJEMPLO
66
67
  example_xref: Ejemplo
@@ -58,6 +58,7 @@ table: Tableau
58
58
  requirement: Exigence
59
59
  recommendation: Recommandation
60
60
  permission: Autorisation
61
+ box: Encadré
61
62
  key: Légende
62
63
  example: EXEMPLE
63
64
  example_xref: Exemple
@@ -66,6 +66,7 @@ table: Таблица
66
66
  requirement: Требование
67
67
  recommendation: Рекомендация
68
68
  permission: Разрешение
69
+ box: Вставка
69
70
  key: Условные обозначения
70
71
  example: ПРИМЕР
71
72
  example_xref: Пример
@@ -56,6 +56,7 @@ table: 表
56
56
  requirement: 要求
57
57
  recommendation: 建议
58
58
  permission: 容許
59
+ box: 专栏
59
60
  key: 说明
60
61
  example: 示例
61
62
  example_xref: 示例
data/lib/isodoc.rb CHANGED
@@ -7,10 +7,10 @@ require "base64"
7
7
  require "mime/types"
8
8
  require "image_size"
9
9
  require "set"
10
- require "pp"
11
10
  require "html2doc"
12
11
  require "liquid"
13
12
  require "htmlentities"
13
+ require "relaton-render"
14
14
 
15
15
  require "isodoc/common"
16
16
  require "isodoc/convert"
@@ -24,6 +24,7 @@ require "isodoc/presentation_xml_convert"
24
24
  require "isodoc/xref"
25
25
  require "isodoc/i18n"
26
26
  require "metanorma/output"
27
+ require "relaton/render-isodoc/general"
27
28
 
28
29
  module IsoDoc
29
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.3
4
+ version: 2.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-23 00:00:00.000000000 Z
11
+ date: 2023-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath
@@ -136,20 +136,6 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 0.3.1
139
- - !ruby/object:Gem::Dependency
140
- name: relaton-cli
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: relaton-render
155
141
  requirement: !ruby/object:Gem::Requirement
@@ -494,8 +480,8 @@ files:
494
480
  - lib/metanorma/output/base.rb
495
481
  - lib/metanorma/output/utils.rb
496
482
  - lib/metanorma/output/xslfo.rb
497
- - lib/relaton/render/config.yml
498
- - lib/relaton/render/general.rb
483
+ - lib/relaton/render-isodoc/config.yml
484
+ - lib/relaton/render-isodoc/general.rb
499
485
  homepage: https://github.com/metanorma/isodoc
500
486
  licenses:
501
487
  - BSD-2-Clause
File without changes
File without changes