isodoc 1.5.4 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -4
  3. data/Gemfile +2 -2
  4. data/Rakefile +2 -2
  5. data/bin/rspec +1 -2
  6. data/isodoc.gemspec +11 -11
  7. data/lib/isodoc-yaml/i18n-ar.yaml +152 -0
  8. data/lib/isodoc-yaml/i18n-de.yaml +149 -0
  9. data/lib/isodoc-yaml/i18n-es.yaml +151 -0
  10. data/lib/isodoc-yaml/i18n-ru.yaml +154 -0
  11. data/lib/isodoc/base_style/all.css +7 -0
  12. data/lib/isodoc/base_style/metanorma_word.css +7 -0
  13. data/lib/isodoc/base_style/metanorma_word.scss +8 -0
  14. data/lib/isodoc/base_style/reset.css +7 -0
  15. data/lib/isodoc/base_style/reset.scss +9 -0
  16. data/lib/isodoc/base_style/scripts.html +187 -0
  17. data/lib/isodoc/class_utils.rb +6 -5
  18. data/lib/isodoc/common.rb +2 -0
  19. data/lib/isodoc/convert.rb +30 -17
  20. data/lib/isodoc/css.rb +42 -28
  21. data/lib/isodoc/function/blocks.rb +21 -4
  22. data/lib/isodoc/function/blocks_example_note.rb +2 -2
  23. data/lib/isodoc/function/cleanup.rb +1 -2
  24. data/lib/isodoc/function/form.rb +51 -0
  25. data/lib/isodoc/function/inline.rb +32 -10
  26. data/lib/isodoc/function/references.rb +55 -42
  27. data/lib/isodoc/function/table.rb +1 -0
  28. data/lib/isodoc/function/to_word_html.rb +29 -28
  29. data/lib/isodoc/function/utils.rb +41 -38
  30. data/lib/isodoc/gem_tasks.rb +30 -31
  31. data/lib/isodoc/html_convert.rb +6 -4
  32. data/lib/isodoc/html_function/form.rb +62 -0
  33. data/lib/isodoc/html_function/postprocess.rb +35 -76
  34. data/lib/isodoc/html_function/postprocess_footnotes.rb +59 -0
  35. data/lib/isodoc/i18n.rb +33 -31
  36. data/lib/isodoc/pdf_convert.rb +1 -3
  37. data/lib/isodoc/presentation_function/bibdata.rb +13 -10
  38. data/lib/isodoc/presentation_function/block.rb +17 -8
  39. data/lib/isodoc/presentation_function/inline.rb +75 -118
  40. data/lib/isodoc/presentation_function/math.rb +84 -0
  41. data/lib/isodoc/presentation_function/section.rb +20 -22
  42. data/lib/isodoc/presentation_xml_convert.rb +2 -1
  43. data/lib/isodoc/sassc_importer.rb +1 -1
  44. data/lib/isodoc/version.rb +1 -1
  45. data/lib/isodoc/word_function/body.rb +28 -24
  46. data/lib/isodoc/word_function/footnotes.rb +22 -15
  47. data/lib/isodoc/word_function/postprocess.rb +16 -6
  48. data/lib/isodoc/xref.rb +10 -11
  49. data/lib/isodoc/xref/xref_counter.rb +32 -17
  50. data/lib/isodoc/xref/xref_gen.rb +45 -32
  51. data/lib/isodoc/xref/xref_sect_gen.rb +33 -31
  52. data/lib/isodoc/xslfo_convert.rb +36 -25
  53. data/spec/assets/html_override.css +1 -0
  54. data/spec/assets/word_override.css +1 -0
  55. data/spec/isodoc/blocks_spec.rb +2518 -2570
  56. data/spec/isodoc/cleanup_spec.rb +1107 -1109
  57. data/spec/isodoc/footnotes_spec.rb +1 -16
  58. data/spec/isodoc/form_spec.rb +156 -0
  59. data/spec/isodoc/i18n_spec.rb +984 -972
  60. data/spec/isodoc/inline_spec.rb +984 -920
  61. data/spec/isodoc/lists_spec.rb +316 -315
  62. data/spec/isodoc/postproc_spec.rb +1692 -1538
  63. data/spec/isodoc/presentation_xml_spec.rb +345 -342
  64. data/spec/isodoc/ref_spec.rb +718 -723
  65. data/spec/isodoc/section_spec.rb +910 -902
  66. data/spec/isodoc/table_spec.rb +566 -556
  67. data/spec/isodoc/terms_spec.rb +252 -256
  68. data/spec/isodoc/xref_spec.rb +3040 -2985
  69. data/spec/isodoc/xslfo_convert_spec.rb +39 -0
  70. data/spec/spec_helper.rb +30 -29
  71. metadata +80 -70
  72. data/.rubocop.ribose.yml +0 -65
  73. data/.rubocop.tb.yml +0 -650
  74. data/lib/twitter-cldr/patch.rb +0 -39
