metanorma-standoc 2.9.4 → 2.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/metanorma/standoc/base.rb +8 -8
  3. data/lib/metanorma/standoc/basicdoc.rng +71 -6
  4. data/lib/metanorma/standoc/biblio.rng +3 -1
  5. data/lib/metanorma/standoc/blocks.rb +1 -1
  6. data/lib/metanorma/standoc/cleanup.rb +4 -2
  7. data/lib/metanorma/standoc/cleanup_bibitem.rb +21 -6
  8. data/lib/metanorma/standoc/cleanup_boilerplate.rb +9 -93
  9. data/lib/metanorma/standoc/cleanup_inline.rb +1 -1
  10. data/lib/metanorma/standoc/cleanup_maths.rb +44 -95
  11. data/lib/metanorma/standoc/cleanup_mathvariant.rb +88 -0
  12. data/lib/metanorma/standoc/cleanup_terms.rb +4 -1
  13. data/lib/metanorma/standoc/cleanup_terms_boilerplate.rb +106 -0
  14. data/lib/metanorma/standoc/cleanup_terms_designations.rb +1 -2
  15. data/lib/metanorma/standoc/cleanup_text.rb +2 -2
  16. data/lib/metanorma/standoc/cleanup_xref.rb +1 -1
  17. data/lib/metanorma/standoc/datamodel/plantuml_renderer.rb +1 -1
  18. data/lib/metanorma/standoc/front.rb +3 -3
  19. data/lib/metanorma/standoc/init.rb +6 -0
  20. data/lib/metanorma/standoc/inline.rb +19 -14
  21. data/lib/metanorma/standoc/isodoc.rng +3 -0
  22. data/lib/metanorma/standoc/localbib.rb +1 -1
  23. data/lib/metanorma/standoc/macros.rb +1 -1
  24. data/lib/metanorma/standoc/macros_inline.rb +3 -3
  25. data/lib/metanorma/standoc/macros_plantuml.rb +1 -1
  26. data/lib/metanorma/standoc/ref.rb +1 -1
  27. data/lib/metanorma/standoc/ref_queue.rb +1 -1
  28. data/lib/metanorma/standoc/ref_utility.rb +7 -6
  29. data/lib/metanorma/standoc/reqt.rng +3 -0
  30. data/lib/metanorma/standoc/section.rb +2 -2
  31. data/lib/metanorma/standoc/term_lookup_cleanup.rb +2 -2
  32. data/lib/metanorma/standoc/utils.rb +2 -1
  33. data/lib/metanorma/standoc/version.rb +1 -1
  34. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49c6dfeea46b38b2e162f13b0e5b8f1e57f446c433e2e30313fff2e4c5b4e96e
4
- data.tar.gz: 188590c9c73a87e1ba73322a540986836b256541764ef4e45ba1a1a134eda1df
3
+ metadata.gz: 992869ede2c5466f357da227133b1604fba74a6d777759684d0cdcda349d3d10
4
+ data.tar.gz: 0c7df6eb69b3999ce5386967cb0f0bd49a2b12167c01125e0620617ee3686817
5
5
  SHA512:
6
- metadata.gz: cc6aed2b8ca43330882c41c8a00e2bc679ff5de30e9c1f914eca253ecc7900368b4c1968a2dbeceeae9db025798a15fe73a68892d83c4c0dcc6080477e66327a
7
- data.tar.gz: 0bf3a151f8dd22a2c28ee6ed158df5f8d8c6f2afe0d27cad2d8ec3234746d1994354ab52dbd1735b8c54ab99e44c3d3b7b10249a464205fc29c453d996e377c9
6
+ metadata.gz: 38291074e2bb9a535880b105609d8eb403b871f16fb180f4f4075e138b05c88e95e7034520869dfe124b620ee266f1ca693c98c7de99768647d8ee780be7fbc3
7
+ data.tar.gz: ddfbe22600ed612456d461cad1dc48ae5b04b8222a515893e7ab08a47c9f1d8782e9baed1d61e20204de145e8626a85471c2e1c33319f056f42eda81e7e609ed
@@ -47,15 +47,15 @@ module Metanorma
47
47
 
48
48
  def insert_xml_cr(doc)
49
49
  doc.gsub(%r{(</(clause|table|figure|p|bibitem|ul|ol|dl|dt|dd|li|example|
50
- sourcecode|formula|quote|references|annex|appendix|title|
51
- name|note|thead|tbody|tfoot|th|td|form|requirement|
52
- recommendation|permission|imagemap|svgmap|preferred|
53
- admitted|related|deprecates|letter-symbol|domain|
54
- graphical-symbol|expression|abbreviation-type|subject|
55
- pronunciation|grammar|term|terms|termnote|termexample|
56
- termsource|origin|termref|modification)>)}x, "\\1\n")
50
+ sourcecode|formula|quote|references|annex|appendix|title|name|note|
51
+ thead|tbody|tfoot|th|td|form|requirement|recommendation|permission|
52
+ imagemap|svgmap|preferred|admitted|related|domain|deprecates|
53
+ letter-symbol|graphical-symbol|expression|subject|abbreviation-type|
54
+ pronunciation|grammar|term|terms|termnote|termexample|termsource|
55
+ origin|termref|modification)>)}x, "\\1\n")
57
56
  .gsub(%r{(<(title|name))}, "\n\\1")
58
- .gsub(%r{(<sourcecode[^>]*>)\s+(<name[^>]*>[^<]+</name>)\s+}, "\\1\\2")
57
+ .gsub(%r{(<sourcecode[^<>]*>)\s+(<name[^<>]*>[^<]+</name>)\s+},
58
+ "\\1\\2")
59
59
  end
60
60
 
61
61
  def version
@@ -1000,14 +1000,14 @@
1000
1000
  <define name="PureTextElement">
1001
1001
  <choice>
1002
1002
  <text/>
1003
- <ref name="em"/>
1004
- <ref name="strong"/>
1003
+ <ref name="pure_em"/>
1004
+ <ref name="pure_strong"/>
1005
1005
  <ref name="sub"/>
1006
1006
  <ref name="sup"/>
1007
- <ref name="tt"/>
1008
- <ref name="underline"/>
1009
- <ref name="strike"/>
1010
- <ref name="smallcap"/>
1007
+ <ref name="pure_tt"/>
1008
+ <ref name="pure_underline"/>
1009
+ <ref name="pure_strike"/>
1010
+ <ref name="pure_smallcap"/>
1011
1011
  <ref name="br"/>
1012
1012
  </choice>
1013
1013
  </define>
@@ -1031,6 +1031,13 @@
1031
1031
  </zeroOrMore>
1032
1032
  </element>
1033
1033
  </define>
1034
+ <define name="pure_em">
1035
+ <element name="em">
1036
+ <zeroOrMore>
1037
+ <ref name="PureTextElement"/>
1038
+ </zeroOrMore>
1039
+ </element>
1040
+ </define>
1034
1041
  <define name="strong">
1035
1042
  <element name="strong">
1036
1043
  <zeroOrMore>
@@ -1046,6 +1053,13 @@
1046
1053
  </zeroOrMore>
1047
1054
  </element>
1048
1055
  </define>
1056
+ <define name="pure_strong">
1057
+ <element name="strong">
1058
+ <zeroOrMore>
1059
+ <ref name="PureTextElement"/>
1060
+ </zeroOrMore>
1061
+ </element>
1062
+ </define>
1049
1063
  <define name="tt">
