isodoc 2.5.0 → 2.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15d6f1ca680a6bb801c444655ba27e347ca04a671c207b9a74ad4c6388596394
4
- data.tar.gz: 02e6caa0ae2463bd2966ee14a9837c0d1b1b4cfac77596380bbb3856979ee142
3
+ metadata.gz: 35414cac7eab8ae893d39af33b9f3ecf591c33bd5013ea6340b13b26c23e73e1
4
+ data.tar.gz: b4820f7236dc69a3fadf213dcd7fef2eadddebbf85dc02a4ec7364c688baa4da
5
5
  SHA512:
6
- metadata.gz: 857b7630d0a1146e5070b3ced33eb99b40089cf114181b6519cd1e26a5c17fc8b1e36dfe59ea115055fb2f8cbf901c57b7ad730fe39878e0cf589201eb06222a
7
- data.tar.gz: 4ca7278d7571fc4aa64fa6443a373d77d352ffe64b79086ef142aad1260a25e57589023707a153bb54cae60bd4e441d2ed116a33f18db2905907b61b5c14875f
6
+ metadata.gz: 902033f59dc11d6f097e7477aa8ea44cc7eb199e085778a3eee2cfa771d7a40a85869176ff0c57e0cad88d1c270546a7d9419da2119fb3a6d435c629aeea6acc
7
+ data.tar.gz: 0f346f7277f8aab99189f29d2e1a35a6d36c593cfd52628d37f9245acb39e7ea0aa8761f6797e18dbb1b1069812ffbf2c2563f97e472cfa628047c6e84df0eb0
data/isodoc.gemspec CHANGED
@@ -29,17 +29,17 @@ Gem::Specification.new do |spec|
29
29
  spec.test_files = `git ls-files -- {spec}/*`.split("\n")
30
30
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
31
31
 
32
- spec.add_dependency "asciimath"
33
- spec.add_dependency "html2doc", "~> 1.4.3"
32
+ spec.add_dependency "html2doc", "~> 1.5.3"
34
33
  spec.add_dependency "htmlentities", "~> 4.3.4"
35
34
  # spec.add_dependency "isodoc-i18n", "~> 1.1.0" # already in relaton-render and mn-requirements
36
- spec.add_dependency "liquid", "~> 4"
37
- # spec.add_dependency "metanorma", ">= 1.2.0"
35
+ spec.add_dependency "liquid", "~> 5"
38
36
  spec.add_dependency "emf2svg"
39
- spec.add_dependency "mathml2asciimath"
40
- spec.add_dependency "metanorma-utils", "~> 1.4.5"
37
+ spec.add_dependency "plurimath"
38
+ spec.add_dependency "relaton-cli"
39
+ # spec.add_dependency "metanorma-utils", "~> 1.5.0" # already in isodoc-i18n
41
40
  spec.add_dependency "mn2pdf"
42
41
  spec.add_dependency "mn-requirements", "~> 0.3.1"
42
+
43
43
  spec.add_dependency "relaton-render", "~> 0.5.2"
44
44
  spec.add_dependency "roman-numerals"
45
45
  spec.add_dependency "rouge", "~> 4.0"
@@ -63,109 +63,6 @@ module IsoDoc
63
63
  init_arrangement(@options)
64
64
  end
65
65
 