@@ -1,12 +1,12 @@
1
1
  module IsoDoc::Function
2
2
  module References
3
-
4
3
  # This is highly specific to ISO, but it's not a bad precedent for
5
4
  # references anyway; keeping here instead of in IsoDoc::Iso for now
6
- def docid_l10n(x)
7
- return x if x.nil?
8
- x.gsub(/All Parts/i, @i18n.all_parts.downcase) if @i18n.all_parts
9
- x
5
+ def docid_l10n(text)
6
+ return text if text.nil?
7
+
8
+ text.gsub(/All Parts/i, @i18n.all_parts.downcase) if @i18n.all_parts
9
+ text
10
10
  end
11
11
 
12
12
  # TODO generate formatted ref if not present
@@ -16,7 +16,7 @@ module IsoDoc::Function
16
16
  identifiers = render_identifier(ids)
17
17
  if biblio then ref_entry_code(ref, ordinal, identifiers, ids)
18
18
  else
19
- ref << "#{identifiers[0] || identifiers[1]}"
19
+ ref << (identifiers[0] || identifiers[1]).to_s
20
20
  ref << ", #{identifiers[1]}" if identifiers[0] && identifiers[1]
21
21
  end
22
22
  ref << ", " unless biblio && !identifiers[1]
@@ -29,7 +29,7 @@ module IsoDoc::Function
29
29
  identifiers = render_identifier(bibitem_ref_code(b))
30
30
  if biblio then ref_entry_code(ref, ordinal, identifiers, nil)
31
31
  else
32
- ref << "#{identifiers[0] || identifiers[1]}"
32
+ ref << (identifiers[0] || identifiers[1]).to_s
33
33
  ref << ", #{identifiers[1]}" if identifiers[0] && identifiers[1]
34
34
  end
35
35
  date_note_process(b, ref)
@@ -40,9 +40,9 @@ module IsoDoc::Function
40
40
 
41
41
  # if t is just a number, only use that ([1] Non-Standard)
42
42
  # else, use both ordinal, as prefix, and t
43
- def ref_entry_code(r, ordinal, t, id)
43
+ def ref_entry_code(r, ordinal, t, _id)
44
44
  prefix_bracketed_ref(r, t[0] || "[#{ordinal}]")
45
- t[1] and r << "#{t[1]}"
45
+ t[1] and r << (t[1]).to_s
46
46
  end
47
47
 
48
48
  def pref_ref_code(b)
@@ -55,27 +55,36 @@ module IsoDoc::Function
55
55
  id = b.at(ns("./docidentifier[@type = 'metanorma']"))
56
56
  id1 = pref_ref_code(b)
57
57
  id2 = b.at(ns("./docidentifier[@type = 'DOI' or @type = 'ISSN' or "\
58
- "@type = 'ISBN']"))
58
+ "@type = 'ISBN']"))
59
59
  return [id, id1, id2] if id || id1 || id2
60
+
60
61
  id = Nokogiri::XML::Node.new("docidentifier", b.document)
61
62
  id << "(NO ID)"
62
63
  [nil, id, nil]
63
64
  end
64
65
 
65
- def bracket_if_num(x)
66
- return nil if x.nil?
67
- x = x.text.sub(/^\[/, "").sub(/\]$/, "")
68
- return "[#{x}]" if /^\d+$/.match(x)
69
- x
66
+ def bracket_if_num(num)
67
+ return nil if num.nil?
68
+
69
+ num = num.text.sub(/^\[/, "").sub(/\]$/, "")
70
+ return "[#{num}]" if /^\d+$/.match?(num)
71
+
72
+ num
70
73
  end