1050
1064
  <element name="tt">
1051
1065
  <zeroOrMore>
@@ -1060,6 +1074,13 @@
1060
1074
  </zeroOrMore>
1061
1075
  </element>
1062
1076
  </define>
1077
+ <define name="pure_tt">
1078
+ <element name="tt">
1079
+ <zeroOrMore>
1080
+ <ref name="PureTextElement"/>
1081
+ </zeroOrMore>
1082
+ </element>
1083
+ </define>
1063
1084
  <define name="keyword">
1064
1085
  <element name="keyword">
1065
1086
  <zeroOrMore>
@@ -1090,13 +1111,42 @@
1090
1111
  <zeroOrMore>
1091
1112
  <choice>
1092
1113
  <ref name="PureTextElement"/>
1114
+ <ref name="stem"/>
1115
+ <ref name="eref"/>
1116
+ <ref name="xref"/>
1117
+ <ref name="hyperlink"/>
1093
1118
  <ref name="index"/>
1094
1119
  <ref name="index-xref"/>
1095
1120
  </choice>
1096
1121
  </zeroOrMore>
1097
1122
  </element>
1098
1123
  </define>
1124
+ <define name="pure_strike">
1125
+ <element name="strike">
1126
+ <zeroOrMore>
1127
+ <ref name="PureTextElement"/>
1128
+ </zeroOrMore>
1129
+ </element>
1130
+ </define>
1099
1131
  <define name="underline">
1132
+ <element name="underline">
1133
+ <optional>
1134
+ <attribute name="style"/>
1135
+ </optional>
1136
+ <zeroOrMore>
1137
+ <choice>
1138
+ <ref name="PureTextElement"/>
1139
+ <ref name="stem"/>
1140
+ <ref name="eref"/>
1141
+ <ref name="xref"/>
1142
+ <ref name="hyperlink"/>
1143
+ <ref name="index"/>
1144
+ <ref name="index-xref"/>
1145
+ </choice>
1146
+ </zeroOrMore>
1147
+ </element>
1148
+ </define>
1149
+ <define name="pure_underline">
1100
1150
  <element name="underline">
1101
1151
  <optional>
1102
1152
  <attribute name="style"/>
@@ -1107,6 +1157,21 @@
1107
1157
  </element>
1108
1158
  </define>
1109
1159
  <define name="smallcap">
1160
+ <element name="smallcap">
1161
+ <zeroOrMore>
1162
+ <choice>
1163
+ <ref name="PureTextElement"/>
1164
+ <ref name="stem"/>
1165
+ <ref name="eref"/>
1166
+ <ref name="xref"/>
1167
+ <ref name="hyperlink"/>
1168
+ <ref name="index"/>
1169
+ <ref name="index-xref"/>
1170
+ </choice>
1171
+ </zeroOrMore>
1172
+ </element>
1173
+ </define>
1174
+ <define name="pure_smallcap">
1110
1175
  <element name="smallcap">
1111
1176
  <zeroOrMore>
1112
1177
  <ref name="PureTextElement"/>
@@ -1204,7 +1204,9 @@
1204
1204
  <optional>
1205
1205
  <ref name="formattedref"/>
1206
1206
  </optional>
1207
- <ref name="btitle"/>
1207
+ <oneOrMore>
1208
+ <ref name="btitle"/>
1209
+ </oneOrMore>
1208
1210
  <optional>
1209
1211
  <ref name="bplace"/>
1210
1212
  </optional>
@@ -77,7 +77,7 @@ module Metanorma
77
77
  def stem(node)
78
78
  noko do |xml|
79
79
  xml.formula **formula_attrs(node) do |s|
80
- stem_parse(node.lines.join("\n"), s, node.style.to_sym, node.block?)
80
+ stem_parse(node.lines.join("\n"), s, node.style.to_sym, node)
81
81
  end
82
82
  end
83
83
  end
@@ -54,6 +54,7 @@ module Metanorma
54
54
  normref_cleanup(xmldoc)
55
55
  biblio_cleanup(xmldoc)
56
56
  reference_names(xmldoc)
57
+ terms_terms_cleanup(xmldoc) # feeds: boilerplate_cleanup
57
58
  asciimath_cleanup(xmldoc) # feeds: mathml_cleanup, termdef_cleanup,
58
59
  # symbols_cleanup
59
60
  symbols_cleanup(xmldoc) # feeds: termdef_cleanup
@@ -77,9 +78,10 @@ module Metanorma
77
78
  docidentifier_cleanup(xmldoc) # feeds: bibdata_cleanup
78
79
  ext_contributor_cleanup(xmldoc) # feeds: bibdata_cleanup
79
80
  ext_dochistory_cleanup(xmldoc) # feeds: bibdata_cleanup
80
- bibdata_cleanup(xmldoc)
81
+ bibdata_cleanup(xmldoc) # feeds: boilerplate_cleanup
82
+ boilerplate_cleanup(xmldoc) # feeds: xref_cleanup for new <<>> introduced
83
+ xref_cleanup(xmldoc)
81
84
  svgmap_cleanup(xmldoc) # feeds: img_cleanup
82
- boilerplate_cleanup(xmldoc)
83
85
  toc_cleanup(xmldoc)
84
86
  smartquotes_cleanup(xmldoc)
85
87
  linebreak_cleanup(xmldoc)
@@ -131,6 +131,9 @@ module Metanorma
131
131
  xmldoc.xpath("//bibitem//bibitem").each do |b|
132
132
  b.delete("id")
133
133
  end
134
+ xmldoc.xpath("//bibdata//bibitem").each do |b|
135
+ b.delete("id")
136
+ end
134
137
  end
135
138
 
136
139
  def attachment_cleanup(xmldoc)
@@ -139,34 +142,46 @@ module Metanorma
139
142
  u = b.at("./uri[@type = 'attachment']")
140
143
  c = b.at("./uri[@type = 'citation']") ||
141
144
  u.after("<uri type='citation'/>")
142
- uri = save_attachment(u.text, b)
145
+ uri = attachment_uri(u.text, b)
143
146
  u.children = uri
144
147
  c.children = uri
145
148
  end
146
149
  end
147
150
 
148
- def save_attachment(path, bib)
151
+ def attachment_uri(path, bib)
149
152
  init_attachments
150
153
  path = File.join(@localdir, path)
151
154
  valid_attachment?(path, bib) or return ""
155
+ @datauriattachment or return attachment_location(path)
156
+ save_attachment(path, bib)
157
+ end
158
+
159
+ def save_attachment(path, bib)
160
+ init_attachments
152
161
  f = File.basename(path)
153
162
  File.exist?(File.join(@attachmentsdir, f)) and
154
163
  f += "_#{UUIDTools::UUID.random_create}"
155
164
  out_fld = File.join(@attachmentsdir, f)
156
165
  FileUtils.cp(path, out_fld)
157
166
  datauri_attachment(out_fld, bib.document)
158
- File.join(@attachmentsfld, f)
167
+ end
168
+
169
+ def attachment_location(path)
170
+ f = path
171
+ @datauriattachment and
172
+ f = File.join(@attachmentsdir, File.basename(path))
173
+ Pathname.new(File.expand_path(f))
174
+ .relative_path_from(Pathname.new(File.expand_path(@localdir))).to_s
159
175
  end
160
176
 
161
177
  def datauri_attachment(path, doc)
162
178
  @datauriattachment or return
163
179
  m = add_misc_container(doc)