66
- def options_preprocess(options)
67
- options.merge!(default_fonts(options)) do |_, old, new|
68
- old || new
69
- end.merge!(default_file_locations(options)) do |_, old, new|
70
- old || new
71
- end
72
- options
73
- end
74
-
75
- def init_rendering(options)
76
- @ulstyle = options[:ulstyle]
77
- @olstyle = options[:olstyle]
78
- @datauriimage = options[:datauriimage]
79
- @suppressheadingnumbers = options[:suppressheadingnumbers]
80
- @break_up_urls_in_tables = options[:breakupurlsintables]
81
- @suppressasciimathdup = options[:suppressasciimathdup]
82
- @aligncrosselements = options[:aligncrosselements]
83
- @modspecidentifierbase = options[:modspecidentifierbase]
84
- @sourcehighlighter = options[:sourcehighlighter]
85
- end
86
-
87
- def init_arrangement(options)
88
- @sectionsplit = options[:sectionsplit] == "true"
89
- @bare = options[:bare]
90
- @semantic_xml_insert = options[:semanticxmlinsert] != "false"
91
- end
92
-
93
- def init_i18n(options)
94
- @i18nyaml = options[:i18nyaml]
95
- @lang = options[:language] || "en"
96
- @script = options[:script] || "Latn"
97
- @locale = options[:locale]
98
- @localizenumber = options[:localizenumber]
99
- end
100
-
101
- def init_locations(options)
102
- @libdir ||= File.dirname(__FILE__)
103
- @baseassetpath = options[:baseassetpath]
104
- @tmpimagedir_suffix = tmpimagedir_suffix
105
- @tmpfilesdir_suffix = tmpfilesdir_suffix
106
- @sourcefilename = options[:sourcefilename]
107
- @files_to_delete = []
108
- @tempfile_cache = []
109
- end
110
-
111
- def init_processing
112
- @termdomain = ""
113
- @termexample = false
114
- @note = false
115
- @sourcecode = false
116
- @footnotes = []
117
- @comments = []
118
- @in_footnote = false
119
- @in_comment = false
120
- @in_table = false
121
- @in_figure = false
122
- @seen_footnote = Set.new
123
- @c = HTMLEntities.new
124
- @openmathdelim = "`"
125
- @closemathdelim = "`"
126
- @maxwidth = 1200
127
- @maxheight = 800
128
- @bookmarks_allocated = { "X" => true }
129
- @fn_bookmarks = {}
130
- end
131
-
132
- def init_fonts(options)
133
- @normalfontsize = options[:normalfontsize]
134
- @smallerfontsize = options[:smallerfontsize]
135
- @monospacefontsize = options[:monospacefontsize]
136
- @footnotefontsize = options[:footnotefontsize]
137
- @fontist_fonts = options[:fonts]
138
- @fontlicenseagreement = options[:fontlicenseagreement]
139
- end
140
-
141
- def init_covers(options)
142
- @header = options[:header]
143
- @htmlcoverpage = options[:htmlcoverpage]
144
- @wordcoverpage = options[:wordcoverpage]
145
- @htmlintropage = options[:htmlintropage]
146
- @wordintropage = options[:wordintropage]
147
- @scripts = options[:scripts] ||
148
- File.join(File.dirname(__FILE__), "base_style", "scripts.html")
149
- @scripts_pdf = options[:scripts_pdf]
150
- @scripts_override = options[:scripts_override]
151
- end
152
-
153
- def init_stylesheets(options)
154
- @htmlstylesheet_name = options[:htmlstylesheet]
155
- @wordstylesheet_name = options[:wordstylesheet]
156
- @htmlstylesheet_override_name = options[:htmlstylesheet_override]
157
- @wordstylesheet_override_name = options[:wordstylesheet_override]
158
- @standardstylesheet_name = options[:standardstylesheet]
159
- end
160
-
161
- def init_toc(options)
162
- @htmlToClevels = 2
163
- @wordToClevels = 2
164
- @tocfigures = options[:tocfigures]
165
- @toctables = options[:toctables]
166
- @tocrecommendations = options[:tocrecommendations]
167
- end
168
-
169
66
  def tmpimagedir_suffix
170
67
  "_#{SecureRandom.hex(8)}_images"
171
68
  end
@@ -214,28 +111,52 @@ module IsoDoc
214
111
  convert_i18n_init(docxml)
215
112
  metadata_init(@lang, @script, @locale, @i18n)
216
113
  xref_init(@lang, @script, self, @i18n, { locale: @locale })
114
+ docxml = preprocess_xslt(docxml)
217
115
  toc_init(docxml)
218
116
  [docxml, filename, dir]
219
117
  end
220
118
 
119
+ def preprocess_xslt(docxml)
120
+ extract_preprocess_xslt(docxml).each do |x|
121
+ docxml = Nokogiri::XSLT(x).transform(docxml)
122
+ end
123
+ docxml
124
+ end
125
+
126
+ def extract_preprocess_xslt(docxml)
127
+ docxml.xpath(ns("//metanorma-extension/render/preprocess-xslt"))
128
+ .each_with_object([]) do |x, m|
129
+ formats = x["format"]&.split(",") || []
130
+ !formats.empty? && !formats.include?(@format.to_s) and next
131
+ m << x.children.to_xml
132
+ end
133
+ end
134
+
221
135
  def convert_i18n_init(docxml)
