isodoc 1.1.1 → 1.1.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: 0fe7dc7a4c361573ce166000c4b747853185889ed1385f6219da5ecd9bf33b73
4
- data.tar.gz: 2da4bf7a5c8a282bdfee95b96b99322c246712405b429404d5accf3385f9b360
3
+ metadata.gz: 5bd9d095a9d498797d6c48b1465b878f5587107e47f09a76a4148ba3a9618db0
4
+ data.tar.gz: a0825c515977f0ae8fe7047848480d2e2131be9b3baed8c803ae17aedf6270cd
5
5
  SHA512:
6
- metadata.gz: 62e7510c6f20ac7d8773d112bc25957c543097164e3b794dcc05d9b241be70317ea37295e9da8d3fcf61aec5597471091af2912277977db1fa266dd3f5351cae
7
- data.tar.gz: 6c09ae0a60b767cd4d3dd4ce22a6df2609ea8d1a21f29863a5c5ca27283ebe5897f0d530bf89212dc7b8cd4788641f66d04d646a04189f9c3c379e058d3c50c7
6
+ metadata.gz: 23b189ba917e52f1822ad80f096b8abb3fb3eca22e06f860fc300c8f3155492da9a7ef1817a43f6674657456885086ba73c5909d0106cdbbd9efe2392269e408
7
+ data.tar.gz: 2f72ce5902ef2a944f5b49d657e71e0afde82b1d94a2c6e9661d004b54810f7109faa98f2272b651a917da1fbf19e39bd027186e57597b2ae447e8551886e390
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require 'isodoc/gem_tasks'
3
4
 
5
+ IsoDoc::GemTasks.install
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task default: :spec
8
+ task default: :spec
@@ -36,11 +36,11 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "html2doc", "~> 1.0.0"
37
37
  spec.add_dependency "liquid"
38
38
  spec.add_dependency "roman-numerals"
39
- spec.add_dependency "sassc", "~> 2.4.0"
40
39
  spec.add_dependency "metanorma", "~> 1.1.0"
41
40
  spec.add_dependency "rake", "~> 12.0"
42
41
 
43
42
  spec.add_development_dependency "byebug", "~> 9.1"
43
+ spec.add_development_dependency "sassc", "~> 2.4.0"
44
44
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
45
45
  spec.add_development_dependency "guard", "~> 2.14"
46
46
  spec.add_development_dependency "guard-rspec", "~> 4.7"
@@ -28,4 +28,3 @@ br.section
28
28
  br.pagebreak
29
29
  {page-break-before:always;
30
30
  mso-special-character:line-break;}
31
-
@@ -49,9 +49,9 @@ time, mark, audio, video {
49
49
  }
50
50
 
51
51
  html, body, div, span, applet, object, iframe,
52
- p, blockquote,
53
- a, abbr, acronym, address, big, cite,
54
- del, dfn, em, img, ins, q, s,
52
+ p, blockquote,
53
+ a, abbr, acronym, address, big, cite,
54
+ del, dfn, em, img, ins, q, s,
55
55
  small, strike, strong, sub, sup, var,
56
56
  b, u, i, center,
57
57
  dl, dt, dd, ol, ul, li,
@@ -1,7 +1,8 @@
1
- require "isodoc/common"
2
- require "sassc"
3
- require "fileutils"
4
- require "tempfile"
1
+ # frozen_string_literal: true
2
+
3
+ require 'isodoc/common'
4
+ require 'fileutils'
5
+ require 'tempfile'
5
6
 
6
7
  module IsoDoc
7
8
  class Convert < ::IsoDoc::Common
@@ -27,15 +28,25 @@ module IsoDoc
27
28
  # scripts_pdf: Scripts file for PDF
28
29
  # datauriimage: Encode images in HTML output as data URIs
29
30
  def initialize(options)
30
- @libdir = File.dirname(__FILE__) unless @libdir
31
- options.merge!(default_fonts(options)) { |_, old, new| old || new }.
32
- merge!(default_file_locations(options)) { |_, old, new| old || new }
31
+ @libdir ||= File.dirname(__FILE__)
32
+ options.merge!(default_fonts(options)) do |_, old, new|
33
+ old || new
34
+ end
35
+ .merge!(default_file_locations(options)) do |_, old, new|
36
+ old || new
37
+ end
33
38
  @options = options
34
39
  @files_to_delete = []