71
74
 
72
75
  def render_identifier(id)
73
76
  [
74
77
  bracket_if_num(id[0]),
75
- id[1].nil? ? nil :
76
- docid_prefix(id[1]["type"], id[1].text.sub(/^\[/, "").sub(/\]$/, "")),
77
- id[2].nil? ? nil :
78
- docid_prefix(id[2]["type"], id[2].text.sub(/^\[/, "").sub(/\]$/, "")),
78
+ if id[1].nil?
79
+ nil
80
+ else
81
+ docid_prefix(id[1]["type"], id[1].text.sub(/^\[/, "").sub(/\]$/, ""))
82
+ end,
83
+ if id[2].nil?
84
+ nil
85
+ else
86
+ docid_prefix(id[2]["type"], id[2].text.sub(/^\[/, "").sub(/\]$/, ""))
87
+ end,
79
88
  ]
80
89
  end
81
90
 
@@ -87,12 +96,14 @@ module IsoDoc::Function
87
96
 
88
97
  def omit_docid_prefix(prefix)
89
98
  return true if prefix.nil? || prefix.empty?
90
- return %w(ISO IEC IEV ITU W3C metanorma rfc-anchor).include? prefix
99
+
100
+ %w(ISO IEC IEV ITU W3C csd metanorma rfc-anchor).include? prefix
91
101
  end
92
102
 
93
103
  def date_note_process(b, ref)
94
104
  date_note = b.at(ns("./note[@type = 'Unpublished-Status']"))
95
105
  return if date_note.nil?
106
+
96
107
  date_note.children.first.replace("<p>#{date_note.content}</p>")
97
108
  footnote_parse(date_note, ref)
98
109
  end
@@ -101,18 +112,17 @@ module IsoDoc::Function
101
112
  { id: b["id"], class: biblio ? "Biblio" : "NormRef" }
102
113
  end
103
114
 
104
- def iso_title(b)
105
- title = b.at(ns("./title[@language = '#{@lang}' and @type = 'main']")) ||
106
- b.at(ns("./title[@language = '#{@lang}']")) ||
107
- b.at(ns("./title[@type = 'main']")) ||
108
- b.at(ns("./title"))
109
- title
115
+ def iso_title(bib)
116
+ bib.at(ns("./title[@language = '#{@lang}' and @type = 'main']")) ||
117
+ bib.at(ns("./title[@language = '#{@lang}']")) ||
118
+ bib.at(ns("./title[@type = 'main']")) ||
119
+ bib.at(ns("./title"))
110
120
  end
111
121
 
112
122
  # reference not to be rendered because it is deemed implicit
113
123
  # in the standards environment
114
- def implicit_reference(b)
115
- b["hidden"] == "true"
124
+ def implicit_reference(bib)
125
+ bib["hidden"] == "true"
116
126
  end
117
127
 
118
128
  def prefix_bracketed_ref(ref, text)
@@ -120,35 +130,38 @@ module IsoDoc::Function
120
130
  insert_tab(ref, 1)
121
131
  end
122
132
 
123
- def reference_format(b, r)
124
- if ftitle = b.at(ns("./formattedref"))
133
+ def reference_format(bib, r)
134
+ if ftitle = bib.at(ns("./formattedref"))
125
135
  ftitle&.children&.each { |n| parse(n, r) }
126
136
  else
127
- title = iso_title(b)
137
+ title = iso_title(bib)
128
138
  r.i do |i|
129
139
  title&.children&.each { |n| parse(n, i) }
130
140
  end
131
141
  end
132
142
  end
133
143
 
134
- def is_standard(b)
144
+ def is_standard(bib)
135
145
  ret = false
136
- b.xpath(ns("./docidentifier")).each do |id|
146
+ bib.xpath(ns("./docidentifier")).each do |id|
137
147
  next if id["type"].nil? ||
138
148
  %w(metanorma DOI ISSN ISBN).include?(id["type"])
149
+
139
150
  ret = true
140
151
  end
141
152
  ret
142
153
  end
143
154
 
144
- def biblio_list(f, div, biblio)
155
+ def biblio_list(refs, div, biblio)
145
156
  i = 0
