metanorma-standoc 2.3.9 → 2.4.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fb752d30fc48409836f4b8b63f7f57864ffe6626f624ca2520875b918ff5df3
4
- data.tar.gz: 5da9f771b4caa899c275a131c4484f0c0ae14a05041012994edd57de3588ff63
3
+ metadata.gz: 29a338b7e2acb906be1a2f9fb958fec1281991d934cae8f33279605d4c7296e7
4
+ data.tar.gz: 104dfd478b186a14b6a7acd276c28785ada074ce3f747839ee30a4620269b74e
5
5
  SHA512:
6
- metadata.gz: 5c85f82ea6c5121977b3f511d5e70b74420bc8ed9f3256117ecf16a2547e454a9b738188d5ace110127533395b4d230787fbfef1dcb37384bc07f1a8403ffc0a
7
- data.tar.gz: 8bcb04197dd817d9a853692935e07c76c70f2293821e4b1e2fb560a6e52c2eccc5b9dfc993ef5b562d09af75381e067af9dac5f2063d92c5995b447d0219c0a5
6
+ metadata.gz: 94ef91339b3743becae21df403eeb7b9af5910257ba97756c72111ddababda0523d9e6b961aa6eab9737af6c460f4c3c89aecf0af3ecbacbb391aa9e10493af3
7
+ data.tar.gz: 0ef86c13ca5bea907b55aa9e9ce98b1447e9c887e388db737855f9d8f55f3db39d20cf34aa526e2c2f0ccf140792cfd6f396b4ba117a1d50f67f28a0dd027442
@@ -125,6 +125,10 @@ a.FootnoteRef + a.FootnoteRef:before {
125
125
  content: ", ";
126
126
  vertical-align: super; }
127
127
 
128
+ a.TableFootnoteRef + a.TableFootnoteRef:before {
129
+ content: ", ";
130
+ vertical-align: super; }
131
+
128
132
  .addition {
129
133
  color: blue; }
130
134
 
@@ -59,6 +59,7 @@ module Metanorma
59
59
  @index_terms = node.attr("index-terms")
60
60
  @boilerplateauthority = node.attr("boilerplate-authority")
61
61
  @embed_hdr = node.attr("embed_hdr")
62
+ @embed_id = node.attr("embed_id")
62
63
  @document_scheme = node.attr("document-scheme")
63
64
  @xrefstyle = node.attr("xrefstyle")
64
65
  @source_linenums = node.attr("source-linenums-option") == "true"
@@ -1,4 +1,3 @@
1
- require "htmlentities"
2
1
  require "uri" if /^2\./.match?(RUBY_VERSION)
3
2
  require_relative "./blocks_notes"
4
3
 
@@ -8,6 +7,7 @@ module Metanorma
8
7
  def id_attr(node = nil)
9
8
  { id: Metanorma::Utils::anchor_or_uuid(node),
10
9
  tag: node&.attr("tag"),
10
+ columns: node&.attr("columns"),
11
11
  "multilingual-rendering": node&.attr("multilingual-rendering") }
12
12
  end
13
13
 
@@ -43,11 +43,15 @@ module Metanorma
43
43
  result
44
44
  end
45
45
 
46
+ def form_attrs(node)
47
+ attr_code(id_attr(node)
48
+ .merge(class: node.attr("class"),
49
+ name: node.attr("name"), action: node.attr("action")))
50
+ end
51
+
46
52
  def form(node)
47
53
  noko do |xml|
48
- xml.form **attr_code(id_attr(node)
49
- .merge(class: node.attr("class"),
50
- name: node.attr("name"), action: node.attr("action"))) do |f|
54
+ xml.form **form_attrs(node) do |f|
51
55
  f << node.content
52
56
  end
53
57
  end
@@ -108,8 +112,7 @@ module Metanorma
108
112
  end
109
113
 
110
114
  def example_to_requirement(node, role)