35
40
  @tempfile_cache = []
36
- @htmlstylesheet_name = options[:htmlstylesheet]
37
- @wordstylesheet_name = options[:wordstylesheet]
38
- @standardstylesheet_name = options[:standardstylesheet]
41
+ @htmlstylesheet_name = precompiled_style_or_original(
42
+ options[:htmlstylesheet]
43
+ )
44
+ @wordstylesheet_name = precompiled_style_or_original(
45
+ options[:wordstylesheet]
46
+ )
47
+ @standardstylesheet_name = precompiled_style_or_original(
48
+ options[:standardstylesheet]
49
+ )
39
50
  @header = options[:header]
40
51
  @htmlcoverpage = options[:htmlcoverpage]
41
52
  @wordcoverpage = options[:wordcoverpage]
@@ -48,8 +59,8 @@ module IsoDoc
48
59
  @olstyle = options[:olstyle]
49
60
  @datauriimage = options[:datauriimage]
50
61
  @suppressheadingnumbers = options[:suppressheadingnumbers]
51
- @break_up_urls_in_tables = options[:break_up_urls_in_tables] == "true"
52
- @termdomain = ""
62
+ @break_up_urls_in_tables = options[:break_up_urls_in_tables] == 'true'
63
+ @termdomain = ''
53
64
  @termexample = false
54
65
  @note = false
55
66
  @sourcecode = false
@@ -61,40 +72,57 @@ module IsoDoc
61
72
  @in_figure = false
62
73
  @seen_footnote = Set.new
63
74
  @c = HTMLEntities.new
64
- @openmathdelim = "`"
65
- @closemathdelim = "`"
66
- @lang = "en"
67
- @script = "Latn"
75
+ @openmathdelim = '`'
76
+ @closemathdelim = '`'
77
+ @lang = 'en'
78
+ @script = 'Latn'
68
79
  @maxwidth = 1200
69
80
  @maxheight = 800
70
81
  @wordToClevels = options[:doctoclevels].to_i
71
- @wordToClevels = 2 if @wordToClevels == 0
82
+ @wordToClevels = 2 if @wordToClevels.zero?
72
83
  @htmlToClevels = options[:htmltoclevels].to_i
73
- @htmlToClevels = 2 if @htmlToClevels == 0
74
- @bookmarks_allocated = {"X" => true}
84
+ @htmlToClevels = 2 if @htmlToClevels.zero?
85
+ @bookmarks_allocated = { 'X' => true }
75
86
  @fn_bookmarks = {}
76
87
  end
77
88
 
89
+ # Check if already compiled version(.css) exists,
90
+ # if not, return original scss file. During release
91
+ # we compile scss into css files in order to not depend on scss
92
+ def precompiled_style_or_original(stylesheet_path)
93
+ # Already have compiled stylesheet, use it
94
+ return stylesheet_path if stylesheet_path.nil? ||
95
+ File.extname(stylesheet_path) == '.css'
96
+
97
+ basename = File.basename(stylesheet_path, '.*')
98
+ compiled_path = File.join(File.dirname(stylesheet_path),
99
+ "#{basename}.css")
100
+ return stylesheet_path unless File.file?(compiled_path)
101
+
102
+ compiled_path
103
+ end
104
+
78
105
  # run this after @meta is populated
79
106
  def populate_css
80
- @htmlstylesheet = generate_css(@htmlstylesheet_name, true, extract_fonts(options))
81
- @wordstylesheet = generate_css(@wordstylesheet_name, false, extract_fonts(options))
82
- @standardstylesheet = generate_css(@standardstylesheet_name, false, extract_fonts(options))
107
+ @htmlstylesheet = generate_css(@htmlstylesheet_name, true)
108
+ @wordstylesheet = generate_css(@wordstylesheet_name, false)
109
+ @standardstylesheet = generate_css(@standardstylesheet_name, false)
83
110
  end
84
111
 
85
112
  def tmpimagedir_suffix
86
- "_images"
113
+ '_images'
87
114
  end
88
115
 
89
116
  def default_fonts(_options)
90
117
  {
91
- bodyfont: "Arial",
92
- headerfont: "Arial",
93
- monospacefont: "Courier",
118
+ bodyfont: 'Arial',
119
+ headerfont: 'Arial',
120
+ monospacefont: 'Courier'
94
121
  }
95
122
  end