222
- lang = docxml.at(ns("//bibdata/language")) and @lang = lang.text
223
- script = docxml.at(ns("//bibdata/script")) and @script = script.text
224
- locale = docxml.at(ns("//bibdata/locale")) and @locale = locale.text
136
+ convert_i18n_init1(docxml)
225
137
  i18n_init(@lang, @script, @locale)
226
138
  @reqt_models = requirements_processor
227
139
  .new({ default: "default", lang: @lang, script: @script, locale: @locale,
228
140
  labels: @i18n.get, modspecidentifierbase: @modspecidentifierbase })
229
141
  end
230
142
 
143
+ def convert_i18n_init1(docxml)
144
+ lang = docxml.at(ns("//bibdata/language")) and @lang = lang.text
145
+ if script = docxml.at(ns("//bibdata/script"))
146
+ @script = script.text
147
+ elsif lang
148
+ @script = ::Metanorma::Utils::default_script(@lang)
149
+ end
150
+ locale = docxml.at(ns("//bibdata/locale")) and @locale = locale.text
151
+ end
152
+
231
153
  def convert(input_filename, file = nil, debug = false,
232
154
  output_filename = nil)
233
155
  file = File.read(input_filename, encoding: "utf-8") if file.nil?
234
156
  @openmathdelim, @closemathdelim = extract_delims(file)
235
157
  docxml, filename, dir = convert_init(file, input_filename, debug)
236
158
  result = convert1(docxml, filename, dir)
237
- return result if debug
238
-
159
+ debug and return result
239
160
  output_filename ||= "#{filename}.#{@suffix}"
240
161
  postprocess(result, output_filename, dir)
241
162
  FileUtils.rm_rf dir
@@ -76,6 +76,7 @@ module IsoDoc
76
76
  out.p **sourcecode_attrs(node) do |div|
77
77
  sourcecode_parse1(node, div)
78
78
  end
79
+ annotation_parse(node, out)
79
80
  sourcecode_name_parse(node, out, name)
80
81
  end
81
82
 
@@ -84,9 +85,10 @@ module IsoDoc
84
85
  node.at(ns(".//table[@class = 'rouge-line-table']")) ||
85
86
  node.at("./ancestor::xmlns:table[@class = 'rouge-line-table']") and
86
87
  @sourcecode = "table"
87
- # !node.ancestors("table").empty? and
88
- # @sourcecode = "table"
89
- node.children.each { |n| parse(n, div) unless n.name == "name" }
88
+ node.children.each do |n|
89
+ %w(name dl).include?(n.name) and next
90
+ parse(n, div)
91
+ end
90
92
  @sourcecode = false
91
93
  end
92
94
 
@@ -95,17 +97,12 @@ module IsoDoc
95
97
  end
96
98
 
97
99
  def annotation_parse(node, out)
100
+ dl = node.at(ns("./dl")) or return
98
101
  @sourcecode = false
99
- @annotation = true
102
+ # @annotation = true
100
103
  out.div class: "annotation" do |div|
101
- # node.at("./preceding-sibling::*[local-name() = 'annotation']") or
102
- # div << "<br/>"
103
- callout = node.at(ns("//callout[@target='#{node['id']}']"))
104
- div << "<span class='c'>&lt;#{callout.text}&gt;</span> "
105
- div << "<span class='c'>#{node.children&.text&.strip}</span>"
106
- node.at("./following-sibling::*[local-name() = 'annotation']") and
107
- div << "<br/>"
108
- @annotation = false
104
+ parse(dl, div)
105
+ # @annotation = false
109
106
  end
110
107
  end
111
108
 
@@ -203,6 +200,14 @@ module IsoDoc
203
200
  node.children.each { |n| parse(n, div) }
204
201
  end
205
202
  end
203
+
204
+ def source_parse(node, out)
205
+ out.div class: "BlockSource" do |d|
206
+ d.p do |p|
207
+ node.children.each { |n| parse(n, p) }
208
+ end
209
+ end
210
+ end
206
211
  end
207
212
  end
208
213
  end
@@ -194,11 +194,12 @@ module IsoDoc
194
194
  end
195
195
 
196
196
  def table_note_cleanup(docxml)
197
- docxml.xpath("//table[div[@class = 'Note' or " \
198
- "@class = 'TableFootnote']]").each do |t|
197
+ docxml.xpath("//table[dl or div[@class = 'Note' or @class = 'BlockSource' " \
198
+ "or @class = 'TableFootnote']]").each do |t|
199
199
  tfoot = table_get_or_make_tfoot(t)