111
- return unless @reqt_models.requirement_roles.key?(role&.to_sym)
112
-
115
+ @reqt_models.requirement_roles.key?(role&.to_sym) or return
113
116
  # need to call here for proper recursion ordering
114
117
  select_requirement_model(node)
115
118
  requirement(node,
@@ -169,8 +172,7 @@ module Metanorma
169
172
  end
170
173
 
171
174
  def figure_title(node, out)
172
- return if node.title.nil?
173
-
175
+ node.title.nil? and return
174
176
  out.name { |name| name << node.title }
175
177
  end
176
178
 
@@ -196,8 +198,7 @@ module Metanorma
196
198
  end
197
199
 
198
200
  def paragraph(node)
199
- return termsource(node) if node.role == "source"
200
-
201
+ node.role == "source" and return termsource(node)
201
202
  noko do |xml|
202
203
  xml.p **para_attrs(node) do |xml_t|
203
204
  xml_t << node.content
@@ -26,7 +26,8 @@ module Metanorma
26
26
  def cleanup(xmldoc)
27
27
  element_name_cleanup(xmldoc)
28
28
  passthrough_cleanup(xmldoc)
29
- sections_cleanup(xmldoc) # feeds: obligations_cleanup, toc_cleanup
29
+ sections_cleanup(xmldoc) # feeds: obligations_cleanup, toc_cleanup,
30
+ # floatingtitle_cleanup
30
31
  obligations_cleanup(xmldoc)
31
32
  para_index_cleanup(xmldoc)
32
33
  block_index_cleanup(xmldoc)
@@ -22,10 +22,8 @@ module Metanorma
22
22
  @log.add("Crossreferences", nil,
23
23
  "term source #{s['bibitemid']} not referenced")
24
24
  end
25
- a = if source.empty? && term.nil?
26
- @i18n.no_terms_boilerplate
27
- else
28
- term_defs_boilerplate_cont(source, term, isodoc)
25
+ a = if source.empty? && term.nil? then @i18n.no_terms_boilerplate
26
+ else term_defs_boilerplate_cont(source, term, isodoc)
29
27
  end
30
28
  a and div.next = a
31
29
  end
@@ -81,7 +79,7 @@ module Metanorma
81
79
  xmldoc.xpath(xpath).each do |f|
82
80
  f.xpath(".//clause[@type = 'boilerplate'] | " \
83
81
  ".//note[@type = 'boilerplate']").each do |c|
84
- c&.at("./title")&.remove
82
+ c.at("./title")&.remove
85
83
  c.replace(c.children)
86
84
  end
87
85
  end
@@ -89,13 +87,12 @@ module Metanorma
89
87
 
90
88
  def termdef_boilerplate_insert(xmldoc, isodoc, once = false)
91
89
  xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
92
- next if f.at("./clause[@type = 'boilerplate'] | " \
93
- "./note[@type = 'boilerplate']")
94
-
90
+ f.at("./clause[@type = 'boilerplate'] | " \
91
+ "./note[@type = 'boilerplate']") and next
95
92
  term_defs_boilerplate(f.at("./title"),
96
93
  xmldoc.xpath(".//termdocsource"),
97
94
  f.at(".//term"), f.at(".//p"), isodoc)
98
- break if once
95
+ once and break
99
96
  end
100
97
  end
101
98
 
@@ -109,8 +106,7 @@ module Metanorma
109
106
  end
110
107
 
111
108
  def initial_boilerplate(xml, isodoc)
112
- return if xml.at("//boilerplate")
113
-
109
+ xml.at("//boilerplate") and return
114
110
  preface = xml.at("//preface") || xml.at("//sections") ||
115
111
  xml.at("//annex") || xml.at("//references") or return
116
112
  b = boilerplate(xml, isodoc) or return
@@ -123,10 +119,8 @@ module Metanorma
123
119
 
124
120
  def boilerplate(xml, conv)
125
121
  file = boilerplate_file(xml)
126
- if @boilerplateauthority
127
- file = File.join(@localdir,
128
- @boilerplateauthority)
129
- end
122
+ @boilerplateauthority and
123
+ file = File.join(@localdir, @boilerplateauthority)
130
124
  (!file.nil? and File.exist?(file)) or return
131
125
  conv.populate_template(File.read(file, encoding: "UTF-8"), nil)
132
126
  end
@@ -134,7 +128,8 @@ module Metanorma
134
128
  def bibdata_cleanup(xmldoc)
135
129
  bibdata_anchor_cleanup(xmldoc)
136
130
  bibdata_docidentifier_cleanup(xmldoc)
137
- bibdata_embed_hdr_cleanup(xmldoc)
131
+ bibdata_embed_hdr_cleanup(xmldoc) # feeds bibdata_embed_id_cleanup
132
+ bibdata_embed_id_cleanup(xmldoc)
138
133
  biblio_indirect_erefs(xmldoc, @internal_eref_namespaces&.uniq)
139
134
  end
140
135
 
@@ -147,8 +142,7 @@ module Metanorma
147
142
  def bibdata_docidentifier_cleanup(xmldoc)
148
143
  ins = xmldoc.at("//bibdata/docidentifier")
149
144
  xmldoc.xpath("//bibdata/docidentifier").each_with_index do |b, i|
150
- next if i.zero?
151
-
145
+ i.zero? and next
152
146
  ins.next = b.remove
153
147
  ins = ins.next
154
148
  end
@@ -212,8 +206,7 @@ module Metanorma
212
206
  end
213
207
 
214
208
  def bibdata_embed_hdr_cleanup(xmldoc)
215
- return if @embed_hdr.nil? || @embed_hdr.empty?
216
-
209
+ (@embed_hdr.nil? || @embed_hdr.empty?) and return
217
210
  xmldoc.at("//bibdata") << "<relation type='derivedFrom'>" \
218
211
  "#{hdr2bibitem(@embed_hdr.first)}</relation>"
219
212
  end
@@ -241,6 +234,19 @@ module Metanorma
241
234
  bibitem << "<relation type='derivedFrom'>#{x}</relation>"
242
235
  end
243
236
  end
237
+
238
+ def bibdata_embed_id_cleanup(xmldoc)
239
+ @embed_id.nil? and return
240
+ bibdata = xmldoc.at("//bibdata")
241
+ #require "debug"; binding.b
242
+ @embed_id.each do |d|
243
+ bibdata = bibdata.at("./relation[@type = 'derivedFrom']/bibitem")
244
+ ident = bibdata.at("./docidentifier[@primary = 'true']") ||
245
+ bibdata.at("./docidentifier")
246
+ xmldoc.xpath("//xref[@target = '#{d}'][normalize-space(text()) = '']")
247
+ .each { |x| x << ident.text }
248
+ end
249
+ end
244
250
  end
245
251
  end
246
252
  end
@@ -13,20 +13,31 @@ module Metanorma
13
13
  end
14
14
 
15
15
  def strip_initial_space(elem)
16
- return unless elem.children[0].text?
17
-
16
+ elem.children[0].text? or return
18
17
  if /\S/.match?(elem.children[0].text)
19
- elem.children[0].content = elem.children[0].text.gsub(/^ /, "")
18
+ elem.children[0].content = elem.children[0].text.lstrip
20
19
  else
21
20
  elem.children[0].remove
22
21
  end
23
22
  end
24
23
 
25
24
  def bookmark_cleanup(xmldoc)
25
+ redundant_bookmark_cleanup(xmldoc)
26
26
  li_bookmark_cleanup(xmldoc)
27
27
  dt_bookmark_cleanup(xmldoc)
28
28
  end
29
29
 
30
+ def redundant_bookmark_cleanup(xmldoc)
31
+ xmldoc.xpath("//bookmark").each do |b|
32
+ p = b
33
+ while !p.xml? && p = p.parent
34
+ p["id"] == b["id"] or next
35
+ b.remove
36
+ break
37
+ end
38
+ end
39
+ end
40
+
30
41
  def bookmark_to_id(elem, bookmark)
31
42
  parent = bookmark.parent
32
43
  elem["id"] = bookmark.remove["id"]
@@ -103,8 +114,8 @@ module Metanorma
103
114
  end
104
115
 
105
116
  def concept_eref_cleanup(elem)
106
- t = elem&.at("./xrefrender")&.remove&.children&.to_xml
107
- l = elem&.at("./locality")&.remove&.children&.to_xml
117
+ t = elem.at("./xrefrender")&.remove&.children&.to_xml
118
+ l = elem.at("./locality")&.remove&.children&.to_xml
108
119
  elem.add_child "<eref bibitemid='#{elem['key']}'>#{l}</eref>"
109
120
  extract_localities(elem.elements[-1])
110
121
  elem.elements[-1].add_child(t) if t
@@ -11,10 +11,23 @@ module Metanorma
11
11
  .asciimath_to_mathml(text, ["<amathstem>", "</amathstem>"],
12
12
  retain_asciimath: true)
13
13
  asciimath2mathml_wrap(text)
14
+ rescue StandardError => e
15
+ asciimath2mathml_err(text, e)
16
+ text
17
+ end
18
+
19
+ def asciimath2mathml_err(text, expr)
20
+ err = "Malformed MathML: #{expr}\n#{text}"
21
+ @log.add("Maths", nil, err)
22
+ @fatalerror << err
23
+ warn err
14
24
  end
15
25
 
16
26
  def asciimath2mathml_wrap(text)
17
27
  x = Nokogiri::XML(text)
28
+ x.xpath("//*[local-name() = 'math'][@display]").each do |y|
29
+ y.delete("display")
30
+ end
18
31
  x.xpath("//*[local-name() = 'math'][not(parent::stem)]").each do |y|
19
32
  y.wrap("<stem type='MathML'></stem>")
20
33
  end
@@ -43,7 +56,9 @@ module Metanorma
43
56
  end
44
57
 
45
58
  def mathml_namespace(stem)
46
- stem.xpath("./math").each { |x| x.default_namespace = MATHML_NS }
59
+ stem.xpath("./*[local-name() = 'math']").each do |x|
60
+ x.default_namespace = MATHML_NS
61
+ end
47
62
  end
48
63
 
49
64
  def mathml_mi_italics
@@ -1,7 +1,6 @@
1
1
  require "date"
2
2
  require "htmlentities"
3
3
  require "json"
4
- require "mathml2asciimath"
5
4
  require_relative "cleanup_section_names"
6
5
 
7
6
  module Metanorma
@@ -86,6 +85,7 @@ module Metanorma
86
85
 
87
86
  def sections_order_cleanup(xml)
88
87
  s = xml.at("//sections")
88
+ pop_floating_title(xml)
89
89
  make_preface(xml, s)
90
90
  make_annexes(xml)
91
91
  make_indexsect(xml, s)
@@ -214,7 +214,6 @@ module Metanorma
214
214
  end
215
215
 
216
216
  def floatingtitle_cleanup(xmldoc)
217
- pop_floating_title(xmldoc)
218
217
  floating_title_preface2sections(xmldoc)
219
218
  end
220
219
 
@@ -17,7 +17,7 @@ module Metanorma
17
17
  doc.xpath(xpath).each_with_index do |node, i|
18
18
  first && !i.zero? and next
19
19
  title = get_or_make_title(node)
20
- fn = title.xpath("./fn")
20
+ fn = title.xpath("./fn | ./bookmark")
21
21
  fn.each(&:remove)
22
22
  title.children = text
23
23
  fn.each { |n| title << n }
@@ -4,11 +4,14 @@ module Metanorma
4
4
  # Indices sort after letter but before any following
5
5
  # letter (x, x_m, x_1, xa); we use colon to force that sort order.
6
6
  # Numbers sort *after* letters; we use thorn to force that sort order.
7
+ # Capitals sort before their corresponding lowercase.
7
8
  def symbol_key(sym)
8
- @c.decode(asciimath_key(sym).text.downcase)
9
+ @c.decode(asciimath_key(sym).text)
9
10
  .gsub(/[\[\]{}<>()]/, "").gsub(/\s/m, "")
10
11
  .gsub(/[[:punct:]]|[_^]/, ":\\0").gsub(/`/, "")
11
12
  .gsub(/[0-9]+/, "þ\\0")
13
+ .tr("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz",
14
+ "ABCFEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
12
15
  end
13
16
 
14
17
  def asciimath_key(sym)
@@ -74,7 +74,7 @@ module Metanorma
74
74
  end
75
75
 
76
76
  def term_children_cleanup(xmldoc)
77
- xmldoc.xpath("//terms[terms]").each { |t| t.name = "clause" }
77
+ xmldoc.xpath("//terms[terms][not(term)]").each { |t| t.name = "clause" }
78
78
  xmldoc.xpath("//term").each do |t|
79
79
  %w(termnote termexample termsource term).each do |w|
80
80
  t.xpath("./#{w}").each { |n| t << n.remove }
@@ -114,7 +114,7 @@ module Metanorma
114
114
  aff = node.attr("affiliation#{suffix}")
115
115
  pos = node.attr("contributor-position#{suffix}")
116
116
  (aff || pos) and person.affiliation do |a|
117
- pos and a.name pos
117
+ pos and a.name { |n| n << pos }
118
118
  aff and a.organization do |o|
119
119
  person_organization(node, suffix, o)
120
120
  end
@@ -1,10 +1,9 @@
1
1
  require "asciidoctor/extensions"
2
- require "htmlentities"
3
2
  require "unicode2latex"
4
3
  require "mime/types"
5
4
  require "base64"
6
5
  require "English"
7
- require "latexmath"
6
+ require "plurimath"
8
7
 
9
8
  module Metanorma
10
9
  module Standoc
@@ -139,27 +138,24 @@ module Metanorma
139
138
  noko { |xml| xml.hr }.join
140
139
  end
141
140
 
142
- def xml_encode(text)
143
- @c.encode(text, :basic, :hexadecimal)
144
- .gsub(/&amp;gt;/, ">").gsub(/&amp;lt;/, "<").gsub(/&amp;amp;/, "&")
145
- .gsub(/&gt;/, ">").gsub(/&lt;/, "<").gsub(/&amp;/, "&")
146
- .gsub(/&quot;/, '"').gsub(/&#xa;/, "\n").gsub(/&amp;#/, "&#")
147
- end
148
-
149
141
  def latex_parse1(text)
150
142
  lxm_input = Unicode2LaTeX.unicode2latex(@c.decode(text))
151
- results = Latexmath.parse(lxm_input).to_mathml
152
- results.nil? and
143
+ results = Plurimath::Math.parse(lxm_input, "latex").to_mathml
144
+ if results.nil?
153
145
  @log.add("Math", nil,
154
146
  "latexmlmath failed to process equation:\n#{lxm_input}")
155
- results&.sub(%r{<math ([^>]+ )?display="block"}, "<math \\1")
147
+ return
148
+ end
149
+ results.sub(%r{<math ([^>]+ )?display="block"}, "<math \\1")
156
150
  end
157
151
 
158
152
  def stem_parse(text, xml, style)
159
153
  if /&lt;([^:>&]+:)?math(\s+[^>&]+)?&gt; |
160
154
  <([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
161
155
  math = xml_encode(text)
162
- xml.stem math, type: "MathML"
156
+ xml.stem type: "MathML" do |s|
157
+ s << math
158
+ end
163
159
  elsif style == :latexmath then latex_parse(text, xml)
164
160
  else
165
161
  xml.stem text&.gsub(/&amp;#/, "&#"), type: "AsciiMath"