164
- f = File.join(@attachmentsdir, File.basename(path))
165
- f = Pathname.new(File.expand_path(f))
166
- .relative_path_from(Pathname.new(File.expand_path(@localdir)))
180
+ f = attachment_location(path)
167
181
  e = (m << "<attachment name='#{f}'/>").last_element_child
168
182
  Vectory::Utils::datauri(path, @localdir).scan(/.{1,60}/)
169
183
  .each { |dd| e << "#{dd}\n" }
184
+ f
170
185
  end
171
186
 
172
187
  def valid_attachment?(path, bib)
@@ -1,41 +1,8 @@
1
+ require_relative "cleanup_terms_boilerplate"
2
+
1
3
  module Metanorma
2
4
  module Standoc
3
5
  module Cleanup
4
- def external_terms_boilerplate(sources)
5
- e = @i18n.external_terms_boilerplate
6
- @i18n.l10n(e.gsub(/%(?=\p{P}|\p{Z}|$)/, sources || "???"),
7
- @lang, @script, @locale)
8
- end
9
-
10
- def internal_external_terms_boilerplate(sources)
11
- e = @i18n.internal_external_terms_boilerplate
12
- @i18n.l10n(e.gsub(/%(?=\p{P}|\p{Z}|$)/, sources || "??"),
13
- @lang, @script)
14
- end
15
-
16
- def term_defs_boilerplate(div, source, term, _preface, isodoc)
17
- a = @i18n.term_def_boilerplate and div.next = a
18
- source.each do |s|
19
- @anchors[s["bibitemid"]] or
20
- @log.add("Crossreferences", nil,
21
- "term source #{s['bibitemid']} not referenced", severity: 1)
22
- end
23
- a = if source.empty? && term.nil? then @i18n.no_terms_boilerplate
24
- else term_defs_boilerplate_cont(source, term, isodoc)
25
- end and div.next = a
26
- end
27
-
28
- def term_defs_boilerplate_cont(src, term, isodoc)
29
- sources = isodoc.sentence_join(src.map do |s|
30
- %{<eref bibitemid="#{s['bibitemid']}"/>}
31
- end)
32
- if src.empty? then @i18n.internal_terms_boilerplate
33
- elsif term.nil? then external_terms_boilerplate(sources)
34
- else
35
- internal_external_terms_boilerplate(sources)
36
- end
37
- end
38
-
39
6
  def norm_ref_preface(ref)
40
7
  ins = norm_ref_boilerplate_insert_location(ref)
41
8
  ins2 = norm_ref_process_boilerplate_note(ref)
@@ -45,7 +12,7 @@ module Metanorma
45
12
  %w(references bibitem).include? e.name
46
13
  end
47
14
  pref = refs.empty? ? @i18n.norm_empty_pref : @i18n.norm_with_refs_pref
48
- ins.next = "<p>#{pref}</p>"
15
+ ins.next = boilerplate_snippet_convert(pref)
49
16
  end
50
17
 
51
18
  def norm_ref_process_boilerplate_note(ref)
@@ -69,16 +36,15 @@ module Metanorma
69
36
  ref.at("./title")
70
37
  end
71
38
 
72
- TERM_CLAUSE =
73
- "//sections//terms[not(.//ancestor::clause[@type = 'terms'])] | " \
74
- "//sections/clause[descendant::terms][@type = 'terms'] | " \
75
- "//sections/clause[not(@type = 'terms')]//terms".freeze
76
-
77
39
  NORM_REF =
78
40
  "//bibliography/references[@normative = 'true'][not(@hidden)] | " \
79
41
  "//bibliography/clause[.//references[@normative = 'true']]".freeze
80
42
 
81
43
  def boilerplate_isodoc(xmldoc)
44
+ # prevent infinite recursion of asciidoc boilerplate processing
45
+ # in termdef_boilerplate_insert and initial_boilerplate
46
+ xmldoc.at("//metanorma-extension/semantic-metadata/" \
47
+ "headless[text() = 'true']") and return nil
82
48
  x = xmldoc.dup
83
49
  x.root.add_namespace(nil, self.class::XML_NAMESPACE)
84
50
  xml = Nokogiri::XML(x.to_xml)
@@ -87,14 +53,6 @@ module Metanorma
87
53
  @isodoc
88
54
  end
89
55
 
90
- def termdef_boilerplate_cleanup(xmldoc)
91
- # termdef_remove_initial_paras(xmldoc)
92
- end
93
-
94
- def termdef_remove_initial_paras(xmldoc)
95
- xmldoc.xpath("//terms/p | //terms/ul").each(&:remove)
96
- end
97
-
98
56
  def unwrap_boilerplate_clauses(xmldoc, xpath)
99
57
  xmldoc.xpath(xpath).each do |f|