200
200
  insert_here = new_fullcolspan_row(t, tfoot)
201
- t.xpath("div[@class = 'Note' or @class = 'TableFootnote']")
201
+ t.xpath("dl | div[@class = 'Note' or @class = 'BlockSource' or " \
202
+ "@class = 'TableFootnote']")
202
203
  .each do |d|
203
204
  d.parent = insert_here
204
205
  end
@@ -3,7 +3,7 @@ module IsoDoc
3
3
  module Lists
4
4
  def list_title_parse(node, out)
5
5
  name = node.at(ns("./name")) or return
6
- out.p **{ class: "ListTitle" } do |p|
6
+ out.p class: "ListTitle" do |p|
7
7
  name&.children&.each { |n| parse(n, p) }
8
8
  end
9
9
  end
@@ -61,10 +61,10 @@ module IsoDoc
61
61
  def li_parse(node, out)
62
62
  out.li **attr_code(id: node["id"]) do |li|
63
63
  if node["uncheckedcheckbox"] == "true"
64
- li << '<span class="zzMoveToFollowing">'\
64
+ li << '<span class="zzMoveToFollowing">' \
65
65
  '<input type="checkbox" checked="checked"/></span>'
66
66
  elsif node["checkedcheckbox"] == "true"
67
- li << '<span class="zzMoveToFollowing">'\
67
+ li << '<span class="zzMoveToFollowing">' \
68
68
  '<input type="checkbox"/></span>'
69
69
  end
70
70
  node.children.each { |n| parse(n, li) }
@@ -4,7 +4,7 @@ module IsoDoc
4
4
  def recommendation_name(name, out)
5
5
  return if name.nil?
6
6
 
7
- out.p **{ class: "RecommendationTitle" } do |p|
7
+ out.p class: "RecommendationTitle" do |p|
8
8
  name.children.each { |n| parse(n, p) }
9
9
  end
10
10
  end
@@ -38,8 +38,7 @@ module IsoDoc
38
38
  out.div **attr_code(annex_attrs(c)) do |s|
39
39
  c.elements.each do |c1|
40
40
  if c1.name == "title" then annex_name(c, c1, s)
41
- else
42
- parse(c1, s)
41
+ else parse(c1, s)
43
42
  end
44
43
  end
45
44
  end
@@ -20,10 +20,11 @@ module IsoDoc
20
20
  end
21
21
 
22
22
  def tbody_parse(node, table)
23
- tbody = node.at(ns("./tbody")) || return
23
+ tbody = node.at(ns("./tbody")) or return
24
+ rowcount = tbody.xpath(ns("./tr")).size
24
25
  table.tbody do |h|
25
26
  tbody.element_children.each_with_index do |n, i|
26
- tr_parse(n, h, i, tbody.xpath(ns("./tr")).size, false)
27
+ tr_parse(n, h, i, rowcount, false)
27
28
  end
28
29
  end
29
30
  end
@@ -76,12 +77,17 @@ module IsoDoc
76
77
  table_title_parse(node, out)
77
78
  out.table **table_attrs(node) do |t|
78
79
  table_parse_core(node, t)
79
- (dl = node.at(ns("./dl"))) && parse(dl, out)
80
- node.xpath(ns("./note")).each { |n| parse(n, out) }
80
+ table_parse_tail(node, t)
81
81
  end
82
82
  @in_table = false
83
83
  end
84
84
 
85
+ def table_parse_tail(node, out)
86
+ (dl = node.at(ns("./dl"))) && parse(dl, out)
87
+ node.xpath(ns("./source")).each { |n| parse(n, out) }
88
+ node.xpath(ns("./note")).each { |n| parse(n, out) }
89
+ end
90
+
85
91
  def table_parse_core(node, out)
86
92
  tcaption(node, out)
87
93
  colgroup(node, out)
@@ -11,20 +11,19 @@ module IsoDoc
11
11
  end
12
12
 
13
13
  def deprecated_term_parse(node, out)
14
- out.p **{ class: "DeprecatedTerms", style: "text-align:left;" } do |p|
15
- p << l10n("#{@i18n.deprecated}: ")
14
+ out.p class: "DeprecatedTerms", style: "text-align:left;" do |p|
16
15
  node.children.each { |c| parse(c, p) }
17
16
  end