96
123
 
97
- # none for this parent gem, but will be populated in child gems which have access to stylesheets &c; e.g.
124
+ # none for this parent gem, but will be populated in child
125
+ # gems which have access to stylesheets &c; e.g.
98
126
  # {
99
127
  # htmlstylesheet: html_doc_path("htmlstyle.scss"),
100
128
  # htmlcoverpage: html_doc_path("html_rsd_titlepage.html"),
@@ -112,30 +140,51 @@ module IsoDoc
112
140
  {}
113
141
  end
114
142
 
115
- # extract fonts for use in generate_css
116
- def extract_fonts(options)
117
- b = options[:bodyfont] || "Arial"
118
- h = options[:headerfont] || "Arial"
119
- m = options[:monospacefont] || "Courier"
143
+ def fonts_options
144
+ {
145
+ 'bodyfont' => options[:bodyfont] || 'Arial',
146
+ 'headerfont' => options[:headerfont] || 'Arial',
147
+ 'monospacefont' => options[:monospacefont] || 'Courier'
148
+ }
149
+ end
150
+
151
+ def scss_fontheader
152
+ b = options[:bodyfont] || 'Arial'
153
+ h = options[:headerfont] || 'Arial'
154
+ m = options[:monospacefont] || 'Courier'
120
155
  "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
121
156
  end
122
157
 
123
158
  def html_doc_path(file)
124
- File.join(@libdir, File.join("html", file))
159
+ File.join(@libdir, File.join('html', file))
160
+ end
161
+
162
+ def convert_scss(filename, stylesheet)
163
+ require 'sassc'
164
+ require 'isodoc/sassc_importer'
165
+
166
+ [File.join(Gem.loaded_specs['isodoc'].full_gem_path,
167
+ 'lib', 'isodoc'),
168
+ File.dirname(filename)].each do |name|
169
+ SassC.load_paths << name
170
+ end
171
+ SassC::Engine.new(scss_fontheader + stylesheet, syntax: :scss,
172
+ importer: SasscImporter)
173
+ .render
125
174
  end
126
175
 
127
- def generate_css(filename, stripwordcss, fontheader)
128
- return nil unless filename
129
- stylesheet = File.read(filename, encoding: "UTF-8")
176
+ def generate_css(filename, stripwordcss)
177
+ return nil if filename.nil?
178
+
179
+ stylesheet = File.read(filename, encoding: 'UTF-8')
130
180
  stylesheet = populate_template(stylesheet, :word)
131
- stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m, "\\1") if stripwordcss
132
- SassC.load_paths << File.join(Gem.loaded_specs['isodoc'].full_gem_path,
133
- "lib", "isodoc")
134
- SassC.load_paths << File.dirname(filename)
135
- engine = SassC::Engine.new(fontheader + stylesheet, syntax: :scss)
136
- Tempfile.open([File.basename(filename, ".*"), "css"],
137
- :encoding => "utf-8") do |f|
138
- f.write(engine.render)
181
+ stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m, '\\1') if stripwordcss
182
+ if File.extname(filename) == '.scss'
183
+ stylesheet = convert_scss(filename, stylesheet)
184
+ end
185
+ Tempfile.open([File.basename(filename, '.*'), 'css'],
186
+ encoding: 'utf-8') do |f|
187
+ f.write(stylesheet)
139
188
  f
140
189
  end
141
190
  end
@@ -143,10 +192,10 @@ module IsoDoc
143
192
  def convert1(docxml, filename, dir)
144
193
  @xrefs.parse docxml
145
194
  noko do |xml|
146
- xml.html **{ lang: "#{@lang}" } do |html|
147
- html.parent.add_namespace("epub", "http://www.idpf.org/2007/ops")
195
+ xml.html **{ lang: @lang.to_s } do |html|
196
+ html.parent.add_namespace('epub', 'http://www.idpf.org/2007/ops')
148
197
  info docxml, nil
149
- populate_css()
198
+ populate_css
150
199
  html.head { |head| define_head head, filename, dir }
151
200
  make_body(html, docxml)
152
201
  end
@@ -164,17 +213,21 @@ module IsoDoc
164
213
  def convert_init(file, input_filename, debug)
165
214
  docxml = Nokogiri::XML(file)
166
215
  filename, dir = init_file(input_filename, debug)
