isodoc 1.5.5 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +2 -12
  3. data/.hound.yml +3 -1
  4. data/.rubocop.yml +3 -7
  5. data/Gemfile +2 -2
  6. data/Rakefile +2 -2
  7. data/bin/rspec +1 -2
  8. data/isodoc.gemspec +11 -11
  9. data/lib/isodoc-yaml/i18n-ar.yaml +152 -0
  10. data/lib/isodoc-yaml/i18n-de.yaml +149 -0
  11. data/lib/isodoc-yaml/i18n-es.yaml +151 -0
  12. data/lib/isodoc-yaml/i18n-ru.yaml +154 -0
  13. data/lib/isodoc.rb +0 -2
  14. data/lib/isodoc/base_style/all.css +7 -0
  15. data/lib/isodoc/base_style/metanorma_word.css +7 -0
  16. data/lib/isodoc/base_style/metanorma_word.scss +8 -0
  17. data/lib/isodoc/base_style/reset.css +7 -0
  18. data/lib/isodoc/base_style/reset.scss +9 -0
  19. data/lib/isodoc/base_style/scripts.html +187 -0
  20. data/lib/isodoc/class_utils.rb +6 -5
  21. data/lib/isodoc/common.rb +2 -0
  22. data/lib/isodoc/convert.rb +30 -17
  23. data/lib/isodoc/css.rb +43 -34
  24. data/lib/isodoc/function/blocks.rb +21 -4
  25. data/lib/isodoc/function/blocks_example_note.rb +2 -2
  26. data/lib/isodoc/function/cleanup.rb +53 -45
  27. data/lib/isodoc/function/form.rb +51 -0
  28. data/lib/isodoc/function/inline.rb +37 -15
  29. data/lib/isodoc/function/references.rb +55 -42
  30. data/lib/isodoc/function/section.rb +29 -16
  31. data/lib/isodoc/function/table.rb +1 -0
  32. data/lib/isodoc/function/to_word_html.rb +33 -29
  33. data/lib/isodoc/function/utils.rb +180 -159
  34. data/lib/isodoc/gem_tasks.rb +30 -31
  35. data/lib/isodoc/headlesshtml_convert.rb +8 -7
  36. data/lib/isodoc/html_convert.rb +6 -4
  37. data/lib/isodoc/html_function/comments.rb +2 -0
  38. data/lib/isodoc/html_function/footnotes.rb +14 -7
  39. data/lib/isodoc/html_function/form.rb +62 -0
  40. data/lib/isodoc/html_function/html.rb +30 -26
  41. data/lib/isodoc/html_function/postprocess.rb +41 -82
  42. data/lib/isodoc/html_function/postprocess_footnotes.rb +59 -0
  43. data/lib/isodoc/i18n.rb +33 -31
  44. data/lib/isodoc/pdf_convert.rb +12 -16
  45. data/lib/isodoc/presentation_function/bibdata.rb +54 -30
  46. data/lib/isodoc/presentation_function/block.rb +17 -8
  47. data/lib/isodoc/presentation_function/inline.rb +84 -120
  48. data/lib/isodoc/presentation_function/math.rb +84 -0
  49. data/lib/isodoc/presentation_function/section.rb +20 -22
  50. data/lib/isodoc/presentation_xml_convert.rb +2 -1
  51. data/lib/isodoc/sassc_importer.rb +1 -1
  52. data/lib/isodoc/version.rb +1 -1
  53. data/lib/isodoc/word_function/body.rb +28 -24
  54. data/lib/isodoc/word_function/footnotes.rb +22 -15
  55. data/lib/isodoc/word_function/postprocess.rb +50 -36
  56. data/lib/isodoc/xref.rb +9 -10
  57. data/lib/isodoc/xref/xref_counter.rb +32 -17
  58. data/lib/isodoc/xref/xref_gen.rb +33 -21
  59. data/lib/isodoc/xref/xref_gen_seq.rb +60 -35
  60. data/lib/isodoc/xref/xref_sect_gen.rb +37 -35
  61. data/lib/isodoc/xslfo_convert.rb +36 -27
  62. data/spec/assets/scripts_override.html +3 -0
  63. data/spec/isodoc/blocks_spec.rb +2490 -2591
  64. data/spec/isodoc/cleanup_spec.rb +1107 -1109
  65. data/spec/isodoc/footnotes_spec.rb +1 -16
  66. data/spec/isodoc/form_spec.rb +156 -0
  67. data/spec/isodoc/i18n_spec.rb +984 -972
  68. data/spec/isodoc/inline_spec.rb +1129 -912
  69. data/spec/isodoc/lists_spec.rb +316 -315
  70. data/spec/isodoc/postproc_spec.rb +1751 -1540
  71. data/spec/isodoc/presentation_xml_spec.rb +403 -323
  72. data/spec/isodoc/ref_spec.rb +718 -723
  73. data/spec/isodoc/section_spec.rb +910 -902
  74. data/spec/isodoc/table_spec.rb +566 -556
  75. data/spec/isodoc/terms_spec.rb +251 -255
  76. data/spec/isodoc/xref_spec.rb +3041 -2992
  77. data/spec/isodoc/xslfo_convert_spec.rb +39 -0
  78. data/spec/spec_helper.rb +30 -29
  79. metadata +77 -65