18
17
  end
19
18
 
20
19
  def admitted_term_parse(node, out)
21
- out.p **{ class: "AltTerms", style: "text-align:left;" } do |p|
20
+ out.p class: "AltTerms", style: "text-align:left;" do |p|
22
21
  node.children.each { |c| parse(c, p) }
23
22
  end
24
23
  end
25
24
 
26
25
  def term_parse(node, out)
27
- out.p **{ class: "Terms", style: "text-align:left;" } do |p|
26
+ out.p class: "Terms", style: "text-align:left;" do |p|
28
27
  node.children.each { |c| parse(c, p) }
29
28
  end
30
29
  end
@@ -63,7 +62,7 @@ module IsoDoc
63
62
 
64
63
  def termdef_parse(node, out)
65
64
  name = node&.at(ns("./name"))&.remove
66
- out.p **{ class: "TermNum", id: node["id"] } do |p|
65
+ out.p class: "TermNum", id: node["id"] do |p|
67
66
  name&.children&.each { |n| parse(n, p) }
68
67
  end
69
68
  set_termdomain("")
@@ -176,6 +176,7 @@ module IsoDoc
176
176
  when "fn" then footnote_parse(node, out)
177
177
  when "p" then para_parse(node, out)
178
178
  when "quote" then quote_parse(node, out)
179
+ when "source" then source_parse(node, out)
179
180
  when "tr" then tr_parse(node, out)
180
181
  when "note" then note_parse(node, out)
181
182
  when "review" then review_note_parse(node, out)
@@ -205,11 +206,6 @@ module IsoDoc
205
206
  when "recommendation" then recommendation_parse(node, out)
206
207
  when "permission" then permission_parse(node, out)
207
208
  when "div" then div_parse(node, out)
208
- # when "subject", "classification"
209
- # requirement_skip_parse(node, out)
210
- # when "inherit", "description", "specification", "measurement-target",
211
- # "verification", "import", "component"
212
- # requirement_component_parse(node, out)
213
209
  when "index" then index_parse(node, out)
214
210
  when "index-xref" then index_xref_parse(node, out)
215
211
  when "termref" then termrefelem_parse(node, out)
@@ -96,6 +96,7 @@ module IsoDoc
96
96
  out.send tag, **attr do |div|
97
97
  sourcecode_parse1(node, div)
98
98
  end
99
+ annotation_parse(node, out)
99
100
  sourcecode_name_parse(node, out, name)
100
101
  end
101
102
 
data/lib/isodoc/i18n.rb CHANGED
@@ -9,7 +9,7 @@ module IsoDoc
9
9
 
10
10
  def load_yaml1(lang, script)
11
11
  case lang
12
- when "en", "fr", "ru", "de", "es", "ar"
12
+ when "en", "fr", "ru", "de", "es", "ar", "ja"
13
13
  load_yaml2(lang)
14
14
  when "zh"
15
15
  if script == "Hans" then load_yaml2("zh-Hans")
data/lib/isodoc/init.rb CHANGED
@@ -26,5 +26,108 @@ module IsoDoc
26
26
  n = docxml.at(ns(x.sub(/TOC/, "HTML TOC"))) and
27
27
  @htmlToClevels = n.text.to_i
28
28
  end