167
- docxml.root.default_namespace = ""
168
- lang = docxml&.at(ns("//bibdata/language"))&.text || @lang
169
- script = docxml&.at(ns("//bibdata/script"))&.text || @script
216
+ docxml.root.default_namespace = ''
217
+ lang = docxml&.at(ns('//bibdata/language'))&.text || @lang
218
+ script = docxml&.at(ns('//bibdata/script'))&.text || @script
170
219
  i18n_init(lang, script)
171
220
  metadata_init(lang, script, @labels)
221
+ @meta.fonts_options = fonts_options
172
222
  xref_init(lang, script, self, @labels, {})
173
223
  [docxml, filename, dir]
174
224
  end
175
225
 
176
- def convert(input_filename, file = nil, debug = false, output_filename = nil)
177
- file = File.read(input_filename, encoding: "utf-8") if file.nil?
226
+ def convert(input_filename,
227
+ file = nil,
228
+ debug = false,
229
+ output_filename = nil)
230
+ file = File.read(input_filename, encoding: 'utf-8') if file.nil?
178
231
  @openmathdelim, @closemathdelim = extract_delims(file)
179
232
  docxml, filename, dir = convert_init(file, input_filename, debug)
180
233
  result = convert1(docxml, filename, dir)
@@ -186,7 +239,7 @@ module IsoDoc
186
239
 
187
240
  def middle_clause
188
241
  "//clause[parent::sections][not(xmlns:title = 'Scope')]"\
189
- "[not(descendant::terms)]".freeze
242
+ '[not(descendant::terms)]'
190
243
  end
191
244
  end
192
245
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module IsoDoc::Function
2
4
  module Utils
3
5
  def date_range(date)
@@ -9,50 +11,50 @@ module IsoDoc::Function
9
11
  end
10
12
 
11
13
  def insert_tab(out, n)
12
- [1..n].each { out << "&nbsp; " }
14
+ [1..n].each { out << '&nbsp; ' }
13
15
  end
14
16
 
15
17
  # add namespaces for Word fragments
16
- NOKOHEAD = <<~HERE.freeze
17
- <!DOCTYPE html SYSTEM
18
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
19
- <html xmlns="http://www.w3.org/1999/xhtml">
20
- <head> <title></title> <meta charset="UTF-8" /> </head>
21
- <body> </body> </html>
18
+ NOKOHEAD = <<~HERE
19
+ <!DOCTYPE html SYSTEM
20
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
21
+ <html xmlns="http://www.w3.org/1999/xhtml">
22
+ <head> <title></title> <meta charset="UTF-8" /> </head>
23
+ <body> </body> </html>
22
24
  HERE
23
25
 
24
26
  # block for processing XML document fragments as XHTML,
25
27
  # to allow for HTMLentities
26
28
  def noko(&block)
27
29
  doc = ::Nokogiri::XML.parse(NOKOHEAD)
28
- fragment = doc.fragment("")
30
+ fragment = doc.fragment('')
29
31
  ::Nokogiri::XML::Builder.with fragment, &block
30
- fragment.to_xml(encoding: "US-ASCII").lines.map do |l|
31
- l.gsub(/\s*\n/, "")
32
+ fragment.to_xml(encoding: 'US-ASCII').lines.map do |l|
33
+ l.gsub(/\s*\n/, '')
32
34
  end
33
35
  end
34
36
 
35
37
  def attr_code(attributes)
36
38
  attributes = attributes.reject { |_, val| val.nil? }.map
37
39
  attributes.map do |k, v|
38
- [k, (v.is_a? String) ? HTMLEntities.new.decode(v) : v]
40
+ [k, v.is_a?(String) ? HTMLEntities.new.decode(v) : v]
39
41
  end.to_h
40
42
  end
41
43
 
42
44
  DOCTYPE_HDR = '<!DOCTYPE html SYSTEM '\
43
- '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.freeze
45
+ '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
44
46
 
45
47
  def to_xhtml(xml)