@@ -1,5 +1,6 @@
1
1
  require_relative "presentation_function/block"
2
2
  require_relative "presentation_function/inline"
3
+ require_relative "presentation_function/math"
3
4
  require_relative "presentation_function/section"
4
5
  require_relative "presentation_function/bibdata"
5
6
 
@@ -59,7 +60,7 @@ module IsoDoc
59
60
  variant docxml
60
61
  end
61
62
 
62
- def postprocess(result, filename, dir)
63
+ def postprocess(result, filename, _dir)
63
64
  toXML(result, filename)
64
65
  @files_to_delete.each { |f| FileUtils.rm_rf f }
65
66
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'sassc'
3
+ require "sassc"
4
4
 
5
5
  class SasscImporter < SassC::Importer
6
6
  def imports(path, _parent_path)
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "1.5.5".freeze
2
+ VERSION = "1.6.4".freeze
3
3
  end
@@ -1,5 +1,5 @@
1
- require_relative "./table.rb"
2
- require_relative "./inline.rb"
1
+ require_relative "./table"
2
+ require_relative "./inline"
3
3
 
4
4
  module IsoDoc::WordFunction
5
5
  module Body
@@ -71,8 +71,8 @@ module IsoDoc::WordFunction
71
71
  node.xpath(ns("./note")).each { |n| parse(n, out) }
72
72
  end
73
73
 
74
- WORD_DT_ATTRS = {class: @note ? "Note" : nil, align: "left",
75
- style: "margin-left:0pt;text-align:left;"}.freeze
74
+ WORD_DT_ATTRS = { class: @note ? "Note" : nil, align: "left",
75
+ style: "margin-left:0pt;text-align:left;" }.freeze
76
76
 
77
77
  def dt_parse(dt, term)
78
78
  term.p **attr_code(WORD_DT_ATTRS) do |p|
@@ -102,6 +102,7 @@ module IsoDoc::WordFunction
102
102
 
103
103
  def dl_parse_notes(node, v)
104
104
  return if node.elements.reject { |n| dt_dd? n }.empty?
105
+
105
106
  v.tr do |tr|
106
107
  tr.td **{ colspan: 2 } do |td|
107
108
  node.elements.reject { |n| dt_dd? n }.each { |n| parse(n, td) }
@@ -109,19 +110,19 @@ module IsoDoc::WordFunction
109
110
  end
110
111
  end
111
112
 
112
- def figure_get_or_make_dl(t)
113
- dl = t.at(".//table[@class = 'dl']")
113
+ def figure_get_or_make_dl(node)
114
+ dl = node.at(".//table[@class = 'dl']")
114
115
  if dl.nil?
