metanorma-standoc 2.9.6 → 2.9.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -101,6 +101,8 @@ module Metanorma
101
101
  m = /:mn-document-class: (\S+)/.match(hdr[:text])
102
102
  if m then m[1].to_sym
103
103
  else Processor.new.asciidoctor_backend
104
+ # don't want processor() : we will leave embedded headers as standoc,
105
+ # not local flavour
104
106
  end
105
107
  end
106
108
 
@@ -20,7 +20,7 @@ module Metanorma
20
20
  def asciimath2mathml_indiv(elem)
21
21
  elem["type"] = "MathML"
22
22
  expr = @c.decode(elem.text)
23
- ret = asciimath_parse(expr, elem)
23
+ ret = asciimath_parse(expr, elem)&.strip
24
24
  ret += "<asciimath>#{@c.encode(expr, :basic)}</asciimath>"
25
25
  elem.children = ret
26
26
  rescue StandardError => e
@@ -40,7 +40,8 @@ module Metanorma
40
40
  MATH
41
41
  else
42
42
  Plurimath::Math.parse(expr, "asciimath")
43
- .to_mathml(display_style: elem["block"])
43
+ .to_mathml(display_style: elem["block"],
44
+ unitsml_xml: expr.include?("unitsml"))
44
45
  end
45
46
  end
46
47
 
@@ -102,7 +103,7 @@ module Metanorma
102
103
  ins
103
104
  end
104
105
 
105
- def mathml_unitsML(xmldoc)
106
+ def mathml_unitsml(xmldoc)
106
107
  xmldoc.at(".//m:*", "m" => UNITSML_NS) or return
107
108
  misc = add_misc_container(xmldoc)
108
109
  unitsml = misc.add_child("<UnitsML xmlns='#{UNITSML_NS}'/>").first
@@ -131,7 +132,7 @@ module Metanorma
131
132
  profile = mathml_mn_profile(m)
132
133
  attr = profile.each_with_object([]) do |(k, v), acc|
133
134
  v == "nil" and next
134
- acc << "#{k}='#{v}'"
135
+ acc << "#{k}='#{@c.decode v}'"
135
136
  end.join(",")
136
137
  attr.empty? or m["data-metanorma-numberformat"] = attr
137
138
  end
@@ -152,10 +153,10 @@ module Metanorma
152
153
  f = mathml_stem_format_attr(stem) or return
153
154
  attr = quoted_csv_split(f, ",").map do |x|
154
155
  m = /^(.+?)=(.+)?$/.match(x) or next
155
- "#{m[1]}='#{m[2]}'"
156
+ "#{m[1]}='#{@c.decode m[2]}'"
156
157
  end.join(",")
157
158
  stem.xpath(".//m:mn", "m" => MATHML_NS).each do |m|
158
- m["data-metanorma-numberformat"] = attr
159
+ attr.empty? or m["data-metanorma-numberformat"] = attr
159
160
  end
160
161
  end
161
162
 
@@ -168,7 +169,7 @@ module Metanorma
168
169
  f == "default" or return f
169
170
  if @numberfmt_default.empty?
170
171
  "notation='basic'"
171
- else @numberfmt_default&.map { |k, v| "#{k}=#{v}" }&.join(",")
172
+ else @numberfmt_default&.map { |k, v| "#{k}='#{v}'" }&.join(",")
172
173
  end
173
174
  end
174
175
 
@@ -179,15 +180,16 @@ module Metanorma
179
180
  end
180
181
 
181
182
  def mathml_cleanup(xmldoc)
182
- unitsml = Asciimath2UnitsML::Conv.new(asciimath2unitsml_options)
183
+ a2u = Asciimath2UnitsML::Conv.new(asciimath2unitsml_options)
183
184
  xmldoc.xpath("//stem[@type = 'MathML'][not(@validate = 'false')]")
184
185
  .each do |x|
185
186
  mathml_xml_cleanup(x)
186
- unitsml.MathML2UnitsML(x)
187
+ a2u.MathML2UnitsML(x)
187
188
  mathml_mathvariant(x)
188
- mathml_number_format(x)
189
189
  end
190
- mathml_unitsML(xmldoc)
190
+ xmldoc.xpath("//stem[@type = 'MathML']")
191
+ .each { |x| mathml_number_format(x) }
192
+ mathml_unitsml(xmldoc)
191
193
  end