46
- xml.gsub!(/<\?xml[^>]*>/, "")
47
- /<!DOCTYPE /.match xml or xml = DOCTYPE_HDR + xml
48
+ xml.gsub!(/<\?xml[^>]*>/, '')
49
+ /<!DOCTYPE /.match(xml) || (xml = DOCTYPE_HDR + xml)
48
50
  xml = xml.split(/(\&[^ \r\n\t#;]+;)/).map do |t|
49
- /^(\&[^ \t\r\n#;]+;)/.match(t) ?
51
+ /^(\&[^ \t\r\n#;]+;)/.match?(t) ?
50
52
  HTMLEntities.new.encode(HTMLEntities.new.decode(t), :hexadecimal) : t
51
- end.join("")
53
+ end.join('')
52
54
  begin
53
- Nokogiri::XML.parse(xml) { |config| config.strict }
55
+ Nokogiri::XML.parse(xml, &:strict)
54
56
  rescue Nokogiri::XML::SyntaxError => e
55
- File.open("#{@filename}.#{@format}.err", "w:UTF-8") { |f| f.write xml }
57
+ File.open("#{@filename}.#{@format}.err", 'w:UTF-8') { |f| f.write xml }
56
58
  abort "Malformed Output XML for #{@format}: #{e} (see #{@filename}.#{@format}.err)"
57
59
  end
58
60
  end
@@ -64,7 +66,7 @@ module IsoDoc::Function
64
66
  end
65
67
 
66
68
  def from_xhtml(xml)
67
- xml.to_xml.sub(%r{ xmlns="http://www.w3.org/1999/xhtml"}, "")
69
+ xml.to_xml.sub(%r{ xmlns="http://www.w3.org/1999/xhtml"}, '')
68
70
  end
69
71
 
70
72
  CLAUSE_ANCESTOR =
@@ -72,7 +74,7 @@ module IsoDoc::Function
72
74
  "local-name() = 'acknowledgements' or local-name() = 'term' or "\
73
75
  "local-name() = 'appendix' or local-name() = 'foreword' or "\
74
76
  "local-name() = 'introduction' or local-name() = 'terms' or "\
75
- "local-name() = 'clause' or local-name() = 'references']/@id".freeze
77
+ "local-name() = 'clause' or local-name() = 'references']/@id"
76
78
 
77
79
  def get_clause_id(node)
78
80
  clause = node.xpath(CLAUSE_ANCESTOR)
@@ -86,7 +88,7 @@ module IsoDoc::Function
86
88
  "local-name() = 'acknowledgements' or local-name() = 'term' or "\
87
89
  "local-name() = 'clause' or local-name() = 'references' or "\
88
90
  "local-name() = 'figure' or local-name() = 'formula' or "\
89
- "local-name() = 'table' or local-name() = 'example']/@id".freeze
91
+ "local-name() = 'table' or local-name() = 'example']/@id"
90
92
 
91
93
  def get_note_container_id(node)
92
94
  container = node.xpath(NOTE_CONTAINER_ANCESTOR)
@@ -94,7 +96,7 @@ module IsoDoc::Function
94
96
  end
95
97
 
96
98
  def sentence_join(array)
97
- return "" if array.nil? || array.empty?
99
+ return '' if array.nil? || array.empty?
98
100
  if array.length == 1 then array[0]
99
101
  else
100
102
  IsoDoc::Function::I18n::l10n("#{array[0..-2].join(', ')} "\
@@ -105,25 +107,25 @@ module IsoDoc::Function
105
107
 
106
108
  # avoid `; avoid {{ (Liquid Templates); avoid [[ (Javascript)
107
109
  def extract_delims(text)
108
- @openmathdelim = "(#("
109
- @closemathdelim = ")#)"
110
+ @openmathdelim = '(#('
111
+ @closemathdelim = ')#)'
110
112
  while text.include?(@openmathdelim) || text.include?(@closemathdelim)
111
- @openmathdelim += "("
112
- @closemathdelim += ")"
113
+ @openmathdelim += '('
114
+ @closemathdelim += ')'
113
115
  end
114
116
  [@openmathdelim, @closemathdelim]
115
117
  end
116
118
 
117
119
  def header_strip(h)
118
- h = h.to_s.gsub(%r{<br\s*/>}, " ").gsub(/<\/?h[123456][^>]*>/, "").
119
- gsub(/<\/?b[^>]*>/, "")
120
+ h = h.to_s.gsub(%r{<br\s*/>}, ' ').gsub(/<\/?h[123456][^>]*>/, '')
121
+ .gsub(/<\/?b[^>]*>/, '')
120
122
  h1 = to_xhtml_fragment(h.dup)
121
123
  h1.traverse do |x|
122
- x.replace(" ") if x.name == "span" && /mso-tab-count/.match(x["style"])
123
- x.remove if x.name == "span" && x["class"] == "MsoCommentReference"
124
- x.remove if x.name == "a" && x["class"] == "FootnoteRef"
125
- x.remove if x.name == "span" && /mso-bookmark/.match(x["style"])
126
- x.replace(x.children) if x.name == "a"
124
+ x.replace(' ') if x.name == 'span' && /mso-tab-count/.match(x['style'])
125
+ x.remove if x.name == 'span' && x['class'] == 'MsoCommentReference'
126
+ x.remove if x.name == 'a' && x['class'] == 'FootnoteRef'
127
+ x.remove if x.name == 'span' && /mso-bookmark/.match(x['style'])
128
+ x.replace(x.children) if x.name == 'a'
127
129
  end
128
130
  from_xhtml(h1)
129
131
  end
@@ -135,9 +137,9 @@ module IsoDoc::Function
135
137
  def liquid(doc)
136
138
  # unescape HTML escapes in doc
137
139
  doc = doc.split(%r<(\{%|%\})>).each_slice(4).map do |a|
138
- a[2] = a[2].gsub(/\&lt;/, "<").gsub(/\&gt;/, ">") if a.size > 2
139
- a.join("")
140
- end.join("")
140
+ a[2] = a[2].gsub(/\&lt;/, '<').gsub(/\&gt;/, '>') if a.size > 2
141
+ a.join('')
142
+ end.join('')
141
143
  Liquid::Template.parse(doc)
142
144
  end
143
145
 
@@ -147,37 +149,41 @@ module IsoDoc::Function
147
149
  end
148
150
 
149
151
  def populate_template(docxml, _format = nil)
150
- meta = @meta.get.merge(@labels || {}).merge(@meta.labels || {})
152
+ meta = @meta
153
+ .get
154
+ .merge(@labels || {})
155
+ .merge(@meta.labels || {})
156
+ .merge(@meta.fonts_options || {})
151
157
  template = liquid(docxml)
152
- template.render(meta.map { |k, v| [k.to_s, empty2nil(v)] }.to_h).
153
- gsub('&lt;', '&#x3c;').gsub('&gt;', '&#x3e;').gsub('&amp;', '&#x26;')
158
+ template.render(meta.map { |k, v| [k.to_s, empty2nil(v)] }.to_h)
159
+ .gsub('&lt;', '&#x3c;').gsub('&gt;', '&#x3e;').gsub('&amp;', '&#x26;')
154
160
  end
155
161
 
156
- def save_dataimage(uri, relative_dir = true)
162
+ def save_dataimage(uri, _relative_dir = true)
157
163
  %r{^data:image/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ uri
158
- imgtype.sub!(/\+[a-z0-9]+$/, "") # svg+xml
159
- imgtype = "png" unless /^[a-z0-9]+$/.match imgtype
160
- Tempfile.open(["image", ".#{imgtype}"]) do |f|
164
+ imgtype.sub!(/\+[a-z0-9]+$/, '') # svg+xml
165
+ imgtype = 'png' unless /^[a-z0-9]+$/.match imgtype
166
+ Tempfile.open(['image', ".#{imgtype}"]) do |f|
161
167
  f.binmode
162
168
  f.write(Base64.strict_decode64(imgdata))
163
- @tempfile_cache << f #persist to the end
169
+ @tempfile_cache << f # persist to the end
164
170
  f.path
165
171
  end
166
172
  end
167
173
 
168
174
  def image_localfile(i)
169
- if /^data:image/.match i["src"]
170
- save_dataimage(i["src"], false)
171
- elsif %r{^([A-Z]:)?/}.match i["src"]
172
- i["src"]
175
+ if /^data:image/.match? i['src']
176
+ save_dataimage(i['src'], false)
177
+ elsif %r{^([A-Z]:)?/}.match? i['src']
178
+ i['src']
173
179
  else
174
- File.join(@localdir, i["src"])
180
+ File.join(@localdir, i['src'])
175
181
  end
176
182
  end
177
183
 
178
184
  def labelled_ancestor(node)
179
- return !node.ancestors("example, requirement, recommendation, permission, "\
180
- "table, figure, sourcecode").empty?
185
+ !node.ancestors('example, requirement, recommendation, permission, '\
186
+ 'table, figure, sourcecode').empty?
181
187
  end
182
188
  end
183
189
  end