29
+
30
+ def options_preprocess(options)
31
+ options.merge!(default_fonts(options)) do |_, old, new|
32
+ old || new
33
+ end.merge!(default_file_locations(options)) do |_, old, new|
34
+ old || new
35
+ end
36
+ options
37
+ end
38
+
39
+ def init_rendering(options)
40
+ @ulstyle = options[:ulstyle]
41
+ @olstyle = options[:olstyle]
42
+ @datauriimage = options[:datauriimage]
43
+ @suppressheadingnumbers = options[:suppressheadingnumbers]
44
+ @break_up_urls_in_tables = options[:breakupurlsintables]
45
+ @suppressasciimathdup = options[:suppressasciimathdup]
46
+ @aligncrosselements = options[:aligncrosselements]
47
+ @modspecidentifierbase = options[:modspecidentifierbase]
48
+ @sourcehighlighter = options[:sourcehighlighter]
49
+ end
50
+
51
+ def init_arrangement(options)
52
+ @sectionsplit = options[:sectionsplit] == "true"
53
+ @bare = options[:bare]
54
+ @semantic_xml_insert = options[:semanticxmlinsert] != "false"
55
+ end
56
+
57
+ def init_i18n(options)
58
+ @i18nyaml = options[:i18nyaml]
59
+ @lang = options[:language] || "en"
60
+ @script = options[:script] || "Latn"
61
+ @locale = options[:locale]
62
+ @localizenumber = options[:localizenumber]
63
+ end
64
+
65
+ def init_locations(options)
66
+ @libdir ||= File.dirname(__FILE__)
67
+ @baseassetpath = options[:baseassetpath]
68
+ @tmpimagedir_suffix = tmpimagedir_suffix
69
+ @tmpfilesdir_suffix = tmpfilesdir_suffix
70
+ @sourcefilename = options[:sourcefilename]
71
+ @files_to_delete = []
72
+ @tempfile_cache = []
73
+ end
74
+
75
+ def init_processing
76
+ @termdomain = ""
77
+ @termexample = false
78
+ @note = false
79
+ @sourcecode = false
80
+ @footnotes = []
81
+ @comments = []
82
+ @in_footnote = false
83
+ @in_comment = false
84
+ @in_table = false
85
+ @in_figure = false
86
+ @seen_footnote = Set.new
87
+ @c = HTMLEntities.new
88
+ @openmathdelim = "`"
89
+ @closemathdelim = "`"
90
+ @maxwidth = 1200
91
+ @maxheight = 800
92
+ @bookmarks_allocated = { "X" => true }
93
+ @fn_bookmarks = {}
94
+ end
95
+
96
+ def init_fonts(options)
97
+ @normalfontsize = options[:normalfontsize]
98
+ @smallerfontsize = options[:smallerfontsize]
99
+ @monospacefontsize = options[:monospacefontsize]
100
+ @footnotefontsize = options[:footnotefontsize]
101
+ @fontist_fonts = options[:fonts]
102
+ @fontlicenseagreement = options[:fontlicenseagreement]
103
+ end
104
+
105
+ def init_covers(options)
106
+ @header = options[:header]
107
+ @htmlcoverpage = options[:htmlcoverpage]
108
+ @wordcoverpage = options[:wordcoverpage]
109
+ @htmlintropage = options[:htmlintropage]
110
+ @wordintropage = options[:wordintropage]
111
+ @scripts = options[:scripts] ||
112
+ File.join(File.dirname(__FILE__), "base_style", "scripts.html")
113
+ @scripts_pdf = options[:scripts_pdf]
114
+ @scripts_override = options[:scripts_override]
115
+ end
116
+
117
+ def init_stylesheets(options)
118
+ @htmlstylesheet_name = options[:htmlstylesheet]
119
+ @wordstylesheet_name = options[:wordstylesheet]
120
+ @htmlstylesheet_override_name = options[:htmlstylesheet_override]
121
+ @wordstylesheet_override_name = options[:wordstylesheet_override]
122
+ @standardstylesheet_name = options[:standardstylesheet]
123
+ end
124
+
125
+ def init_toc(options)
126
+ @htmlToClevels = 2
127
+ @wordToClevels = 2
128
+ @tocfigures = options[:tocfigures]
129
+ @toctables = options[:toctables]
130
+ @tocrecommendations = options[:tocrecommendations]
131
+ end
29
132
  end
30
133
  end
@@ -5,6 +5,7 @@ module IsoDoc
5
5
  def bibdata(docxml)
6
6
  toc_metadata(docxml)
7
7
  fonts_metadata(docxml)
8
+ preprocess_xslt_insert(docxml)
8
9
  docid_prefixes(docxml)
9
10
  a = bibdata_current(docxml) or return
10
11
  address_precompose(a)
@@ -14,11 +15,30 @@ module IsoDoc
14
15
  "</localized-strings>"
15
16
  end
16
17
 
18
+ def extension_insert(docxml, path = [])
19
+ ins = docxml.at(ns("//metanorma-extension")) ||
20
+ docxml.at(ns("//bibdata")).after("<metanorma-extension/>").next_element
21
+ path.each do |n|
22
+ ins = ins.at(ns("./#{n}")) || ins.add_child("<#{n}/>").first
23
+ end
24
+ ins
25
+ end
26
+
27
+ def preprocess_xslt_insert(docxml)
28
+ content = preprocess_xslt_read or return
29
+ ins = extension_insert(docxml, %w(render))
30
+ ins << File.read(content)
31
+ end
32
+
33
+ # read in from file, but with `<preprocess-xslt @format="">` wrapper
34
+ def preprocess_xslt_read
35
+ html_doc_path("preprocess.xslt")
36
+ end
37
+
17
38
  def toc_metadata(docxml)