192
194
  end
193
195
  end
@@ -40,14 +40,21 @@ module Metanorma
40
40
  def linebreak_cleanup_block(block)
41
41
  block.each_with_index do |e, i|
42
42
  e[:skip] and next
43
- lines = e[:text].lines.map(&:rstrip)
44
- e[:last] or lines << block[i + 1][:text].lines.first # next token context
43
+ lines = lines_strip_textspan(e, block[i + 1])
45
44
  out = Metanorma::Utils.line_sanitise(lines)
46
45
  e[:last] or out.pop
47
46
  e[:elem].replace(out.join)
48
47
  end
49
48
  end
50
49
 
50
+ def lines_strip_textspan(span, nextspan)
51
+ lines = span[:text].lines[0..-2].map(&:rstrip) <<
52
+ span[:text].lines[-1]&.sub(/\n$/, "")
53
+ # no final line rstrip: can be space linking to next line
54
+ span[:last] or lines << nextspan[:text].lines.first # next token context
55
+ lines
56
+ end
57
+
51
58
  def gather_text_for_linebreak_cleanup(block)
52
59
  x = block.xpath(".//text()").map do |e|
53
60
  { elem: e, text: e.text,
@@ -25,6 +25,7 @@ module Metanorma
25
25
  preprocessor Metanorma::Plugin::Lutaml::LutamlPreprocessor
26
26
  preprocessor Metanorma::Plugin::Lutaml::LutamlUmlAttributesTablePreprocessor
27
27
  preprocessor Metanorma::Plugin::Lutaml::LutamlUmlDatamodelDescriptionPreprocessor
28
+ preprocessor Metanorma::Plugin::Lutaml::LutamlEaXmiPreprocessor
28
29
  preprocessor Metanorma::Plugin::Lutaml::LutamlUmlClassPreprocessor
29
30
  inline_macro Metanorma::Plugin::Lutaml::LutamlFigureInlineMacro
30
31
  inline_macro Metanorma::Plugin::Lutaml::LutamlTableInlineMacro
@@ -33,6 +34,7 @@ module Metanorma
33
34
  block Metanorma::Plugin::Lutaml::LutamlDiagramBlock
34
35
  block_macro Metanorma::Plugin::Lutaml::LutamlGmlDictionaryBlockMacro
35
36
  block Metanorma::Plugin::Lutaml::LutamlGmlDictionaryBlock
37
+ block_macro Metanorma::Plugin::Lutaml::LutamlKlassTableBlockMacro
36
38
  preprocessor Metanorma::Standoc::EmbedIncludeProcessor
37
39
  preprocessor Metanorma::Standoc::LinkProtectPreprocessor
38
40
  preprocessor Metanorma::Standoc::Datamodel::AttributesTablePreprocessor
@@ -127,6 +127,7 @@ module Metanorma
127
127
  def relation_normalise(type)
128
128
  type.sub(/-by$/, "By").sub(/-of$/, "Of").sub(/-from$/, "From")
129
129
  .sub(/-in$/, "In")
130
+ .sub(/^has-([a-z])/) { "has#{$1.upcase}" }
130
131
  end
131
132
 
132
133
  def metadata_getrelation(node, xml, type, desc = nil)
@@ -189,6 +190,7 @@ module Metanorma
189
190
  def metadata_ext(node, ext)
190
191
  metadata_doctype(node, ext)
191
192
  metadata_subdoctype(node, ext)
193
+ metadata_flavor(node, ext)
192
194
  metadata_committee(node, ext)
193
195
  metadata_ics(node, ext)
194
196
  end
@@ -201,6 +203,10 @@ module Metanorma
201
203
  s = node.attr("docsubtype") and xml.subdoctype s
202
204
  end
203
205
 
206
+ def metadata_flavor(_node, ext)
207
+ ext.flavor processor.new.asciidoctor_backend
208
+ end
209
+
204
210
  def metadata_note(node, xml); end
205
211
 
206
212
  def metadata_series(node, xml); end
@@ -7,6 +7,8 @@ module Metanorma
7
7
  init_vars
8
8
  init_misc(node)
9
9
  init_processing(node)
10
+ init_log(node)
11
+ init_image(node)
10
12
  init_reqt(node)
11
13
  init_toc(node)
12
14
  init_output(node) # feeds init_biblio
@@ -47,11 +49,22 @@ module Metanorma
47
49
  @smartquotes = node.attr("smartquotes") != "false"
48
50
  @sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
49
51
  @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
52
+ @blockunnumbered = (node.attr("block-unnumbered") || "").split(",")
53
+ .map(&:strip)
54
+ end
55
+
56
+ def init_log(node)
57
+ @log or return
58
+ severity = node.attr("log-filter-severity")&.to_i || 4
59
+ category = node.attr("log-filter-category") || ""
60
+ category = category.split(",").map(&:strip)
61
+ @log.suppress_log = { severity:, category: }
62
+ end
63
+
64
+ def init_image(node)
50
65
  @datauriimage = node.attr("data-uri-image") != "false"
51
66
  @datauriattachment = node.attr("data-uri-attachment") != "false"
52
67
  @dataurimaxsize = node.attr("data-uri-maxsize")&.to_i || 13981013
53
- @blockunnumbered = (node.attr("block-unnumbered") || "").split(",")
54
- .map(&:strip)
55
68
  end
56
69
 
57
70
  def init_reqt(node)
@@ -123,15 +136,15 @@ module Metanorma
123
136
  def init_math(node)
124
137
  @keepasciimath = node.attr("mn-keep-asciimath") &&
125
138
  node.attr("mn-keep-asciimath") != "false"
126
- @numberfmt_default = kv_parse(node.attr("number-presentation"))
127
- @numberfmt_formula = node.attr("number-presentation-formula")
139
+ @numberfmt_default = kv_parse(@c.decode(node.attr("number-presentation")))
140
+ @numberfmt_formula = @c.decode(node.attr("number-presentation-formula"))
128
141
  @numberfmt_formula == "number-presentation" and
129
- @numberfmt_formula = node.attr("number-presentation")
142
+ @numberfmt_formula = @c.decode(node.attr("number-presentation"))
130
143
  @numberfmt_formula == "default" and
131
144
  @numberfmt_formula = "notation='basic'"
132
145
  @numberfmt_prof = node.attributes.each_with_object({}) do |(k, v), m|
133
146
  p = /^number-presentation-profile-(.*)$/.match(k) or next
134
- m[p[1]] = kv_parse(v)
147
+ m[p[1]] = kv_parse(@c.decode(v))
135
148
  end
136
149
  end
137
150
 
@@ -40,21 +40,29 @@ module Metanorma
40
40
  end
41
41
 
42
42
  def stem_parse(text, xml, style, node)
43
- attr = stem_attrs(node)
43
+ attrs, text = stem_attrs(node, text)
44
44
  if /&lt;([^:>&]+:)?math(\s+[^>&]+)?&gt; |
45
45
  <([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
46
- xml.stem **attr.merge(type: "MathML") do |s|
46
+ xml.stem **attrs.merge(type: "MathML") do |s|
47
47
  s << xml_encode(text)
48
48
  end
49
- elsif style == :latexmath then latex_parse(text, xml, attr)
49
+ elsif style == :latexmath then latex_parse(text, xml, attrs)
50
50
  else
51
- xml.stem text&.gsub("&amp;#", "&#"), **attr.merge(type: "AsciiMath")
51
+ xml.stem text&.gsub("&amp;#", "&#"), **attrs.merge(type: "AsciiMath")
52
52
  end
53
53
  end
54
54
 
55
- def stem_attrs(node)
56
- n = node.attr("number-format")
57
- { block: node.block?, "number-format": n }.compact
55
+ STEM_ATTRS = "number-format".freeze
56
+
57
+ def stem_attrs(node, text)
58
+ attrs = STEM_ATTRS.split("|").each_with_object({}) do |k, m|
59
+ n = node.attr(k) and m[k.to_sym] = n
60
+ end
61
+ while m = /^(#{STEM_ATTRS})(=[^%]+)?%(.*)$/o.match(text)
62
+ text = m[3]
63
+ attrs[m[1].to_sym] = m[2]&.sub(/^=/, "")
64
+ end
65
+ [{ block: node.block? }.merge(attrs), text]
58
66
  end
59
67
 
60
68
  def latex_parse(text, xml, attr)