isodoc 2.4.1 → 2.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/isodoc/base_style/all.css +29 -0
  3. data/lib/isodoc/base_style/metanorma_word.css +9 -0
  4. data/lib/isodoc/base_style/metanorma_word.scss +11 -0
  5. data/lib/isodoc/base_style/reset.css +29 -0
  6. data/lib/isodoc/base_style/reset.scss +34 -0
  7. data/lib/isodoc/base_style/rouge.css +39 -0
  8. data/lib/isodoc/base_style/typography.scss +1 -1
  9. data/lib/isodoc/convert.rb +10 -3
  10. data/lib/isodoc/function/blocks.rb +29 -16
  11. data/lib/isodoc/function/inline.rb +13 -13
  12. data/lib/isodoc/function/inline_simple.rb +1 -1
  13. data/lib/isodoc/function/references.rb +17 -38
  14. data/lib/isodoc/function/table.rb +1 -1
  15. data/lib/isodoc/function/to_word_html.rb +0 -4
  16. data/lib/isodoc/function/utils.rb +6 -2
  17. data/lib/isodoc/html_function/html.rb +13 -13
  18. data/lib/isodoc/html_function/postprocess.rb +14 -1
  19. data/lib/isodoc/metadata.rb +1 -1
  20. data/lib/isodoc/presentation_function/bibdata.rb +3 -3
  21. data/lib/isodoc/presentation_function/block.rb +1 -98
  22. data/lib/isodoc/presentation_function/math.rb +15 -4
  23. data/lib/isodoc/presentation_function/sourcecode.rb +122 -0
  24. data/lib/isodoc/presentation_function/terms.rb +14 -27
  25. data/lib/isodoc/presentation_xml_convert.rb +38 -0
  26. data/lib/isodoc/version.rb +1 -1
  27. data/lib/isodoc/word_function/body.rb +19 -19
  28. data/lib/isodoc/word_function/comments.rb +23 -18
  29. data/lib/isodoc/word_function/footnotes.rb +8 -8
  30. data/lib/isodoc/word_function/postprocess.rb +25 -118
  31. data/lib/isodoc/word_function/postprocess_cover.rb +29 -157
  32. data/lib/isodoc/word_function/postprocess_table.rb +85 -0
  33. data/lib/isodoc/word_function/postprocess_toc.rb +165 -0
  34. data/lib/isodoc/word_function/table.rb +34 -15
  35. data/lib/isodoc/xref/xref_gen.rb +2 -4
  36. metadata +6 -2
@@ -7,7 +7,7 @@ module IsoDoc
7
7
  def convert1(docxml, filename, dir)
8
8
  bibitem_lookup(docxml)
9
9
  noko do |xml|
10
- xml.html **{ lang: @lang.to_s } do |html|
10
+ xml.html lang: @lang.to_s do |html|
11
11
  info docxml, nil
12
12
  populate_css
13
13
  html.head { |head| define_head head, filename, dir }
@@ -19,7 +19,7 @@ module IsoDoc
19
19
  def make_body1(body, _docxml)
20
20
  return if @bare
21
21
 
22
- body.div **{ class: "title-section" } do |div1|
22
+ body.div class: "title-section" do |div1|
23
23
  div1.p { |p| p << "&#xa0;" } # placeholder
24
24
  end
25
25
  section_break(body)
@@ -28,14 +28,14 @@ module IsoDoc
28
28
  def make_body2(body, _docxml)
29
29
  return if @bare
30
30
 
31
- body.div **{ class: "prefatory-section" } do |div2|
31
+ body.div class: "prefatory-section" do |div2|
32
32
  div2.p { |p| p << "&#xa0;" } # placeholder
33
33
  end
34
34
  section_break(body)
35
35
  end
36
36
 
37
37
  def make_body3(body, docxml)
38
- body.div **{ class: "main-section" } do |div3|
38
+ body.div class: "main-section" do |div3|
39
39
  boilerplate docxml, div3
40
40
  preface_block docxml, div3
41
41
  abstract docxml, div3
@@ -51,8 +51,8 @@ module IsoDoc
51
51
 