18
39
  return unless @tocfigures || @toctables || @tocrecommendations
19
40
 
20
- ins = docxml.at(ns("//metanorma-extension")) ||
21
- docxml.at(ns("//bibdata")).after("<metanorma-extension/>").next_element
41
+ ins = extension_insert(docxml)
22
42
  @tocfigures and
23
43
  ins << "<toc type='figure'><title>#{@i18n.toc_figures}</title></toc>"
24
44
  @toctables and
@@ -178,5 +178,32 @@ module IsoDoc
178
178
  node.replace(@reqt_models.model(node["model"])
179
179
  .requirement_render1(node))
180
180
  end
181
+
182
+ def source(docxml)
183
+ docxml.xpath(ns("//source/modification")).each do |f|
184
+ source_modification(f)
185
+ end
186
+ docxml.xpath(ns("//table/source")).each { |f| tablesource(f) }
187
+ docxml.xpath(ns("//figure/source")).each { |f| figuresource(f) }
188
+ end
189
+
190
+ def tablesource(elem)
191
+ source1(elem)
192
+ end
193
+
194
+ def figuresource(elem)
195
+ source1(elem)
196
+ end
197
+
198
+ def source1(elem)
199
+ while elem&.next_element&.name == "source"
200
+ elem << "; #{to_xml(elem.next_element.remove.children)}"
201
+ end
202
+ elem.children = l10n("[#{@i18n.source}: #{to_xml(elem.children).strip}]")
203
+ end
204
+
205
+ def source_modification(mod)
206
+ termsource_modification(mod)
207
+ end
181
208
  end
182
209
  end
@@ -1,6 +1,6 @@
1
1
  require "twitter_cldr"
2
2
  require "bigdecimal"
3
- require "mathml2asciimath"
3
+ require "plurimath"
4
4
 
5
5
  module IsoDoc
6
6
  class PresentationXMLConvert < ::IsoDoc::Convert
@@ -20,7 +20,7 @@ module IsoDoc
20
20
  num = BigDecimal(x.text)
21
21
  precision = /\./.match?(x.text) ? x.text.sub(/^.*\./, "").size : 0
22
22
  x.children = localized_number(num, locale, precision)
23
- rescue ArgumentError => e
23
+ rescue ArgumentError
24
24
  end
25
25
  end
26
26
 
@@ -90,17 +90,34 @@ module IsoDoc
90
90
  end
91
91
 
92
92
  def asciimath_dup(node)
93
- return if @suppressasciimathdup
93
+ return if @suppressasciimathdup || node.parent.at(ns("./asciimath"))
94
+
95
+ math = node.to_xml.gsub(/ xmlns=["'][^"']+["']/, "")
96
+ .gsub(%r{<[^:/>]+:}, "<").gsub(%r{</[^:/>]+:}, "</")
97
+ ret = Plurimath::Math.parse(math, "mathml").to_asciimath
98
+ ret = HTMLEntities.new.encode(ret, :basic)
99
+ node.next = "<asciimath>#{ret}</asciimath>"
100
+ rescue StandardError => e
101
+ warn "Failure to convert MathML to AsciiMath"
102
+ warn node.parent.to_xml
103
+ warn e
104
+ end
94
105
 
95
- a = MathML2AsciiMath.m2a(node.to_xml)
96
- node.next = "<!-- #{a} -->"
106
+ def maths_just_numeral(node)
107
+ mn = node.at("./m:mn", MATHML).children
108
+ if node.parent.name == "stem"
109
+ node.parent.replace(mn)
110
+ else
111
+ node.replace(mn)
112
+ end
97
113
  end
98
114
 
99
115
  def mathml1(node, locale)
100
116
  mathml_style_inherit(node)
101
- asciimath_dup(node)
117
+ justnumeral = node.elements.size == 1 && node.elements.first.name == "mn"
118
+ justnumeral or asciimath_dup(node)
102
119
  localize_maths(node, locale)
103
- mathml_number_to_number(node)
120
+ justnumeral and maths_just_numeral(node)
104
121
  end
105
122
 
106
123
  def mathml_style_inherit(node)