146
- f.children.each do |b|
157
+ refs.children.each do |b|
147
158
  if b.name == "bibitem"
148
159
  next if implicit_reference(b)
160
+
149
161
  i += 1
150
- (is_standard(b)) ? std_bibitem_entry(div, b, i, biblio) :
151
- nonstd_bibitem(div, b, i, biblio)
162
+ if is_standard(b) then std_bibitem_entry(div, b, i, biblio)
163
+ else nonstd_bibitem(div, b, i, biblio)
164
+ end
152
165
  else
153
166
  parse(b, div) unless %w(title).include? b.name
154
167
  end
@@ -174,7 +187,7 @@ module IsoDoc::Function
174
187
  num
175
188
  end
176
189
 
177
- def bibliography_xpath
190
+ def bibliography_xpath
178
191
  "//bibliography/clause[.//references]"\
179
192
  "[not(.//references[@normative = 'true'])] | "\
180
193
  "//bibliography/references[@normative = 'false']"
@@ -184,7 +197,7 @@ module IsoDoc::Function
184
197
  f = isoxml.at(ns(bibliography_xpath)) and f["hidden"] != "true" or return
185
198
  page_break(out)
186
199
  out.div do |div|
187
- div.h1 **{class: "Section3"} do |h1|
200
+ div.h1 **{ class: "Section3" } do |h1|
188
201
  f&.at(ns("./title"))&.children&.each { |c2| parse(c2, h1) }
189
202
  end
190
203
  biblio_list(f, div, true)
@@ -193,7 +206,6 @@ module IsoDoc::Function
193
206
 
194
207
  def bibliography_parse(node, out)
195
208
  node["hidden"] != true or return
196
- title = node&.at(ns("./title"))&.text || ""
197
209
  out.div do |div|
198
210
  clause_parse_title(node, div, node.at(ns("./title")), out,
199
211
  { class: "Section3" })
@@ -201,11 +213,12 @@ module IsoDoc::Function
201
213
  end
202
214
  end
203
215
 
204
- def format_ref(ref, prefix, isopub, date, allparts)
216
+ def format_ref(ref, prefix, _isopub, _date, _allparts)
205
217
  ref = docid_prefix(prefix, ref)
206
218
  return "[#{ref}]" if ref && /^\d+$/.match(ref) && !prefix &&
207
219
  !/^\[.*\]$/.match(ref)
208
- ref
220
+
221
+ ref
209
222
  end
210
223
  end
211
224
  end
@@ -51,6 +51,7 @@ module IsoDoc::Function
51
51
 
52
52
  def tcaption(node, t)
53
53
  return unless node["summary"]
54
+
54
55
  t.caption do |c|
55
56
  c.span **{ style: "display:none" } do |s|
56
57
  s << node["summary"]
@@ -18,15 +18,22 @@ module IsoDoc::Function
18
18
 
19
19
  def init_file(filename, debug)
20
20
  filepath = Pathname.new(filename)
21
- filename = filepath.sub_ext('').sub(/\.presentation$/, "").to_s
21
+ filename = filepath.sub_ext("").sub(/\.presentation$/, "").to_s
22
+ dir = init_dir(filename, debug)
23
+ @filename = filename
24
+ @localdir = filepath.parent.to_s + "/"
25
+ @sourcedir = @localdir
26
+ @sourcefilename and @sourcedir = Pathname.new(@sourcefilename).parent.to_s + "/"
27
+ [filename, dir]
28
+ end
29
+
30
+ def init_dir(filename, debug)
22
31
  dir = "#{filename}_files"
23
32
  unless debug
24
- Dir.mkdir(dir, 0777) unless File.exists?(dir)
33
+ Dir.mkdir(dir, 0o777) unless File.exists?(dir)
25
34
  FileUtils.rm_rf "#{dir}/*"
26
35
  end
27
- @filename = filename
28
- @localdir = filepath.parent.to_s + '/'
29
- [filename, dir]
36
+ dir
30
37
  end
31
38
 
32
39
  # tmp image dir is same directory as @filename
@@ -44,15 +51,14 @@ module IsoDoc::Function
44
51
  if @standardstylesheet
45
52
  head.style do |style|
46
53
  @standardstylesheet.open