52
52
  def googlefonts
53
53
  <<~HEAD.freeze
54
- <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet">
55
- <link href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,900" rel="stylesheet">
54
+ <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet"/>
55
+ <link href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,900" rel="stylesheet"/>
56
56
  HEAD
57
57
  end
58
58
 
@@ -66,11 +66,11 @@ module IsoDoc
66
66
  <script type="text/javascript">#{toclevel}</script>
67
67
 
68
68
  <!--Google fonts-->
69
- <link rel="preconnect" href="https://fonts.gstatic.com">#{' '}
69
+ <link rel="preconnect" href="https://fonts.gstatic.com"/>
70
70
  #{googlefonts}
71
71
  <!--Font awesome import for the link icon-->
72
- <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous">
73
- <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous">
72
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous"/>
73
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous"/>
74
74
  <style class="anchorjs"></style>
75
75
  HEAD
76
76
  end
@@ -91,10 +91,10 @@ module IsoDoc
91
91
 
92
92
  def sourcecode_parse(node, out)
93
93
  name = node.at(ns("./name"))
94
- out.pre **sourcecode_attrs(node).merge(class: "sourcecode") do |div|
95
- @sourcecode = true unless node.at(ns(".//sourcecode"))
96
- node.children.each { |n| parse(n, div) unless n.name == "name" }
97
- @sourcecode = false
94
+ tag = node.at(ns(".//sourcecode | .//table")) ? "div" : "pre"
95
+ attr = sourcecode_attrs(node).merge(class: "sourcecode")
96
+ out.send tag, **attr do |div|
97
+ sourcecode_parse1(node, div)
98
98
  end
99
99
  sourcecode_name_parse(node, out, name)
100
100
  end
@@ -27,7 +27,20 @@ module IsoDoc
27
27
  def html_cleanup(html)
28
28
  html = term_header(html_footnote_filter(html_preface(htmlstyle(html))))
29
29
  html = footnote_format(footnote_backlinks(html_toc(html)))
30
- mathml(html_list_clean(remove_placeholder_paras(html)))
30
+ html = mathml(html_list_clean(remove_placeholder_paras(html)))
31
+ sourcecode_cleanup(html)
32
+ end
33
+
34
+ def sourcecode_cleanup(html)
35
+ ann = ".//div[@class = 'annotation']"
36
+ html.xpath("//pre[#{ann}] | //div[@class = 'sourcecode'][#{ann}]")
37
+ .each do |p|
38
+ ins = p.after("<pre class='sourcecode'/>").next_element
39
+ p.xpath(ann).each do |d|
40
+ ins << d.remove.children
41
+ end
42
+ end
43
+ html
31
44
  end
32
45
 
33
46
  def remove_placeholder_paras(html)
@@ -170,7 +170,7 @@ module IsoDoc
170
170
  end
171
171
 
172
172
  def code_css(isoxml, _out)
173
- c = isoxml.at(ns("//misc-container/source-highlighter-css")) or return
173
+ c = isoxml.at(ns("//metanorma-extension/source-highlighter-css")) or return
174
174
  set(:code_css, c.text)
175
175
  end
176
176
  end
@@ -17,8 +17,8 @@ module IsoDoc
17
17
  def toc_metadata(docxml)
18
18
  return unless @tocfigures || @toctables || @tocrecommendations
19
19
 
20
- ins = docxml.at(ns("//misc-container")) ||
21
- docxml.at(ns("//bibdata")).after("<misc-container/>").next_element
20
+ ins = docxml.at(ns("//metanorma-extension")) ||
21
+ docxml.at(ns("//bibdata")).after("<metanorma-extension/>").next_element
22
22
  @tocfigures and
23
23
  ins << "<toc type='figure'><title>#{@i18n.toc_figures}</title></toc>"
24
24
  @toctables and
@@ -41,7 +41,7 @@ module IsoDoc
41
41
  return unless @fontist_fonts
42
42
 
43
43
  ins = xmldoc.at(ns("//presentation-metadata")) ||