100
58
  f.xpath(".//clause[@type = 'boilerplate'] | " \
@@ -105,51 +63,8 @@ module Metanorma
105
63
  end
106
64
  end
107
65
 
108
- def termdef_boilerplate_insert(xmldoc, isodoc, once = false)
109
- if once
110
- f = termdef_boilerplate_insert_location(xmldoc) and
111
- termdef_boilerplate_insert1(f, xmldoc, isodoc)
112
- else
113
- xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
114
- termdef_boilerplate_insert1(f, xmldoc, isodoc)
115
- end
116
- end
117
- end
118
-
119
- def termdef_boilerplate_insert_location(xmldoc)
120
- f = xmldoc.at(self.class::TERM_CLAUSE)
121
- root = xmldoc.at("//sections/terms | //sections/clause[@type = 'terms']")
122
- if f && root && f["id"] != root["id"]
123
- f = termdef_boilerplate_climb_up(f, root)
124
- elsif !f && root then f = root
125
- end
126
- f
127
- end
128
-
129
- def termdef_boilerplate_climb_up(clause, container)
130
- container.at(".//*[@id = '#{clause['id']}']") or return clause
131
- while (n = clause.parent)
132
- n.at(".//definitions") and break
133
- clause = n
134
- n["id"] == container["id"] and break
135
- end
136
- clause
137
- end
138
-
139
- def termdef_boilerplate_insert1(sect, xmldoc, isodoc)
140
- ins = sect.at("./title")
141
- if (ins2 = sect.at("./clause[@type = 'boilerplate'] | " \
142
- "./note[@type = 'boilerplate']"))
143
- ins2.text.strip.downcase == "(default)" or return
144
- ins2.children = " "
145
- ins = ins2.children.first
146
- end
147
- term_defs_boilerplate(ins, xmldoc.xpath(".//termdocsource"),
148
- sect.at(".//term"), sect.at(".//p"), isodoc)
149
- end
150
-
151
66
  def boilerplate_cleanup(xmldoc)
152
- isodoc = boilerplate_isodoc(xmldoc)
67
+ isodoc = boilerplate_isodoc(xmldoc) or return
153
68
  termdef_boilerplate_cleanup(xmldoc)
154
69
  termdef_boilerplate_insert(xmldoc, isodoc)
155
70
  unwrap_boilerplate_clauses(xmldoc, self.class::TERM_CLAUSE)
@@ -245,6 +160,7 @@ module Metanorma
245
160
  /^_\d+$/.match?(n["id"]) and
246
161
  n["id"] = "_#{UUIDTools::UUID.random_create}"
247
162
  end
163
+ xml
248
164
  end
249
165
 
250
166
  def boilerplate_top_elements(xml)
@@ -99,7 +99,7 @@ module Metanorma
99
99
  def key_extract_locality(elem)
100
100
  elem["key"].include?(",") or return
101
101
  elem.add_child("<locality>#{elem['key'].sub(/^[^,]+,/, '')}</locality>")
102
- elem["key"] = elem["key"].sub(/,.*$/, "")
102
+ elem["key"] = elem["key"].sub(/(^[^,]+),.*$/, "\\1")
103
103
  end
104
104
 
105
105
  def concept_termbase_cleanup(elem)
@@ -1,4 +1,5 @@
1
1
  require "asciimath2unitsml"
2
+ require_relative "cleanup_mathvariant"
2
3
 
3
4
  module Metanorma
4
5
  module Standoc
@@ -58,15 +59,19 @@ module Metanorma
58
59
  xml
59
60
  end
60
61
 
61
- def progress_conv(idx, step, total, threshold, msg)
62
- return unless (idx % step).zero? && total > threshold && idx.positive?
62
+ def mathml_xml_cleanup(stem)
63
+ xml_unescape_mathml(stem)
64
+ mathml_namespace(stem)
65
+ mathml_preserve_space(stem)
66
+ end
63
67
 
68
+ def progress_conv(idx, step, total, threshold, msg)
69
+ (idx % step).zero? && total > threshold && idx.positive? or return
64
70
  warn "#{msg} #{idx} of #{total}"
65
71
  end
66
72
 
67
73
  def xml_unescape_mathml(xml)
68
- return if xml.children.any?(&:element?)
69
-
74
+ xml.children.any?(&:element?) and return
70
75
  math = xml.text.gsub("&lt;", "<").gsub("&gt;", ">")
71
76
  .gsub("&quot;", '"').gsub("&apos;", "'").gsub("&amp;", "&")
72
77
  .gsub(/<[^: \r\n\t\/]+:/, "<").gsub(/<\/[^ \r\n\t:]+:/, "</")
@@ -86,33 +91,6 @@ module Metanorma
86
91
  end
87
92
  end
88
93
 
89
- def mathml_mi_italics
90
- { uppergreek: true, upperroman: true,
91
- lowergreek: true, lowerroman: true }
92
- end
93
-
94
- # presuppose multichar mi upright, singlechar mi MathML default italic
95
- def mathml_italicise(xml)
96
- xml.xpath(".//m:mi[not(ancestor::*[@mathvariant])]",
97
- "m" => MATHML_NS).each do |i|
98
- char = @c.decode(i.text)
99
- i["mathvariant"] = "normal" if mi_italicise?(char)
100
- end
101
- end
102
-
103
- def mi_italicise?(char)
104
- char.length > 1 and return false
105
- case char
106
- when /\p{Greek}/
107
- (/\p{Lower}/.match(char) && !mathml_mi_italics[:lowergreek]) ||
108
- (/\p{Upper}/.match(char) && !mathml_mi_italics[:uppergreek])
109
- when /\p{Latin}/
110
- (/\p{Lower}/.match(char) && !mathml_mi_italics[:lowerroman]) ||
111
- (/\p{Upper}/.match(char) && !mathml_mi_italics[:upperroman])
112
- else false
113
- end
114
- end
115
-
116
94
  UNITSML_NS = "https://schema.unitsml.org/unitsml/1.0".freeze
117
95
 
118
96
  def add_misc_container(xmldoc)
@@ -125,8 +103,7 @@ module Metanorma
125
103
  end
126
104
 
127
105
  def mathml_unitsML(xmldoc)
128
- return unless xmldoc.at(".//m:*", "m" => UNITSML_NS)
129
-
106
+ xmldoc.at(".//m:*", "m" => UNITSML_NS) or return
130
107
  misc = add_misc_container(xmldoc)
131
108
  unitsml = misc.add_child("<UnitsML xmlns='#{UNITSML_NS}'/>").first
132
109
  %w(Unit CountedItem Quantity Dimension Prefix).each do |t|
@@ -139,8 +116,7 @@ module Metanorma
139
116
  .each_with_object({}) do |x, m|
140
117
  m[x["xml:id"]] = x.remove
141
118
  end
142
- return if tags.empty?
143
-
119
+ tags.empty? and return
144
120
  set = unitsml.add_child("<#{tag}Set/>").first
145
121
  tags.each_value { |v| set << v }
146
122
  end
@@ -149,62 +125,8 @@ module Metanorma
149
125
  { multiplier: :space }
150
126
  end
151
127
 
152
- MATHVARIANT_OVERRIDE = {
153
- bold: { normal: "bold", italic: "bold-italic", fraktur: "bold-fraktur",
154
- script: "bold-script", "sans-serif": "bold-sans-serif",
155
- "sans-serif-italic": "sans-serif-bold-italic" },
156
- italic: { normal: "italic", bod: "bold-italic",
157
- "sans-serif": "sans-serif-italic",
158
- "bold-sans-serif": "sans-serif-bold-italic" },
159
- "bold-italic": { normal: "bold-italic", bold: "bold-italic",
160
- italic: "bold-italic",
161
- "sans-serif": "sans-serif-bold-italic",
162
- "bold-sans-serif": "sans-serif-bold-italic",
163
- "sans-serif-italic": "sans-serif-bold-italic" },
164
- fraktur: { normal: "fraktur", bold: "bold-fraktur" },
165
- "bold-fraktur": { normal: "bold-fraktur", fraktur: "bold-fraktur" },
166
- script: { normal: "script", bold: "bold-script" },
167
- "bold-script": { normal: "script", script: "bold-script" },
168
- "sans-serif": { normal: "sans-serif", bold: "bold-sans-serif",
169
- italic: "sans-serif-italic",
170
- "bold-italic": "sans-serif-bold-italic" },
171
- "bold-sans-serif": { normal: "bold-sans-serif", bold: "bold-sans-serif",
172
- "sans-serif": "bold-sans-serif",
173
- italic: "sans-serif-bold-italic",
174
- "bold-italic": "sans-serif-bold-italic",
175
- "sans-serif-italic": "sans-serif-bold-italic" },
176
- "sans-serif-italic": { normal: "sans-serif-italic",
177
- italic: "sans-serif-italic",
178
- "sans-serif": "sans-serif-italic",
179
- bold: "sans-serif-bold-italic",
180
- "bold-italic": "sans-serif-bold-italic",
181
- "sans-serif-bold": "sans-serif-bold-italic" },
182
- "sans-serif-bold-italic": { normal: "sans-serif-bold-italic",
183
- italic: "sans-serif-bold-italic",
184
- "sans-serif": "sans-serif-bold-italic",
185
- "sans-serif-italic": "sans-serif-bold-italic",
186
- bold: "sans-serif-bold-italic",
187
- "bold-italic": "sans-serif-bold-italic",
188
- "sans-serif-bold": "sans-serif-bold-italic" },
189
- }.freeze
190
-
191
- def mathvariant_override(inner, outer)
192
- o = outer.to_sym
193
- i = inner.to_sym
194
- MATHVARIANT_OVERRIDE[o] or return inner
195
- MATHVARIANT_OVERRIDE[o][i] || inner
196
- end
197
-
198
- def mathml_mathvariant(math)
199
- math.xpath(".//*[@mathvariant]").each do |outer|
200
- outer.xpath(".//*[@mathvariant]").each do |inner|
201
- inner["mathvariant"] =
202
- mathvariant_override(inner["mathvariant"], outer["mathvariant"])
203
- end
204
- end
205
- end
206
-
207
128
  def mathml_mn_format(math)
129
+ math["number-format"] or return
208
130
  math.xpath(".//m:mn", "m" => MATHML_NS).each do |m|
209
131
  profile = mathml_mn_profile(m)
210
132
  attr = profile.each_with_object([]) do |(k, v), acc|
@@ -226,17 +148,44 @@ module Metanorma
226
148
  fmt.merge(fmt1).merge(fmt2)
227
149
  end
228
150
 
151
+ def mathml_stem_format(stem)
152
+ f = mathml_stem_format_attr(stem) or return
153
+ attr = quoted_csv_split(f, ",").map do |x|
154
+ m = /^(.+?)=(.+)?$/.match(x) or next
155
+ "#{m[1]}='#{m[2]}'"
156
+ end.join(",")
157
+ stem.xpath(".//m:mn", "m" => MATHML_NS).each do |m|
158
+ m["data-metanorma-numberformat"] = attr
159
+ end
160
+ end
161
+
162
+ def mathml_stem_format_attr(stem)
163
+ f = stem["number-format"] || @numberfmt_formula or return
164
+ if f == "nil"
165
+ stem.delete("number-format")
166
+ return
167
+ end
168
+ f == "default" or return f
169
+ if @numberfmt_default.empty?
170
+ "notation='basic'"
171
+ else @numberfmt_default&.map { |k, v| "#{k}=#{v}" }&.join(",")
172
+ end
173
+ end
174
+
175
+ def mathml_number_format(stem)
176
+ mathml_stem_format(stem)
177
+ mathml_mn_format(stem)
178
+ stem.delete("number-format")
179
+ end
180
+
229
181
  def mathml_cleanup(xmldoc)
230
182
  unitsml = Asciimath2UnitsML::Conv.new(asciimath2unitsml_options)
231
183
  xmldoc.xpath("//stem[@type = 'MathML'][not(@validate = 'false')]")
232
184
  .each do |x|
233
- xml_unescape_mathml(x)
234
- mathml_namespace(x)
235
- mathml_preserve_space(x)
185
+ mathml_xml_cleanup(x)
236
186
  unitsml.MathML2UnitsML(x)
237
187
  mathml_mathvariant(x)
238
- mathml_italicise(x)
239
- mathml_mn_format(x)
188
+ mathml_number_format(x)
240
189
  end
241
190
  mathml_unitsML(xmldoc)
242
191
  end
@@ -0,0 +1,88 @@
1
+ module Metanorma
2
+ module Standoc
3
+ module Cleanup
4
+ def mathml_mi_italics
5
+ { uppergreek: true, upperroman: true,
6
+ lowergreek: true, lowerroman: true }
7
+ end
8
+
9
+ # presuppose multichar mi upright, singlechar mi MathML default italic
10
+ def mathml_italicise(xml)
11
+ xml.xpath(".//m:mi[not(ancestor::*[@mathvariant])]",
12
+ "m" => MATHML_NS).each do |i|
13
+ char = @c.decode(i.text)
14
+ i["mathvariant"] = "normal" if mi_italicise?(char)
15
+ end
16
+ end
17
+
18
+ def mi_italicise?(char)
19
+ char.length > 1 and return false
20
+ case char
21
+ when /\p{Greek}/
22
+ (/\p{Lower}/.match(char) && !mathml_mi_italics[:lowergreek]) ||
23
+ (/\p{Upper}/.match(char) && !mathml_mi_italics[:uppergreek])
24
+ when /\p{Latin}/
25
+ (/\p{Lower}/.match(char) && !mathml_mi_italics[:lowerroman]) ||
26
+ (/\p{Upper}/.match(char) && !mathml_mi_italics[:upperroman])
27
+ else false
28
+ end
29
+ end
30
+
31
+ MATHVARIANT_OVERRIDE = {
32
+ bold: { normal: "bold", italic: "bold-italic", fraktur: "bold-fraktur",
33
+ script: "bold-script", "sans-serif": "bold-sans-serif",
34
+ "sans-serif-italic": "sans-serif-bold-italic" },
35
+ italic: { normal: "italic", bod: "bold-italic",
36
+ "sans-serif": "sans-serif-italic",
37
+ "bold-sans-serif": "sans-serif-bold-italic" },
38
+ "bold-italic": { normal: "bold-italic", bold: "bold-italic",
39
+ italic: "bold-italic",
40
+ "sans-serif": "sans-serif-bold-italic",
41
+ "bold-sans-serif": "sans-serif-bold-italic",
42
+ "sans-serif-italic": "sans-serif-bold-italic" },
43
+ fraktur: { normal: "fraktur", bold: "bold-fraktur" },
44
+ "bold-fraktur": { normal: "bold-fraktur", fraktur: "bold-fraktur" },
45
+ script: { normal: "script", bold: "bold-script" },
46
+ "bold-script": { normal: "script", script: "bold-script" },
47
+ "sans-serif": { normal: "sans-serif", bold: "bold-sans-serif",
48
+ italic: "sans-serif-italic",
49
+ "bold-italic": "sans-serif-bold-italic" },
50
+ "bold-sans-serif": { normal: "bold-sans-serif", bold: "bold-sans-serif",
51
+ "sans-serif": "bold-sans-serif",
52
+ italic: "sans-serif-bold-italic",
53
+ "bold-italic": "sans-serif-bold-italic",
54
+ "sans-serif-italic": "sans-serif-bold-italic" },
55
+ "sans-serif-italic": { normal: "sans-serif-italic",
56
+ italic: "sans-serif-italic",
57
+ "sans-serif": "sans-serif-italic",
58
+ bold: "sans-serif-bold-italic",
59
+ "bold-italic": "sans-serif-bold-italic",
60
+ "sans-serif-bold": "sans-serif-bold-italic" },
61
+ "sans-serif-bold-italic": { normal: "sans-serif-bold-italic",
62
+ italic: "sans-serif-bold-italic",
63
+ "sans-serif": "sans-serif-bold-italic",
64
+ "sans-serif-italic": "sans-serif-bold-italic",
65
+ bold: "sans-serif-bold-italic",
66
+ "bold-italic": "sans-serif-bold-italic",
67
+ "sans-serif-bold": "sans-serif-bold-italic" },
68
+ }.freeze
69
+
70
+ def mathvariant_override(inner, outer)
71
+ o = outer.to_sym
72
+ i = inner.to_sym
73
+ MATHVARIANT_OVERRIDE[o] or return inner
74
+ MATHVARIANT_OVERRIDE[o][i] || inner
75
+ end
76
+
77
+ def mathml_mathvariant(math)
78
+ math.xpath(".//*[@mathvariant]").each do |outer|
79
+ outer.xpath(".//*[@mathvariant]").each do |inner|
80
+ inner["mathvariant"] =
81
+ mathvariant_override(inner["mathvariant"], outer["mathvariant"])
82
+ end
83
+ end
84
+ mathml_italicise(math)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -73,11 +73,14 @@ module Metanorma
73
73
  xmldoc.xpath("//termdocsource").each { |s| f.previous = s.remove }
74
74
  end
75
75
 
76
- def term_children_cleanup(xmldoc)
76
+ def terms_terms_cleanup(xmldoc)
77
77
  xmldoc.xpath("//terms[terms][not(term)]").each do |t|
78
78
  t.name = "clause"
79
79
  t["type"] = "terms"
80
80
  end
81
+ end
82
+
83
+ def term_children_cleanup(xmldoc)
81
84
  xmldoc.xpath("//term").each do |t|
82
85
  %w(termnote termexample termsource term).each do |w|
83
86
  t.xpath("./#{w}").each { |n| t << n.remove }
@@ -0,0 +1,106 @@
1
+ module Metanorma
2
+ module Standoc
3
+ module Cleanup
4
+ def external_terms_boilerplate(sources)
5
+ e = @i18n.external_terms_boilerplate
6
+ e.gsub(/%(?=\p{P}|\p{Z}|$)/, sources || "???")
7
+ end
8
+
9
+ def internal_external_terms_boilerplate(sources)
10
+ e = @i18n.internal_external_terms_boilerplate
11
+ e.gsub(/%(?=\p{P}|\p{Z}|$)/, sources || "??")
12
+ end
13
+
14
+ def boilerplate_snippet_convert(adoc)
15
+ ret = boilerplate_xml_cleanup(adoc2xml(adoc, backend.to_sym))
16
+ @i18n.l10n(ret.children.to_xml, @lang, @script)
17
+ end
18
+
19
+ def term_defs_boilerplate(div, source, term, _preface, isodoc)
20
+ verify_term_defs_source(source)
21
+ a = @i18n.term_def_boilerplate and
22
+ div.next = boilerplate_snippet_convert(a)
23
+ a = if source.empty? && term.nil? then @i18n.no_terms_boilerplate
24
+ else term_defs_boilerplate_cont(source, term, isodoc)
25
+ end
26
+ a and div.next = boilerplate_snippet_convert(a)
27
+ end
28
+
29
+ def verify_term_defs_source(source)
30
+ source.each do |s|
31
+ @anchors[s["bibitemid"]] or
32
+ @log.add("Crossreferences", nil,
33
+ "term source #{s['bibitemid']} not referenced",
34
+ severity: 1)
35
+ end
36
+ end
37
+
38
+ def term_defs_boilerplate_cont(src, term, isodoc)
39
+ sources = isodoc.sentence_join(src.map do |s|
40
+ %{<<#{s['bibitemid']}>>}
41
+ end)
42
+ if src.empty? then @i18n.internal_terms_boilerplate
43
+ elsif term.nil? then external_terms_boilerplate(sources)
44
+ else
45
+ internal_external_terms_boilerplate(sources)
46
+ end
47
+ end
48
+
49
+ TERM_CLAUSE =
50
+ "//sections//terms[not(.//ancestor::clause[@type = 'terms'])] | " \
51
+ "//sections/clause[descendant::terms][@type = 'terms'] | " \
52
+ "//sections/clause[not(@type = 'terms')]//terms".freeze
53
+
54
+ def termdef_boilerplate_cleanup(xmldoc)
55
+ # termdef_remove_initial_paras(xmldoc)
56
+ end
57
+
58
+ def termdef_remove_initial_paras(xmldoc)
59
+ xmldoc.xpath("//terms/p | //terms/ul").each(&:remove)
60
+ end
61
+
62
+ def termdef_boilerplate_insert(xmldoc, isodoc, once = false)
63
+ if once
64
+ f = termdef_boilerplate_insert_location(xmldoc) and
65
+ termdef_boilerplate_insert1(f, xmldoc, isodoc)
66
+ else
67
+ xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
68
+ termdef_boilerplate_insert1(f, xmldoc, isodoc)
69
+ end
70
+ end
71
+ end
72
+
73
+ def termdef_boilerplate_insert_location(xmldoc)
74
+ f = xmldoc.at(self.class::TERM_CLAUSE)
75
+ root = xmldoc.at("//sections/terms | //sections/clause[@type = 'terms']")
76
+ if f && root && f["id"] != root["id"]
77
+ f = termdef_boilerplate_climb_up(f, root)
78
+ elsif !f && root then f = root
79
+ end
80
+ f
81
+ end
82
+
83
+ def termdef_boilerplate_climb_up(clause, container)
84
+ container.at(".//*[@id = '#{clause['id']}']") or return clause
85
+ while (n = clause.parent)
86
+ n.at(".//definitions") and break
87
+ clause = n
88
+ n["id"] == container["id"] and break
89
+ end
90
+ clause
91
+ end
92
+
93
+ def termdef_boilerplate_insert1(sect, xmldoc, isodoc)
94
+ ins = sect.at("./title")
95
+ if (ins2 = sect.at("./clause[@type = 'boilerplate'] | " \
96
+ "./note[@type = 'boilerplate']"))
97
+ ins2.text.strip.downcase == "(default)" or return
98
+ ins2.children = " "
99
+ ins = ins2.children.first
100
+ end
101
+ term_defs_boilerplate(ins, xmldoc.xpath(".//termdocsource"),
102
+ sect.at(".//term"), sect.at(".//p"), isodoc)
103
+ end
104
+ end
105
+ end
106
+ end
@@ -156,8 +156,7 @@ module Metanorma
156
156
  while %w(domain subject).include? p&.name
157
157
  p = p.previous_element
158
158
  end
159
- DESIGNATOR.include?(p&.name) or
160
- next
159
+ DESIGNATOR.include?(p&.name) or next
161
160
  related2pref(p) << t.remove
162
161
  end
163
162
  end
@@ -2,8 +2,8 @@ module Metanorma
2
2
  module Standoc
3
3
  module Cleanup
4
4
  def textcleanup(result)
5
- text = result.flatten.map { |l| l.sub(/\s*\Z/, "") } * "\n"
6
- text = text.gsub(/\s+<fn /, "<fn ")
5
+ text = result.flatten.map(&:rstrip) * "\n"
6
+ text = text.gsub(/(?<!\s)\s+<fn /, "<fn ")
7
7
  %w(passthrough passthrough-inline).each do |v|
8
8
  text.gsub!(%r{<#{v}\s+formats="metanorma">([^<]*)
9
9
  </#{v}>}mx) { @c.decode($1) }
@@ -176,7 +176,7 @@ module Metanorma
176
176
 
177
177
  def xref_compound_cleanup1(xref, locations)
178
178
  xref.children.empty? and xref.children = "<sentinel/>"
179
- xref_parse_compound_locations(locations).reverse.each do |y|
179
+ xref_parse_compound_locations(locations).reverse_each do |y|
180
180
  xref.children.first.previous =
181
181
  "<xref target='#{y[1]}' connective='#{y[0]}'/>"
182
182
  end
@@ -15,7 +15,7 @@ module Metanorma
15
15
  end
16
16
 
17
17
  def join_as_plantuml(*ary)
18
- ary.compact.join("\n").sub(/\s+\Z/, "")
18
+ ary.compact.join("\n").sub(/(?<!\s)\s+\Z/, "")
19
19
  end
20
20
 
21
21
  def render
@@ -74,7 +74,7 @@ module Metanorma
74
74
 
75
75
  def metadata_date1(node, xml, type)
76
76
  date = node.attr("#{type}-date")
77
- date and xml.date type: type do |d|
77
+ date and xml.date(type:) do |d|
78
78
  d.on date
79
79
  end
80
80
  end
@@ -91,7 +91,7 @@ module Metanorma
91
91
  a == "date" || /^date_\d+$/.match(a) or next
92
92
  type, date = node.attr(a).split(/ /, 2)
93
93
  type or next
94
- xml.date type: type do |d|
94
+ xml.date(type:) do |d|
95
95
  d.on date
96
96
  end
97
97
  end
@@ -139,7 +139,7 @@ module Metanorma
139
139
  def metadata_getrelation1(doc, xml, type, desc)
140
140
  id = doc.split(/,\s*/)
141
141
  xml.relation type: relation_normalise(type) do |r|
142
- desc.nil? or r.description desc.gsub(/-/, " ")
142
+ desc.nil? or r.description desc.tr("-", " ")
143
143
  fetch_ref(r, doc, nil, **{}) or r.bibitem do |b|
144
144
  b.title id[1] || "--"
145
145
  b.docidentifier id[0]
@@ -103,6 +103,7 @@ module Metanorma
103
103
  def init_biblio(node)
104
104
  @no_isobib_cache = node.attr("no-isobib-cache")
105
105
  @no_isobib = node.attr("no-isobib")
106
+ @flush_caches = node.attr("flush-caches")
106
107
  init_bib_log
107
108
  @bibdb = nil
108
109
  init_bib_caches(node)
@@ -123,6 +124,11 @@ module Metanorma
123
124
  @keepasciimath = node.attr("mn-keep-asciimath") &&
124
125
  node.attr("mn-keep-asciimath") != "false"
125
126
  @numberfmt_default = kv_parse(node.attr("number-presentation"))
127
+ @numberfmt_formula = node.attr("number-presentation-formula")
128
+ @numberfmt_formula == "number-presentation" and
129
+ @numberfmt_formula = node.attr("number-presentation")
130
+ @numberfmt_formula == "default" and
131
+ @numberfmt_formula = "notation='basic'"
126
132
  @numberfmt_prof = node.attributes.each_with_object({}) do |(k, v), m|
127
133
  p = /^number-presentation-profile-(.*)$/.match(k) or next
128
134
  m[p[1]] = kv_parse(v)
@@ -39,25 +39,30 @@ module Metanorma
39
39
  results.sub(%r{<math ([^>]+ )?display="block"}, "<math \\1")
40
40
  end
41
41
 
42
- def stem_parse(text, xml, style, block)
42
+ def stem_parse(text, xml, style, node)
43
+ attr = stem_attrs(node)
43
44
  if /&lt;([^:>&]+:)?math(\s+[^>&]+)?&gt; |
44
45
  <([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
45
- math = xml_encode(text)
46
- xml.stem(type: "MathML", block:) do |s|
47
- s << math
46
+ xml.stem **attr.merge(type: "MathML") do |s|
47
+ s << xml_encode(text)
48
48
  end
49
- elsif style == :latexmath then latex_parse(text, xml, block)
49
+ elsif style == :latexmath then latex_parse(text, xml, attr)
50
50
  else
51
- xml.stem text&.gsub("&amp;#", "&#"), type: "AsciiMath", block:
51
+ xml.stem text&.gsub("&amp;#", "&#"), **attr.merge(type: "AsciiMath")
52
52
  end
53
53
  end
54
54
 
55
- def latex_parse(text, xml, block)
56
- latex = latex_parse1(text, block) or
57
- return xml.stem(type: "MathML", block:)
58
- xml.stem(type: "MathML", block:) do |s|
55
+ def stem_attrs(node)
56
+ n = node.attr("number-format")
57
+ { block: node.block?, "number-format": n }.compact
58
+ end
59
+
60
+ def latex_parse(text, xml, attr)
61
+ latex = latex_parse1(text, attr[:block]) or
62
+ return xml.stem **attr.merge(type: "MathML")
63
+ xml.stem **attr.merge(type: "MathML") do |s|
59
64
  math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, ""))
60
- .elements[0]
65
+ .elements[0]
61
66
  math.delete("alttext")
62
67
  s.parent.children = math
63
68
  s << "<latexmath>#{text}</latexmath>"
@@ -78,8 +83,8 @@ module Metanorma
78
83
  when :single then xml << "'#{node.text}'"
79
84
  when :superscript then xml.sup { |s| s << node.text }
80
85
  when :subscript then xml.sub { |s| s << node.text }
81
- when :asciimath then stem_parse(node.text, xml, :asciimath, false)
82
- when :latexmath then stem_parse(node.text, xml, :latexmath, false)
86
+ when :asciimath then stem_parse(node.text, xml, :asciimath, node)
87
+ when :latexmath then stem_parse(node.text, xml, :latexmath, node)
83
88
  when :mark then highlight_parse(node.text, xml)
84
89
  else
85
90
  case node.role
@@ -123,7 +128,7 @@ module Metanorma
123
128
  end
124
129
  uri = node.image_uri (nodetarget)
125
130
  if Gem.win_platform? && /^\/[a-zA-Z]:/.match?(uri)
126
- uri = uri[1..-1]
131
+ uri = uri[1..]
127
132
  end
128
133
  types = if /^data:/.match?(uri) then Vectory::Utils::datauri2mime(uri)
129
134
  else MIME::Types.type_for(uri)
@@ -662,6 +662,9 @@
662
662
  <value>LatexMath</value>
663
663
  </choice>
664
664
  </attribute>
665
+ <optional>
666
+ <attribute name="number-format"/>
667
+ </optional>
665
668
  <attribute name="block">
666
669
  <data type="boolean"/>
667
670
  </attribute>
@@ -23,7 +23,7 @@ module Metanorma
23
23
 
24
24
  def init_file_bibdb_config(defn, key)
25
25
  /=/.match?(defn) or defn = "file=#{defn}"
26
- values = defn.split(",").map { |item| item.split /\s*=\s*/ }.to_h
26
+ values = defn.split(",").map { |item| item.split /(?<!\s)\s*=\s*/ }.to_h
27
27
  values["key"] = key
28
28
  values["format"] ||= "bibtex" # all we currently suppoort
29
29
  values
@@ -22,7 +22,7 @@ module Metanorma
22
22
  on_context :example, :sourcecode
23
23
 
24
24
  def init_indent(line)
25
- /^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ line
25
+ /^(?<prefix>[ \t]*)(?![ \t])(?<suffix>.*)$/ =~ line
26
26
  prefix = prefix.gsub("\t", "\u00a0\u00a0\u00a0\u00a0")
27
27
  .tr(" ", "\u00a0")
28
28
  prefix + suffix
@@ -178,10 +178,10 @@ module Metanorma
178
178
  def process(parent, target, attrs)
179
179
  out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
180
180
  fmt = format(out)
181
- fmt.empty? and fmt = "notation='basic'"
182
- fmt = %( data-metanorma-numberformat="#{fmt}")
181
+ fmt.empty? and fmt = "default"
182
+ fmt = %( number-format="#{fmt}")
183
183
  <<~OUTPUT
184
- <stem type="MathML"><math xmlns='#{MATHML_NS}'><mn#{fmt}>#{number(target)}</mn></math></stem>
184
+ <stem type="MathML"#{fmt}><math xmlns='#{MATHML_NS}'><mn>#{number(target)}</mn></math></stem>
185
185
  OUTPUT
186
186
  end
187
187
  end
@@ -71,7 +71,7 @@ module Metanorma
71
71
 
72
72
  def self.prep_source(reader)
73
73
  src = reader.source
74
- reader.lines.first.sub(/\s+$/, "").match /^@startuml($| )/ or
74
+ reader.lines.first.sub(/(?<!\s)\s+$/, "").match /^@startuml($| )/ or
75
75
  src = "@startuml\n#{src}\n@enduml\n"
76
76
  %r{@enduml\s*$}m.match?(src) or
77
77
  raise "@startuml without matching @enduml in PlantUML!"
@@ -5,7 +5,7 @@ module Metanorma
5
5
  module Standoc
6
6
  module Refs
7
7
  def iso_publisher(bib, code)
8
- code.sub(/ .*$/, "").split("/").each do |abbrev|
8
+ code.sub(/(?<! ) .*$/, "").split("/").each do |abbrev|
9
9
  bib.contributor do |c|
10
10
  c.role type: "publisher"
11
11
  c.organization do |org|
@@ -228,7 +228,7 @@ module Metanorma
228
228
  @iev_globalname = global_ievcache_name
229
229
  @iev_localname = local_ievcache_name(node.attr("local-cache") ||
230
230
  node.attr("local-cache-only"))
231
- if node.attr("flush-caches")
231
+ if @flush_caches
232
232
  FileUtils.rm_f @iev_globalname unless @iev_globalname.nil?
233
233
  FileUtils.rm_f @iev_localname unless @iev_localname.nil?
234
234
  end
@@ -20,7 +20,7 @@ module Metanorma
20
20
  def norm_year(year)
21
21
  /^&\#821[12];$/.match(year) and return "--"
22
22
  /^\d\d\d\d-\d\d\d\d$/.match(year) and return year
23
- year&.sub(/(?<=[0-9])-.*$/, "")
23
+ year&.sub(/^([0-9]+)-.*$/, "\\1")
24
24
  end
25
25
 
26
26
  def conditional_date(bib, match, noyr)
@@ -46,7 +46,7 @@ module Metanorma
46
46
  @bibdb&.docid_type(code) || [nil, code]
47
47
  end
48
48
  code1.sub!(/^nofetch\((.+)\)$/, "\\1")
49
- bib.docidentifier **attr_code(type: type) do |d|
49
+ bib.docidentifier **attr_code(type:) do |d|
50
50
  d << code1
51
51
  end
52
52
  end
@@ -59,7 +59,7 @@ module Metanorma
59
59
  end
60
60
 
61
61
  def mn_code(code)
62
- code.sub(/^\(/, "[").sub(/\).*$/, "]")
62
+ code.sub(/^\(/, "[").sub(/^([^)]+)\).*$/, "\\1]")
63
63
  .sub(/^dropid\((.+)\)$/, "\\1")
64
64
  .sub(/^hidden\((.+)\)$/, "\\1")
65
65
  .sub(/^nofetch\((.+)\)$/, "\\1")
@@ -67,7 +67,8 @@ module Metanorma
67
67
  end
68
68
 
69
69
  def analyse_ref_localfile(ret)
70
- m = /^local-file\((?:(?<source>[^,]+),\s*)?(?<id>.+)\)$/.match(ret[:id])
70
+ m = /^local-file\((?:(?<source>[^,)]+),\s*)?(?<id>[^)]+)\)$/
71
+ .match(ret[:id])
71
72
  m or return ret
72
73
  ret.merge(id: m[:id], localfile: m[:source] || "default")
73
74
  end
@@ -88,7 +89,7 @@ module Metanorma
88
89
  end
89
90
 
90
91
  def analyse_ref_repo_path(ret)
91
- m = /^(?<type>repo|path|attachment):\((?<key>[^,]+),?(?<id>[^)]*)\)$/
92
+ m = /^(?<type>repo|path|attachment):\((?<key>[^,)]+),?(?<id>[^)]*)\)$/
92
93
  .match(ret[:id]) or return ret