47
- stylesheet = @standardstylesheet.read.
48
- gsub("FILENAME", File.basename(filename).sub(/\.presentation$/, ""))
54
+ stylesheet = @standardstylesheet.read
49
55
  style.comment "\n#{stylesheet}\n"
50
56
  end
51
57
  end
52
58
  end
53
59
 
54
60
  def body_attr
55
- { lang: "#{@lang}" }
61
+ { lang: @lang.to_s }
56
62
  end
57
63
 
58
64
  def make_body(xml, docxml)
@@ -70,7 +76,7 @@ module IsoDoc::Function
70
76
  section_break(body)
71
77
  end
72
78
 
73
- def make_body2(body, docxml)
79
+ def make_body2(body, _docxml)
74
80
  body.div **{ class: "prefatory-section" } do |div2|
75
81
  div2.p { |p| p << "&nbsp;" } # placeholder
76
82
  end
@@ -109,23 +115,13 @@ module IsoDoc::Function
109
115
  @meta.get
110
116
  end
111
117
 
112
- def middle_title(_isoxml, out)
113
- out.p(**{ class: "zzSTDTitle1" }) { |p| p << @meta.get[:doctitle] }
114
- end
115
-
116
- def middle_admonitions(isoxml, out)
117
- isoxml.xpath(ns("//sections/note | //sections/admonition")).each do |x|
118
- parse(x, out)
119
- end
120
- end
121
-
122
118
  def middle(isoxml, out)
123
119
  middle_title(isoxml, out)
124
120
  middle_admonitions(isoxml, out)
125
121
  i = scope isoxml, out, 0
126
122
  i = norm_ref isoxml, out, i
127
123
  i = terms_defs isoxml, out, i
128
- i = symbols_abbrevs isoxml, out, i
124
+ symbols_abbrevs isoxml, out, i
129
125
  clause isoxml, out
130
126
  annex isoxml, out
131
127
  bibliography isoxml, out
@@ -133,22 +129,20 @@ module IsoDoc::Function
133
129
 
134
130
  def boilerplate(node, out)
135
131
  boilerplate = node.at(ns("//boilerplate")) or return
136
- out.div **{class: "authority"} do |s|
132
+ out.div **{ class: "authority" } do |s|
137
133
  boilerplate.children.each do |n|
138
134
  if n.name == "title"
139
135
  s.h1 do |h|
140
136
  n.children.each { |nn| parse(nn, h) }
141
137
  end
142
- else
143
- parse(n, s)
138
+ else parse(n, s)
144
139
  end
145
140
  end
146
141
  end
147
142
  end
148
143
 
149
144
  def parse(node, out)
150
- if node.text?
151
- text_parse(node, out)
145
+ if node.text? then text_parse(node, out)
152
146
  else
153
147
  case node.name
154
148
  when "em" then em_parse(node, out)
@@ -225,9 +219,16 @@ module IsoDoc::Function
225
219
  when "passthrough" then passthrough_parse(node, out)
226
220
  when "amend" then amend_parse(node, out)
227
221
  when "tab" then clausedelimspace(out) # in Presentation XML only
228
- when "svg" then svg_parse(node, out) # introduced in Presentation XML only
229
- else
230
- error_parse(node, out)
222
+ when "svg" then svg_parse(node, out) # in Presentation XML only
223
+ when "add" then add_parse(node, out)
224
+ when "del" then del_parse(node, out)
225
+ when "form" then form_parse(node, out)
226
+ when "input" then input_parse(node, out)
227
+ when "select" then select_parse(node, out)
228
+ when "label" then label_parse(node, out)
229
+ when "option" then option_parse(node, out)
230
+ when "textarea" then textarea_parse(node, out)
231
+ else error_parse(node, out)
231
232
  end
232
233
  end
233
234
  end
@@ -28,10 +28,10 @@ module IsoDoc::Function
28
28
  # to allow for HTMLentities
29
29
  def noko(&block)
30
30
  doc = ::Nokogiri::XML.parse(NOKOHEAD)
31
- fragment = doc.fragment('')
31
+ fragment = doc.fragment("")
32
32
  ::Nokogiri::XML::Builder.with fragment, &block