44
- xmldoc.at(ns("//misc-container")) || xmldoc.at(ns("//bibdata"))
44
+ xmldoc.at(ns("//metanorma-extension")) || xmldoc.at(ns("//bibdata"))
45
45
  CSV.parse_line(@fontist_fonts, col_sep: ";").map(&:strip).each do |f|
46
46
  ins.next = presmeta("fonts", f)
47
47
  end
@@ -1,4 +1,5 @@
1
1
  require_relative "./image"
2
+ require_relative "./sourcecode"
2
3
  require "rouge"
3
4
 
4
5
  module IsoDoc
@@ -26,104 +27,6 @@ module IsoDoc
26
27
  end
27
28
  end
28
29
 
29
- def sourcehighlighter_theme
30
- "igorpro"
31
- end
32
-
33
- def sourcehighlighter_css(docxml)
34
- @sourcehighlighter or return
35
- ins = docxml.at(ns("//misc-container")) ||
36
- docxml.at(ns("//bibdata")).after("<misc-container/>").next_element
37
- x = Rouge::Theme.find(sourcehighlighter_theme)
38
- .render(scope: "sourcecode")
39
- ins << "<source-highlighter-css>#{x}</source-highlighter-css>"
40
- end
41
-
42
- def sourcehighlighter
43
- @sourcehighlighter or return
44
- f = Rouge::Formatters::HTML.new
45
- { formatter: f,
46
- formatter_line: Rouge::Formatters::HTMLTable.new(f, {}) }
47
- end
48
-
49
- def sourcecode(docxml)
50
- sourcehighlighter_css(docxml)
51
- @highlighter = sourcehighlighter
52
- docxml.xpath(ns("//sourcecode")).each do |f|
53
- sourcecode1(f)
54
- end
55
- end
56
-
57
- def sourcecode1(elem)
58
- source_highlight(elem)
59
- source_label(elem)
60
- end
61
-
62
- def source_highlight(elem)
63
- @highlighter or return
64
- markup = source_remove_markup(elem)
65
- p = source_lex(elem)
66
- wrapper, code =
67
- if elem["linenums"] == "true" then sourcecode_table_to_elem(elem, p)
68
- else
69
- r = Nokogiri::XML.fragment(@highlighter[:formatter].format(p))
70
- [r, r]
71
- end
72
- elem.children = source_restore_markup(wrapper, code, markup)
73
- end
74
-
75
- def source_remove_markup(elem)
76
- ret = {}
77
- name = elem.at(ns("./name")) and ret[:name] = name.remove.to_xml
78
- ret[:ann] = elem.xpath(ns("./annotation")).each(&:remove)
79
- ret[:call] = elem.xpath(ns("./callout")).each_with_object([]) do |c, m|
80
- m << { xml: c.remove.to_xml, line: c.line - elem.line }
81
- end
82
- ret
83
- end
84
-
85
- def source_restore_markup(wrapper, code, markup)
86
- text = source_restore_callouts(code, markup[:call])
87
- ret = if code == wrapper
88
- text
89
- else
90
- code.replace(text)
91
- to_xml(wrapper)
92
- end
93
- "#{markup[:name]}#{ret}#{markup[:ann]}"
94
- end
95
-
96
- def source_restore_callouts(code, callouts)
97
- text = to_xml(code)
98
- text.split(/[\n\r]/).each_with_index do |c, i|
99
- while !callouts.empty? && callouts[0][:line] == i
100
- c.sub!(/\s+$/, " #{callouts[0][:xml]} ")
101
- callouts.shift
102
- end
103
- end.join("\n")
104
- end
105
-
106
- def sourcecode_table_to_elem(elem, tokens)
107
- r = Nokogiri::XML(@highlighter[:formatter_line].format(tokens)).root
108
- pre = r.at(".//td[@class = 'rouge-code']/pre")
109
- %w(style).each { |n| elem[n] and pre[n] = elem[n] }
110
- pre.name = "sourcecode"
111
- [r, pre]
112
- end
113
-
114
- def source_lex(elem)
115
- l = (Rouge::Lexer.find(elem["lang"] || "plaintext") ||
116
- Rouge::Lexer.find("plaintext"))
117
- l.lex(@c.decode(elem.children.to_xml))
118
- end
119
-
120
- def source_label(elem)
121
- labelled_ancestor(elem) and return
122
- lbl = @xrefs.anchor(elem["id"], :label, false) or return
123
- prefix_name(elem, block_delim,
124
- l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
125
- end
126
-
127
30
  def formula(docxml)
128
31
  docxml.xpath(ns("//formula")).each { |f| formula1(f) }
129
32
  end
@@ -32,7 +32,7 @@ module IsoDoc
32
32
  return localized unless twitter_cldr_reader_symbols[:decimal]
33
33
 
34
34
  integer, fraction = localized.split(twitter_cldr_reader_symbols[:decimal])
35
- return localized if fraction.nil? || fraction.length.zero?
35
+ return localized if fraction.nil? || fraction.empty?
36
36
 
37
37
  [integer, decorate_fraction_part(fraction, locale)]
38
38
  .join(twitter_cldr_reader_symbols[:decimal])
@@ -97,14 +97,25 @@ module IsoDoc
97
97
  end
98
98
 
99
99
  def mathml1(node, locale)
100
+ mathml_style_inherit(node)
100
101
  asciimath_dup(node)
101
102
  localize_maths(node, locale)
102
- return unless node.elements.size == 1 && node.elements.first.name == "mn"
103
+ mathml_number_to_number(node)
104
+ end
105
+
106
+ def mathml_style_inherit(node)
107
+ node.at("./ancestor::xmlns:strong") or return
108
+ node.children =
109
+ "<mstyle fontweight='bold'>#{node.children.to_xml}</mstyle>"
110
+ end
103
111
 
112
+ def mathml_number_to_number(node)
113
+ (node.elements.size == 1 && node.elements.first.name == "mn") or return
114
+ repl = node.at("./m:mn", MATHML).children
104
115
  if node.parent.name == "stem"
105
- node.parent.replace(node.at("./m:mn", MATHML).children)
116
+ node.parent.replace(repl)
106
117
  else
107
- node.replace(node.at("./m:mn", MATHML).children)
118
+ node.replace(repl)
108
119
  end
109
120
  end
110
121
  end
@@ -0,0 +1,122 @@
1
+ module IsoDoc
2
+ class PresentationXMLConvert < ::IsoDoc::Convert
3
+ def sourcehighlighter_css(docxml)
4
+ @sourcehighlighter or return
5
+ ins = docxml.at(ns("//metanorma-extension")) ||
6
+ docxml.at(ns("//bibdata")).after("<metanorma-extension/>").next_element
7
+ ins << "<source-highlighter-css>#{sourcehighlighter_css_file}" \
8
+ "</source-highlighter-css>"
9
+ end
10
+
11
+ def sourcehighlighter_css_file
12
+ File.read(File.join(File.dirname(__FILE__), "..", "base_style",
13
+ "rouge.css"))
14
+ end
15
+
16
+ def sourcehighlighter
17
+ @sourcehighlighter or return
18
+ Rouge::Formatter.enable_escape!
19
+ f = Rouge::Formatters::HTML.new
20
+ opts = { gutter_class: "rouge-gutter", code_class: "rouge-code" }
21
+ f1 = Rouge::Formatters::HTMLLineTable.new(f, opts)
22
+ { formatter: f, formatter_line: f1 }
23
+ end
24
+
25
+ def sourcecode(docxml)
26
+ sourcehighlighter_css(docxml)
27
+ @highlighter = sourcehighlighter
28
+ docxml.xpath(ns("//sourcecode")).each do |f|
29
+ sourcecode1(f)
30
+ end
31
+ end
32
+
33
+ def sourcecode1(elem)
34
+ source_highlight(elem)
35
+ source_label(elem)
36
+ end
37
+
38
+ def source_highlight(elem)
39
+ @highlighter or return
40
+ markup = source_remove_markup(elem)
41
+ p = source_lex(elem)
42
+ elem.children = if elem["linenums"] == "true"
43
+ r = sourcecode_table_to_elem(elem, p)
44
+ source_restore_markup_table(r, markup)
45
+ else
46
+ r = @highlighter[:formatter].format(p)
47
+ source_restore_markup(Nokogiri::XML.fragment(r), markup)
48
+ end
49
+ end
50
+
51
+ def source_remove_markup(elem)
52
+ ret = {}
53
+ name = elem.at(ns("./name")) and ret[:name] = name.remove.to_xml
54
+ source_remove_annotations(ret, elem)
55
+ ret
56
+ end
57
+
58
+ def source_remove_annotations(ret, elem)
59
+ ret[:ann] = elem.xpath(ns("./annotation")).each(&:remove)
60
+ ret[:call] = elem.xpath(ns("./callout")).each_with_object([]) do |c, m|
61
+ m << { xml: c.remove.to_xml, line: c.line - elem.line }
62
+ end
63
+ ret
64
+ end
65
+
66
+ def source_restore_markup(wrapper, markup)
67
+ ret = source_restore_callouts(wrapper, markup[:call])
68
+ "#{markup[:name]}#{ret}#{markup[:ann]}"
69
+ end
70
+
71
+ def source_restore_markup_table(wrapper, markup)
72
+ source_restore_callouts_table(wrapper, markup[:call])
73
+ ret = to_xml(wrapper)
74
+ "#{markup[:name]}#{ret}#{markup[:ann]}"
75
+ end
76
+
77
+ def source_restore_callouts(code, callouts)
78
+ text = to_xml(code)
79
+ text.split(/[\n\r]/).each_with_index do |c, i|
80
+ while !callouts.empty? && callouts[0][:line] == i
81
+ c.sub!(/\s+$/, " <span class='c'>#{callouts[0][:xml]}</span> ")
82
+ callouts.shift
83
+ end
84
+ end.join("\n")
85
+ end
86
+
87
+ def source_restore_callouts_table(table, callouts)
88
+ table.xpath(".//td[@class = 'rouge-code']/sourcecode")
89
+ .each_with_index do |c, i|
90
+ while !callouts.empty? && callouts[0][:line] == i
91
+ c << " <span class='c'>#{callouts[0][:xml]}</span> "
92
+ callouts.shift
93
+ end
94
+ end
95
+ end
96
+
97
+ def sourcecode_table_to_elem(elem, tokens)
98
+ r = Nokogiri::XML(@highlighter[:formatter_line].format(tokens)).root
99
+ r.xpath(".//td[@class = 'rouge-code']/pre").each do |pre|
100
+ %w(style).each { |n| elem[n] and pre[n] = elem[n] }
101
+ pre.name = "sourcecode"
102
+ pre.children = to_xml(pre.children).sub(/\s+$/, "")
103
+ end
104
+ r
105
+ end
106
+
107
+ def source_lex(elem)
108
+ lexer = (Rouge::Lexer.find(elem["lang"] || "plaintext") ||
109
+ Rouge::Lexer.find("plaintext"))
110
+ l = Rouge::Lexers::Escape.new(start: "{^^{", end: "}^^}", lang: lexer)
111
+ source = to_xml(elem.children).gsub(/</, "{^^{<").gsub(/>/, ">}^^}")
112
+ l.lex(@c.decode(source))
113
+ end
114
+
115
+ def source_label(elem)
116
+ labelled_ancestor(elem) and return
117
+ lbl = @xrefs.anchor(elem["id"], :label, false) or return
118
+ prefix_name(elem, block_delim,
119
+ l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
120
+ end
121
+ end
122
+ end
@@ -46,9 +46,8 @@ module IsoDoc
46
46
  end
47
47
 
48
48
  def concept1_linkmention(ref, renderterm, opts)
49
- return unless opts[:linkmention] == "true" &&
50
- !renderterm.nil? && !ref.nil?
51
-
49
+ (opts[:linkmention] == "true" &&
50
+ !renderterm.nil? && !ref.nil?) or return
52
51
  ref2 = ref.clone
53
52
  r2 = renderterm.clone
54
53
  renderterm.replace(ref2).children = r2
@@ -56,16 +55,14 @@ module IsoDoc
56
55
 
57
56
  def concept1_ref(_node, ref, opts)
58
57
  ref.nil? and return
59
- return ref.remove if opts[:ref] == "false"
60
-
58
+ opts[:ref] == "false" and return ref.remove
61
59
  r = concept1_ref_content(ref)
62
60
  ref = r.at("./descendant-or-self::xmlns:xref | " \
63
61
  "./descendant-or-self::xmlns:eref | " \
64
62
  "./descendant-or-self::xmlns:termref")
65
63
  %w(xref eref).include? ref&.name and get_linkend(ref)
66
- if opts[:linkref] == "false" && %w(xref eref).include?(ref&.name)
64
+ opts[:linkref] == "false" && %w(xref eref).include?(ref&.name) and
67
65
  ref.replace(ref.children)
68
- end
69
66
  end
70
67
 
71
68
  def concept1_ref_content(ref)
@@ -97,9 +94,8 @@ module IsoDoc
97
94
 
98
95
  def designation(docxml)
99
96
  docxml.xpath(ns("//term")).each { |t| merge_second_preferred(t) }
100
- docxml.xpath(ns("//preferred | //admitted | //deprecates")).each do |p|
101
- designation1(p)
102
- end
97
+ docxml.xpath(ns("//preferred | //admitted | //deprecates"))
98
+ .each { |p| designation1(p) }
103
99
  end
104
100
 
105
101
  def merge_second_preferred(term)
@@ -112,11 +108,10 @@ module IsoDoc
112
108
  end
113
109
 
114
110
  def merge_second_preferred1(pref, second)
115
- if merge_preferred_eligible?(pref, second)
116
- n1 = pref.at(ns("./expression/name"))
117
- n2 = second.remove.at(ns("./expression/name"))
118
- n1.children = l10n("#{to_xml(n1.children)}; #{Common::to_xml(n2.children)}")
119
- end
111
+ merge_preferred_eligible?(pref, second) or return
112
+ n1 = pref.at(ns("./expression/name"))
113
+ n2 = second.remove.at(ns("./expression/name"))
114
+ n1.children = l10n("#{to_xml(n1.children)}; #{Common::to_xml(n2.children)}")
120
115
  end
121
116
 
122
117
  def merge_preferred_eligible?(first, second)
@@ -132,7 +127,6 @@ module IsoDoc
132
127
  s = desgn.at(ns("./termsource"))
133
128
  name = desgn.at(ns("./expression/name | ./letter-symbol/name | " \
134
129
  "./graphical-symbol")) or return
135
-
136
130
  designation_annotate(desgn, name)
137
131
  s and desgn.next = s
138
132
  end
@@ -156,8 +150,7 @@ module IsoDoc
156
150
  def designation_field(desgn, name)
157
151
  f = desgn.xpath(ns("./field-of-application | ./usage-info"))
158
152
  &.map { |u| to_xml(u.children) }&.join(", ")
159
- return nil if f&.empty?
160
-
153
+ f&.empty? and return nil
161
154
  name << ", &#x3c;#{f}&#x3e;"
162
155
  end
163
156
 
@@ -178,27 +171,21 @@ module IsoDoc
178
171
  loc = [desgn&.at(ns("./expression/@language"))&.text,
179
172
  desgn&.at(ns("./expression/@script"))&.text,
180
173
  desgn&.at(ns("./@geographic-area"))&.text].compact
181
- return if loc.empty?
182
-
174
+ loc.empty? and return
183
175
  name << ", #{loc.join(' ')}"
184
176
  end
185
177
 
186
178
  def designation_pronunciation(desgn, name)
187
179
  f = desgn.at(ns("./expression/pronunciation")) or return
188
-
189
180
  name << ", /#{to_xml(f.children)}/"
190
181
  end
191
182
 
192
183
  def termexample(docxml)
193
- docxml.xpath(ns("//termexample")).each do |f|
194
- example1(f)
195
- end
184
+ docxml.xpath(ns("//termexample")).each { |f| example1(f) }
196
185
  end
197
186
 
198
187
  def termnote(docxml)
199
- docxml.xpath(ns("//termnote")).each do |f|
200
- termnote1(f)
201
- end
188
+ docxml.xpath(ns("//termnote")).each { |f| termnote1(f) }
202
189
  end
203
190
 
204
191
  def termnote1(elem)
@@ -24,6 +24,7 @@ module IsoDoc
24
24
  end
25
25
 
26
26
  def conversions(docxml)
27
+ semantic_xml_insert(docxml)
27
28
  bibdata docxml
28
29
  @xrefs.parse docxml
29
30
  section docxml
@@ -84,6 +85,43 @@ module IsoDoc
84
85
  related docxml
85
86
  end
86
87
 
88
+ def semantic_xml_insert(xml)
89
+ @semantic_xml_insert or return
90
+ embed = to_xml(embedable_semantic_xml(xml))
91
+ ins = metanorma_extension_insert_pt(xml)
92
+ ins = ins.at(ns("./metanorma")) || ins.add_child("<metanorma/>").first
93
+ ins << "<source>#{embed}</source>"
94
+ end
95
+
96
+ def metanorma_extension_insert_pt(xml)
97
+ xml.at(ns("//metanorma-extension")) ||
98
+ xml.at(ns("//bibdata"))&.after("<metanorma-extension/>")
99
+ &.next_element ||
100
+ xml.root.elements.first.before("<metanorma-extension/>")
101
+ .previous_element
102
+ end
103
+
104
+ def embedable_semantic_xml(xml)
105
+ xml = embedable_semantic_xml_tags(xml)
106
+ embedable_semantic_xml_attributes(xml)
107
+ end
108
+
109
+ def embedable_semantic_xml_tags(xml)
110
+ Nokogiri::XML(to_xml(xml).gsub(%r{(</?)([[:alpha:]])},
111
+ "\\1semantic__\\2")).root
112
+ end
113
+
114
+ def embedable_semantic_xml_attributes(xml)
115
+ Metanorma::Utils::anchor_attributes.each do |(tag_name, attr_name)|
116
+ tag_name == "*" or tag_name = "semantic__#{tag_name}"
117
+ xml.xpath(ns("//#{tag_name}[@#{attr_name}]")).each do |elem|
118
+ elem.attributes[attr_name].value =
119
+ "semantic__#{elem.attributes[attr_name].value}"
120
+ end
121
+ end
122
+ xml
123
+ end
124
+
87
125
  def postprocess(result, filename, _dir)
88
126
  to_xml_file(result, filename)
89
127
  @files_to_delete.each { |f| FileUtils.rm_rf f }
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.4.1".freeze
2
+ VERSION = "2.4.3".freeze
3
3
  end
@@ -19,14 +19,14 @@ module IsoDoc
19
19
  end
20
20
 
21
21
  def make_body1(body, _docxml)
22
- body.div **{ class: "WordSection1" } do |div1|
22
+ body.div class: "WordSection1" do |div1|
23
23
  div1.p { |p| p << "&#xa0;" } # placeholder
24
24
  end
25
25
  section_break(body)
26
26
  end
27
27
 
28
28
  def make_body2(body, docxml)
29
- body.div **{ class: "WordSection2" } do |div2|
29
+ body.div class: "WordSection2" do |div2|
30
30
  boilerplate docxml, div2
31
31
  preface_block docxml, div2
32
32
  abstract docxml, div2
@@ -40,7 +40,7 @@ module IsoDoc
40
40
  end
41
41
 
42
42
  def make_body3(body, docxml)
43
- body.div **{ class: "WordSection3" } do |div3|
43
+ body.div class: "WordSection3" do |div3|
44
44
  middle docxml, div3
45
45
  footnotes div3
46
46
  comments div3
@@ -93,7 +93,7 @@ module IsoDoc
93
93
 
94
94
  def dl_parse_table(node, out)
95
95
  list_title_parse(node, out)
96
- out.table **{ class: "dl" } do |v|
96
+ out.table class: "dl" do |v|
97
97
  node.elements.select { |n| dt_dd?(n) }
98
98
  .each_slice(2) do |dt, dd|
99
99
  dl_parse_table1(v, dt, dd)
@@ -104,10 +104,10 @@ module IsoDoc
104
104
 
105
105
  def dl_parse_table1(table, dterm, ddefn)
106
106
  table.tr do |tr|
107
- tr.td **{ valign: "top", align: "left" } do |term|
107
+ tr.td valign: "top", align: "left" do |term|
108
108
  dt_parse(dterm, term)
109
109
  end
110
- tr.td **{ valign: "top" } do |listitem|
110
+ tr.td valign: "top" do |listitem|
111
111
  ddefn.children.each { |n| parse(n, listitem) }
112
112
  end
113
113
  end
@@ -118,7 +118,7 @@ module IsoDoc
118
118
  return if remainder.empty?
119
119
 
120
120
  out.tr do |tr|
121
- tr.td **{ colspan: 2 } do |td|
121
+ tr.td colspan: 2 do |td|
122
122
  remainder.each { |n| parse(n, td) }
123
123
  end
124
124
  end
@@ -149,8 +149,8 @@ module IsoDoc
149
149
 
150
150
  def note_p_parse(node, div)
151
151
  name = node&.at(ns("./name"))&.remove
152
- div.p **{ class: "Note" } do |p|
153
- p.span **{ class: "note_label" } do |s|
152
+ div.p class: "Note" do |p|
153
+ p.span class: "note_label" do |s|
154
154
  name&.children&.each { |n| parse(n, s) }
155
155
  end
156
156
  insert_tab(p, 1)
@@ -161,8 +161,8 @@ module IsoDoc
161
161
 
162
162
  def note_parse1(node, div)
163
163
  name = node&.at(ns("./name"))&.remove
164
- div.p **{ class: "Note" } do |p|
165
- p.span **{ class: "note_label" } do |s|
164
+ div.p class: "Note" do |p|
165
+ p.span class: "note_label" do |s|
166
166
  name&.children&.each { |n| parse(n, s) }
167
167
  end
168
168
  insert_tab(p, 1)
@@ -173,7 +173,7 @@ module IsoDoc
173
173
  def termnote_parse(node, out)
174
174
  name = node&.at(ns("./name"))&.remove
175
175
  out.div **note_attrs(node) do |div|
176
- div.p **{ class: "Note" } do |p|
176
+ div.p class: "Note" do |p|
177
177
  if name
178
178
  name.children.each { |n| parse(n, p) }
179
179
  p << termnote_delim
@@ -196,10 +196,10 @@ module IsoDoc
196
196
 
197
197
  def example_table_attr(node)
198
198
  super.merge(
199
- style: "mso-table-lspace:15.0cm;margin-left:423.0pt;"\
200
- "mso-table-rspace:15.0cm;margin-right:423.0pt;"\
201
- "mso-table-anchor-horizontal:column;"\
202
- "mso-table-overlap:never;border-collapse:collapse;"\
199
+ style: "mso-table-lspace:15.0cm;margin-left:423.0pt;" \
200
+ "mso-table-rspace:15.0cm;margin-right:423.0pt;" \
201
+ "mso-table-anchor-horizontal:column;" \
202
+ "mso-table-overlap:never;border-collapse:collapse;" \
203
203
  "#{keep_style(node)}",
204
204
  )
205
205
  end
@@ -244,11 +244,11 @@ module IsoDoc
244
244
 
245
245
  def info(isoxml, out)
246
246
  @tocfigurestitle =
247
- isoxml&.at(ns("//misc-container/toc[@type = 'figure']/title"))&.text
247
+ isoxml&.at(ns("//metanorma-extension/toc[@type = 'figure']/title"))&.text
248
248
  @toctablestitle =
249
- isoxml&.at(ns("//misc-container/toc[@type = 'table']/title"))&.text
249
+ isoxml&.at(ns("//metanorma-extension/toc[@type = 'table']/title"))&.text
250
250
  @tocrecommendationstitle = isoxml
251
- &.at(ns("//misc-container/toc[@type = 'recommendation']/title"))&.text
251
+ &.at(ns("//metanorma-extension/toc[@type = 'recommendation']/title"))&.text
252
252
  super
253
253
  end
254
254
  end