93
94
  id = if m[:id].empty?
94
95
  if m[:type] == "attachment"
@@ -96,7 +97,7 @@ module Metanorma
96
97
  else m[:key].sub(%r{^[^/]+/}, "")
97
98
  end
98
99
  else m[:id] end
99
- ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true)
100
+ ret.merge(id:, type: m[:type], key: m[:key], nofetch: true)
100
101
  end
101
102
 
102
103
  def analyse_ref_numeric(ret)
@@ -66,6 +66,9 @@
66
66
  <ref name="MultilingualRenderingType"/>
67
67
  </attribute>
68
68
  </optional>
69
+ <optional>
70
+ <attribute name="class"/>
71
+ </optional>
69
72
  <optional>
70
73
  <ref name="reqtitle"/>
71
74
  </optional>
@@ -14,8 +14,8 @@ module Metanorma
14
14
  node.attr("heading")&.downcase ||
15
15
  node.title
16
16
  .gsub(%r{<index>.*?</index>}m, "")
17
- .gsub(%r{<fn[^>]*>.*?</fn>}m, "")
18
- .gsub(/<[^>]+>/, "")
17
+ .gsub(%r{<fn[^<>]*>.*?</fn>}m, "")
18
+ .gsub(/<[^<>]+>/, "")
19
19
  .strip.downcase.sub(/\.$/, "")