115
- t.add_child("<p><b>#{@i18n.key}</b></p><table class='dl'></table>")
116
- dl = t.at(".//table[@class = 'dl']")
116
+ node.add_child("<p><b>#{@i18n.key}</b></p><table class='dl'></table>")
117
+ dl = node.at(".//table[@class = 'dl']")
117
118
  end
118
119
  dl
119
120
  end
120
121
 
121
- def figure_aside_process(f, aside, key)
122
+ def figure_aside_process(fig, aside, key)
122
123
  # get rid of footnote link, it is in diagram
123
- f&.at("./a[@class='TableFootnoteRef']")&.remove
124
- fnref = f.at(".//span[@class='TableFootnoteRef']/..")
124
+ fig&.at("./a[@class='TableFootnoteRef']")&.remove
125
+ fnref = fig.at(".//span[@class='TableFootnoteRef']/..")
125
126
  tr = key.add_child("<tr></tr>").first
126
127
  dt = tr.add_child("<td valign='top' align='left'></td>").first
127
128
  dd = tr.add_child("<td valign='top'></td>").first
@@ -174,31 +175,32 @@ module IsoDoc::WordFunction
174
175
  attrs[:align] = node["align"] unless node["align"] == "justify"
175
176
  attrs[:style] += "text-align:#{node['align']};"
176
177
  end
177
- attrs[:style] += "#{keep_style(node)}"
178
+ attrs[:style] += keep_style(node).to_s
178
179
  attrs[:style] = nil if attrs[:style].empty?
179
180
  attrs
180
181
  end
181
182
 
182
183
  def example_table_attr(node)
183
184
  super.merge({
184
- style: "mso-table-lspace:15.0cm;margin-left:423.0pt;"\
185
- "mso-table-rspace:15.0cm;margin-right:423.0pt;"\
186
- "mso-table-anchor-horizontal:column;"\
187
- "mso-table-overlap:never;border-collapse:collapse;"\
188
- "#{keep_style(node)}"
189
- })
185
+ style: "mso-table-lspace:15.0cm;margin-left:423.0pt;"\
186
+ "mso-table-rspace:15.0cm;margin-right:423.0pt;"\
187
+ "mso-table-anchor-horizontal:column;"\
188
+ "mso-table-overlap:never;border-collapse:collapse;"\
189
+ "#{keep_style(node)}",
190
+ })
190
191
  end
191
192
 
192
- def formula_where(dl, out)
193
- return unless dl
193
+ def formula_where(deflist, out)
194
+ return unless deflist
195
+
194
196
  out.p { |p| p << @i18n.where }
195
- parse(dl, out)
197
+ parse(deflist, out)
196
198
  out.parent.at("./table")["class"] = "formula_dl"
197
199
  end
198
200
 
199
201
  def formula_parse1(node, out)
200
202
  out.div **attr_code(class: "formula") do |div|
201
- div.p do |p|
203
+ div.p do |_p|
202
204
  parse(node.at(ns("./stem")), div)
203
205
  insert_tab(div, 1)
204
206
  if lbl = node&.at(ns("./name"))&.text
@@ -209,7 +211,7 @@ module IsoDoc::WordFunction
209
211
  end
210
212
 
211
213
  def li_parse(node, out)
212
- out.li **attr_code(id: node["id"]) do |li|
214
+ out.li **attr_code(id: node["id"]) do |li|
213
215
  if node["uncheckedcheckbox"] == "true"
214
216
  li << '<span class="zzMoveToFollowing">&#x2610; </span>'
215
217
  elsif node["checkedcheckbox"] == "true"
@@ -220,7 +222,9 @@ module IsoDoc::WordFunction
220
222
  end
221
223
 
222
224
  def suffix_url(url)