33
- fragment.to_xml(encoding: 'US-ASCII').lines.map do |l|
34
- l.gsub(/\s*\n/, '')
33
+ fragment.to_xml(encoding: "US-ASCII").lines.map do |l|
34
+ l.gsub(/\s*\n/, "")
35
35
  end
36
36
  end
37
37
 
@@ -46,17 +46,18 @@ module IsoDoc::Function
46
46
  '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
47
47
 
48
48
  def to_xhtml(xml)
49
- xml.gsub!(/<\?xml[^>]*>/, '')
49
+ xml.gsub!(/<\?xml[^>]*>/, "")
50
50
  /<!DOCTYPE /.match(xml) || (xml = DOCTYPE_HDR + xml)
51
51
  xml = xml.split(/(\&[^ \r\n\t#;]+;)/).map do |t|
52
52
  /^(\&[^ \t\r\n#;]+;)/.match?(t) ?
53
53
  HTMLEntities.new.encode(HTMLEntities.new.decode(t), :hexadecimal) : t
54
- end.join('')
54
+ end.join("")
55
55
  begin
56
56
  Nokogiri::XML.parse(xml, &:strict)
57
57
  rescue Nokogiri::XML::SyntaxError => e
58
- File.open("#{@filename}.#{@format}.err", 'w:UTF-8') { |f| f.write xml }
59
- abort "Malformed Output XML for #{@format}: #{e} (see #{@filename}.#{@format}.err)"
58
+ File.open("#{@filename}.#{@format}.err", "w:UTF-8") { |f| f.write xml }
59
+ abort "Malformed Output XML for #{@format}: #{e} "\
60
+ "(see #{@filename}.#{@format}.err)"
60
61
  end
61
62
  end
62
63
 
@@ -67,11 +68,12 @@ module IsoDoc::Function
67
68
  end
68
69
 
69
70
  def from_xhtml(xml)
70
- xml.to_xml.sub(%r{ xmlns="http://www.w3.org/1999/xhtml"}, '')
71
+ xml.to_xml.sub(%r{ xmlns="http://www.w3.org/1999/xhtml"}, "")
71
72
  end
72
73
 
73
74
  CLAUSE_ANCESTOR =
74
75
  ".//ancestor::*[local-name() = 'annex' or "\
76
+ "local-name() = 'definitions' or "\
75
77
  "local-name() = 'acknowledgements' or local-name() = 'term' or "\
76
78
  "local-name() = 'appendix' or local-name() = 'foreword' or "\
77
79
  "local-name() = 'introduction' or local-name() = 'terms' or "\
@@ -102,31 +104,32 @@ module IsoDoc::Function
102
104
  else
103
105
  @i18n.l10n("#{array[0..-2].join(', ')} "\
104
106
  "#{@i18n.and} #{array.last}",
105
- @lang, @script)
107
+ @lang, @script)
106
108
  end
107
109
  end
108
110
 
109
111
  # avoid `; avoid {{ (Liquid Templates); avoid [[ (Javascript)
110
112
  def extract_delims(text)
111
- @openmathdelim = '(#('
112
- @closemathdelim = ')#)'
113
+ @openmathdelim = "(#("
114
+ @closemathdelim = ")#)"
113
115
  while text.include?(@openmathdelim) || text.include?(@closemathdelim)
114
- @openmathdelim += '('
115
- @closemathdelim += ')'
116
+ @openmathdelim += "("
117
+ @closemathdelim += ")"
116
118
  end
117
119
  [@openmathdelim, @closemathdelim]
118
120
  end
119
121
 
120
122
  def header_strip(h)
121
- h = h.to_s.gsub(%r{<br\s*/>}, ' ').gsub(/<\/?h[123456][^>]*>/, '')
122
- .gsub(/<\/?b[^>]*>/, '')
123
+ h = h.to_s.gsub(%r{<br\s*/>}, " ").gsub(/<\/?h[123456][^>]*>/, "")
124
+ .gsub(/<\/?b[^>]*>/, "")
123
125
  h1 = to_xhtml_fragment(h.dup)
124
126
  h1.traverse do |x|
125
- x.replace(' ') if x.name == 'span' && /mso-tab-count/.match(x['style'])
126
- x.remove if x.name == 'span' && x['class'] == 'MsoCommentReference'
127
- x.remove if x.name == 'a' && x['class'] == 'FootnoteRef'
128
- x.remove if x.name == 'span' && /mso-bookmark/.match(x['style'])
129
- x.replace(x.children) if x.name == 'a'
127
+ x.replace(" ") if x.name == "span" && /mso-tab-count/.match(x["style"])
128
+ x.remove if x.name == "img"
129
+ x.remove if x.name == "span" && x["class"] == "MsoCommentReference"
130
+ x.remove if x.name == "a" && x["class"] == "FootnoteRef"
131
+ x.remove if x.name == "span" && /mso-bookmark/.match(x["style"])
132
+ x.replace(x.children) if x.name == "a"
130
133
  end
131
134
  from_xhtml(h1)
132
135
  end
@@ -138,9 +141,9 @@ module IsoDoc::Function
138
141
  def liquid(doc)
139
142
  # unescape HTML escapes in doc
140
143
  doc = doc.split(%r<(\{%|%\})>).each_slice(4).map do |a|
141
- a[2] = a[2].gsub(/\&lt;/, '<').gsub(/\&gt;/, '>') if a.size > 2
142
- a.join('')
143
- end.join('')
144
+ a[2] = a[2].gsub(/\&lt;/, "<").gsub(/\&gt;/, ">") if a.size > 2
145
+ a.join("")
146
+ end.join("")
144
147
  Liquid::Template.parse(doc)
145
148
  end
146
149
 
@@ -151,20 +154,20 @@ module IsoDoc::Function
151
154
 
152
155
  def populate_template(docxml, _format = nil)
153
156
  meta = @meta
154
- .get
155
- .merge(@labels ? {labels: @labels} : {})
156
- .merge(@meta.labels ? {labels: @meta.labels} : {})
157
- .merge(fonts_options || {})
157
+ .get
158
+ .merge(@labels ? {labels: @labels} : {})
159
+ .merge(@meta.labels ? {labels: @meta.labels} : {})
160
+ .merge(fonts_options || {})
158
161
  template = liquid(docxml)
159
162
  template.render(meta.map { |k, v| [k.to_s, empty2nil(v)] }.to_h)
160
- .gsub('&lt;', '&#x3c;').gsub('&gt;', '&#x3e;').gsub('&amp;', '&#x26;')
163
+ .gsub("&lt;", "&#x3c;").gsub("&gt;", "&#x3e;").gsub("&amp;", "&#x26;")
161
164
  end
162
165
 
163
166
  def save_dataimage(uri, _relative_dir = true)
164
167
  %r{^data:(image|application)/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ uri
165
- imgtype.sub!(/\+[a-z0-9]+$/, '') # svg+xml
166
- imgtype = 'png' unless /^[a-z0-9]+$/.match imgtype
167
- Tempfile.open(['image', ".#{imgtype}"]) do |f|
168
+ imgtype.sub!(/\+[a-z0-9]+$/, "") # svg+xml
169
+ imgtype = "png" unless /^[a-z0-9]+$/.match imgtype
170
+ Tempfile.open(["image", ".#{imgtype}"]) do |f|
168
171
  f.binmode
169
172
  f.write(Base64.strict_decode64(imgdata))
170
173
  @tempfile_cache << f # persist to the end
@@ -173,18 +176,18 @@ module IsoDoc::Function
173
176
  end
174
177
 
175
178
  def image_localfile(i)
176
- if /^data:/.match? i['src']
177
- save_dataimage(i['src'], false)
178
- elsif %r{^([A-Z]:)?/}.match? i['src']
179
- i['src']
179
+ if /^data:/.match? i["src"]
180
+ save_dataimage(i["src"], false)
181
+ elsif %r{^([A-Z]:)?/}.match? i["src"]
182
+ i["src"]
180
183
  else
181
- File.join(@localdir, i['src'])
184
+ File.join(@localdir, i["src"])
182
185
  end
183
186
  end
184
187
 
185
188
  def labelled_ancestor(node)
186
- !node.ancestors('example, requirement, recommendation, permission, '\
187
- 'note, table, figure, sourcecode').empty?
189
+ !node.ancestors("example, requirement, recommendation, permission, "\
190
+ "note, table, figure, sourcecode").empty?
188
191
  end
189
192
  end
190
193
  end