20
20
  end
21
21
 
@@ -4,7 +4,7 @@ module Metanorma
4
4
  module Standoc
5
5
  # Intelligent term lookup xml modifier
6
6
  class TermLookupCleanup
7
- AUTO_GEN_ID_REGEXP = /\A_/.freeze
7
+ AUTO_GEN_ID_REGEXP = /\A_/
8
8
 
9
9
  attr_reader :xmldoc, :lookup, :log
10
10
 
@@ -130,7 +130,7 @@ module Metanorma
130
130
  end
131
131
 
132
132
  def remove_missing_ref_msg1(_node, target, ret)
133
- target2 = "_#{target.downcase.gsub('-', '_')}"
133
+ target2 = "_#{target.downcase.tr('-', '_')}"
134
134
  if @terms_tags[target] || @terms_tags[target2]
135
135
  ret.strip!
136
136
  ret += ". Did you mean to point to a subterm?"
@@ -100,8 +100,9 @@ module Metanorma
100
100
  # wrapped in <sections>
101
101
  def adoc2xml(text, flavour)
102
102
  Nokogiri::XML(text).root and return text
103
+ f = @flush_caches ? ":flush-caches:\n" : ""
103
104
  c = Asciidoctor.convert("= X\nA\n:semantic-metadata-headless: true\n" \
104
- ":novalid:\n\n#{text}\n",
105
+ ":no-isobib:\n#{f}:novalid:\n\n#{text}\n",
105
106
  backend: flavour, header_footer: true)