223
- return url if %r{^http[s]?://}.match(url)
225
+ return url if %r{^https?://}.match?(url)
226
+ return url unless File.extname(url).empty?
227
+
224
228
  url.sub(/#{File.extname(url)}$/, ".doc")
225
229
  end
226
230
  end
@@ -2,7 +2,7 @@ module IsoDoc::WordFunction
2
2
  module Footnotes
3
3
  def bookmarkid
4
4
  ret = "X"
5
- until !@bookmarks_allocated[ret] do
5
+ until !@bookmarks_allocated[ret]
6
6
  ret = Random.rand(1000000000)
7
7
  end
8
8
  @bookmarks_allocated[ret] = true
@@ -11,6 +11,7 @@ module IsoDoc::WordFunction
11
11
 
12
12
  def footnotes(div)
13
13
  return if @footnotes.empty?
14
+
14
15
  @footnotes.each { |fn| div.parent << fn }
15
16
  end
16
17
 
@@ -52,6 +53,7 @@ module IsoDoc::WordFunction
52
53
  def get_table_ancestor_id(node)
53
54
  table = node.ancestors("table") || node.ancestors("figure")
54
55
  return UUIDTools::UUID.random_create.to_s if table.empty?
56
+
55
57
  table.last["id"]
56
58
  end
57
59
 
@@ -61,30 +63,34 @@ module IsoDoc::WordFunction
61
63
  make_table_footnote_link(out, tid + fn, fn)
62
64
  # do not output footnote text if we have already seen it for this table
63
65
  return if @seen_footnote.include?(tid + fn)
66
+
64
67
  @in_footnote = true
65
68
  out.aside { |a| a << make_table_footnote_text(node, tid + fn, fn) }
66
69
  @in_footnote = false
67
70
  @seen_footnote << (tid + fn)
68
71
  end
69
72
 
70
- def seen_footnote_parse(node, out, fn)
71
- out.span **{style: "mso-element:field-begin"}
72
- out << " NOTEREF _Ref#{@fn_bookmarks[fn]} \\f \\h"
73
- out.span **{style: "mso-element:field-separator"}
74
- out.span **{class: "MsoFootnoteReference"} do |s|
75
- s << fn
73
+ def seen_footnote_parse(_node, out, footnote)
74
+ out.span **{ style: "mso-element:field-begin" }
75
+ out << " NOTEREF _Ref#{@fn_bookmarks[footnote]} \\f \\h"
76
+ out.span **{ style: "mso-element:field-separator" }
77
+ out.span **{ class: "MsoFootnoteReference" } do |s|
78
+ s << footnote
76
79
  end
77
- out.span **{style: "mso-element:field-end"}
80
+ out.span **{ style: "mso-element:field-end" }
78
81
  end
79
82
 
80
83
  def footnote_parse(node, out)
81
84
  return table_footnote_parse(node, out) if (@in_table || @in_figure) &&
82
- !node.ancestors.map {|m| m.name }.include?("name")
85
+ !node.ancestors.map { |m| m.name }.include?("name")
86
+
83
87
  fn = node["reference"] || UUIDTools::UUID.random_create.to_s
84
88
  return seen_footnote_parse(node, out, fn) if @seen_footnote.include?(fn)
89
+
85
90
  @fn_bookmarks[fn] = bookmarkid
86
- out.span **{style: "mso-bookmark:_Ref#{@fn_bookmarks[fn]}"} do |s|
87
- s.a **{ "class": "FootnoteRef", "epub:type": "footnote", href: "#ftn#{fn}" } do |a|
91
+ out.span **{ style: "mso-bookmark:_Ref#{@fn_bookmarks[fn]}" } do |s|
92
+ s.a **{ "class": "FootnoteRef", "epub:type": "footnote",
93
+ href: "#ftn#{fn}" } do |a|
88
94
  a.sup { |sup| sup << fn }
89
95
  end
90
96
  end
@@ -94,12 +100,13 @@ module IsoDoc::WordFunction
94
100
  @seen_footnote << fn
95
101
  end
96
102
 
97
- def make_footnote(node, fn)
98
- return if @seen_footnote.include?(fn)
103
+ def make_footnote(node, footnote)
104
+ return if @seen_footnote.include?(footnote)
105
+
99
106
  @in_footnote = true
100
- @footnotes << make_generic_footnote_text(node, fn)
107
+ @footnotes << make_generic_footnote_text(node, footnote)
101
108
  @in_footnote = false
102
- @seen_footnote << fn
109
+ @seen_footnote << footnote
103
110
  end
104
111
  end
105
112
  end
@@ -1,17 +1,17 @@
1
1
  require "fileutils"
2
- require_relative "./postprocess_cover.rb"
2
+ require_relative "./postprocess_cover"
3
3
 
4
4
  module IsoDoc::WordFunction
5
5
  module Postprocess
6
6
  # add namespaces for Word fragments
7
7
  WORD_NOKOHEAD = <<~HERE.freeze
8
- <!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
9
- <html xmlns="http://www.w3.org/1999/xhtml"
10
- xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"
11
- xmlns:w="urn:schemas-microsoft-com:office:word"
12
- xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
13
- <head> <title></title> <meta charset="UTF-8" /> </head>
14
- <body> </body> </html>
8
+ <!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
9
+ <html xmlns="http://www.w3.org/1999/xhtml"
10
+ xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"
11
+ xmlns:w="urn:schemas-microsoft-com:office:word"
12
+ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
13
+ <head> <title></title> <meta charset="UTF-8" /> </head>
14
+ <body> </body> </html>
15
15
  HERE
16
16
 
17
17
  def to_word_xhtml_fragment(xml)
@@ -22,7 +22,8 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
22
22
  def table_note_cleanup(docxml)
23
23
  super
24
24
  # preempt html2doc putting MsoNormal there
25
- docxml.xpath("//p[not(self::*[@class])][ancestor::*[@class = 'Note']]").each do |p|
25
+ docxml.xpath("//p[not(self::*[@class])][ancestor::*[@class = 'Note']]")
26
+ .each do |p|
26
27
  p["class"] = "Note"
27
28
  end
28
29
  end
@@ -38,16 +39,21 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
38
39
  def toWord(result, filename, dir, header)
39
40
  result = from_xhtml(word_cleanup(to_xhtml(result)))
40
41
  @wordstylesheet = wordstylesheet_update
41
- Html2Doc.process(result, filename: filename, stylesheet: @wordstylesheet&.path,
42
- header_file: header&.path, dir: dir,
43
- asciimathdelims: [@openmathdelim, @closemathdelim],
44
- liststyles: { ul: @ulstyle, ol: @olstyle })
42
+ Html2Doc.process(
43
+ result,
44
+ filename: filename,
45
+ stylesheet: @wordstylesheet&.path,
46
+ header_file: header&.path, dir: dir,
47
+ asciimathdelims: [@openmathdelim, @closemathdelim],
48
+ liststyles: { ul: @ulstyle, ol: @olstyle }
49
+ )
45
50
  header&.unlink
46
- @wordstylesheet&.unlink if @wordstylesheet&.is_a?(Tempfile)
51
+ @wordstylesheet.unlink if @wordstylesheet.is_a?(Tempfile)
47
52
  end
48
53
 
49
- def wordstylesheet_update()
54
+ def wordstylesheet_update
50
55
  return if @wordstylesheet.nil?
56
+
51
57
  f = File.open(@wordstylesheet.path, "a")
52
58
  @landscapestyle.empty? or f.write(@landscapestyle)
53
59
  if @wordstylesheet_override && @wordstylesheet
@@ -62,7 +68,8 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
62
68
 
63
69
  def word_admonition_images(docxml)
64
70
  docxml.xpath("//div[@class = 'Admonition']//img").each do |i|
65
- i["width"], i["height"] = Html2Doc.image_resize(i, image_localfile(i), @maxheight, 300)
71
+ i["width"], i["height"] =
72
+ Html2Doc.image_resize(i, image_localfile(i), @maxheight, 300)
66
73
  end
67
74
  end
68
75
 
@@ -88,21 +95,23 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
88
95
  cells2d = {}
89
96
  docxml.xpath("//table[colgroup]").each do |t|
90
97
  w = colgroup_widths(t)
91
- t.xpath(".//tr").each_with_index { |tr, r| cells2d[r] = {} }
98
+ t.xpath(".//tr").each_with_index { |_tr, r| cells2d[r] = {} }
92
99
  t.xpath(".//tr").each_with_index do |tr, r|
93
- tr.xpath("./td | ./th").each_with_index do |td, i|
100
+ tr.xpath("./td | ./th").each_with_index do |td, _i|
94
101
  x = 0
95
102
  rs = td&.attr("rowspan")&.to_i || 1
96
103
  cs = td&.attr("colspan")&.to_i || 1
97
- while cells2d[r][x] do
98
- x += 1
104
+ while cells2d[r][x]
105
+ x += 1
99
106
  end
100
- for y2 in r..(r + rs - 1)
101
- for x2 in x..(x + cs - 1)
107
+ (r..(r + rs - 1)).each do |y2|
108
+ (x..(x + cs - 1)).each do |x2|
102
109
  cells2d[y2][x2] = 1
103
110
  end
104
111
  end
105
- width = (x..(x+cs-1)).each_with_object({width: 0}) { |z, m| m[:width] += w[z] }
112
+ width = (x..(x + cs - 1)).each_with_object({ width: 0 }) do |z, m|
113
+ m[:width] += w[z]
114
+ end
106
115
  td["width"] = "#{width[:width]}%"
107
116
  x += cs
108
117
  end
@@ -111,8 +120,8 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
111
120
  end
112
121
 
113
122
  # assume percentages
114
- def colgroup_widths(t)
115
- t.xpath("./colgroup/col").each_with_object([]) do |c, m|
123
+ def colgroup_widths(table)
124
+ table.xpath("./colgroup/col").each_with_object([]) do |c, m|
116
125
  m << c["width"].sub(/%$/, "").to_f
117
126
  end
118
127
  end
@@ -127,12 +136,13 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
127
136
 
128
137
  def style_update(node, css)
129
138
  return unless node
130
- node["style"] = node["style"] ? node["style"].sub(/;?$/, ";#{css}") : css
139
+
140
+ node["style"] = node["style"] ? node["style"].sub(/;?$/, ";#{css}") : css
131
141
  end
132
142
 
133
143
  def word_image_caption(docxml)
134
- docxml.xpath("//p[@class = 'FigureTitle' or @class = 'SourceTitle']").
135
- each do |t|
144
+ docxml.xpath("//p[@class = 'FigureTitle' or @class = 'SourceTitle']")
145
+ .each do |t|
136
146
  if t&.previous_element&.name == "img"
137
147
  img = t.previous_element
138
148
  t.previous_element.swap("<p class=\'figure\'>#{img.to_xml}</p>")
@@ -150,7 +160,8 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
150
160
  xpath.each do |list|
151
161
  (list.xpath(".//li") - list.xpath(".//ol//li | .//ul//li")).each do |l|
152
162
  l.xpath("./p | ./div | ./table").each_with_index do |p, i|
153
- next if i == 0
163
+ next if i.zero?
164
+
154
165
  p.wrap(%{<div class="ListContLevel#{lvl}"/>})
155
166
  end
156
167
  list_add(l.xpath(".//ul") - l.xpath(".//ul//ul | .//ol//ul"), lvl + 1)
@@ -162,20 +173,21 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
162
173
  def word_table_align(docxml)
163
174
  docxml.xpath("//td[@align]/p | //th[@align]/p").each do |p|
164
175
  next if p["align"]
165
- style_update(p, "text-align: #{p.parent["align"]}")
176
+
177
+ style_update(p, "text-align: #{p.parent['align']}")
166
178
  end
167
179
  end
168
180
 
169
181
  def word_table_separator(docxml)
170
182
  docxml.xpath("//p[@class = 'TableTitle']").each do |t|
171
183
  next unless t.children.empty?
184
+
172
185
  t["style"] = t["style"].sub(/;?$/, ";font-size:0pt;")
173
186
  t.children = "&nbsp;"
174
187
  end
175
188
  end
176
189
 
177
- def word_annex_cleanup(docxml)
178
- end
190
+ def word_annex_cleanup(docxml); end
179
191
 
180
192
  def word_example_cleanup(docxml)
181
193
  docxml.xpath("//div[@class = 'example']//p[not(@class)]").each do |p|
@@ -194,19 +206,21 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
194
206
  docxml.xpath("//div[p/br]").each do |d|
195
207
  /^WordSection\d+_\d+$/.match(d["class"]) or next
196
208
  d.elements[0].name == "p" && !d.elements[0].elements.empty? or next
197
- d.elements[0].elements[0].name == "br" && d.elements[0].elements[0]["style"] ==
198
- "mso-special-character:line-break;page-break-before:always" or next
209
+ d.elements[0].elements[0].name == "br" &&
210
+ d.elements[0].elements[0]["style"] ==
211
+ "mso-special-character:line-break;page-break-before:always" or next
199
212
  d.elements[0].remove
200
213
  end
201
214
  end
202
215
 
203
216
  def word_footnote_format(docxml)
204
- # the content is in a[@epub:type = 'footnote']//sup, but in Word,
217
+ # the content is in a[@epub:type = 'footnote']//sup, but in Word,
205
218
  # we need to inject content around the autonumbered footnote reference
206
219
  docxml.xpath("//a[@epub:type = 'footnote']").each do |x|
207
220
  footnote_reference_format(x)
208
221
  end
209
- docxml.xpath("//a[@class = 'TableFootnoteRef'] | //span[@class = 'TableFootnoteRef']").each do |x|
222
+ docxml.xpath("//a[@class = 'TableFootnoteRef'] | "\
223
+ "//span[@class = 'TableFootnoteRef']").each do |x|
210
224
  table_footnote_reference_format(x)
211
225
  end
212
226
  docxml
data/lib/isodoc/xref.rb CHANGED
@@ -11,7 +11,7 @@ module IsoDoc
11
11
  include XrefGen::Blocks
12
12
  include XrefGen::Sections
13
13
 
14
- def initialize(lang, script, klass, i18n, options = {})
14
+ def initialize(lang, script, klass, i18n, options = {})
15
15
  @anchors = {}
16
16
  @lang = lang
17
17
  @script = script
@@ -28,13 +28,12 @@ module IsoDoc
28
28
 
29
29
  def anchor(id, lbl, warning = true)
30
30
  return nil if id.nil? || id.empty?
31
- unless @anchors[id]
32
- if warning
33
- @seen ||= Seen_Anchor.instance
34
- @seen.seen(id) or warn "No label has been processed for ID #{id}"
35
- @seen.add(id)
36
- return "[#{id}]"
37
- end
31
+
32
+ if warning && !@anchors[id]
33
+ @seen ||= Seen_Anchor.instance
34
+ @seen.seen(id) or warn "No label has been processed for ID #{id}"
35
+ @seen.add(id)
36
+ return "[#{id}]"
38
37
  end
39
38
  @anchors.dig(id, lbl)
40
39
  end
@@ -56,8 +55,8 @@ module IsoDoc
56
55
  Common::ns(xpath)
57
56
  end
58
57
 
59
- def l10n(a, lang = @lang, script = @script)
60
- @i18n.l10n(a, lang, script)
58
+ def l10n(text, lang = @lang, script = @script)
59
+ @i18n.l10n(text, lang, script)
61
60
  end
62
61
  end
63
62
  end