106
107
  Nokogiri::XML(c).at("//xmlns:sections")
107
108
  end
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "2.9.4".freeze
22
+ VERSION = "2.9.6".freeze
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-standoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.4
4
+ version: 2.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-19 00:00:00.000000000 Z
11
+ date: 2024-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -528,6 +528,7 @@ files:
528
528
  - lib/metanorma/standoc/cleanup_image.rb
529
529
  - lib/metanorma/standoc/cleanup_inline.rb
530
530
  - lib/metanorma/standoc/cleanup_maths.rb
531
+ - lib/metanorma/standoc/cleanup_mathvariant.rb
531
532
  - lib/metanorma/standoc/cleanup_ref.rb
532
533
  - lib/metanorma/standoc/cleanup_reqt.rb
533
534
  - lib/metanorma/standoc/cleanup_section.rb
@@ -535,6 +536,7 @@ files:
535
536
  - lib/metanorma/standoc/cleanup_symbols.rb
536
537
  - lib/metanorma/standoc/cleanup_table.rb
537
538
  - lib/metanorma/standoc/cleanup_terms.rb
539
+ - lib/metanorma/standoc/cleanup_terms_boilerplate.rb
538
540
  - lib/metanorma/standoc/cleanup_terms_designations.rb
539
541
  - lib/metanorma/standoc/cleanup_text.rb
540
542
  - lib/metanorma/standoc/cleanup_toc.rb