reverse_adoc 0.2.4 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +16 -5
  3. data/.github/workflows/ubuntu.yml +18 -5
  4. data/.github/workflows/windows.yml +20 -6
  5. data/Gemfile +2 -2
  6. data/Gemfile.lock +84 -0
  7. data/README.adoc +40 -7
  8. data/Rakefile +1 -1
  9. data/bin/reverse_adoc +24 -17
  10. data/bin/w2a +19 -31
  11. data/lib/reverse_adoc.rb +30 -0
  12. data/lib/{reverse_asciidoctor → reverse_adoc}/cleaner.rb +27 -4
  13. data/lib/{reverse_asciidoctor → reverse_adoc}/config.rb +3 -2
  14. data/lib/{reverse_asciidoctor → reverse_adoc}/converters.rb +6 -6
  15. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/a.rb +7 -3
  16. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/aside.rb +1 -1
  17. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/audio.rb +1 -1
  18. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/base.rb +2 -2
  19. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/blockquote.rb +2 -2
  20. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/br.rb +1 -1
  21. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/bypass.rb +1 -1
  22. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/code.rb +1 -1
  23. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/div.rb +1 -1
  24. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/drop.rb +1 -1
  25. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/em.rb +1 -1
  26. data/lib/reverse_adoc/converters/example.rb +17 -0
  27. data/lib/reverse_adoc/converters/express_ref.rb +12 -0
  28. data/lib/reverse_adoc/converters/ext_description.rb +16 -0
  29. data/lib/reverse_adoc/converters/ext_descriptions.rb +12 -0
  30. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/figure.rb +1 -1
  31. data/lib/reverse_adoc/converters/h.rb +34 -0
  32. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/head.rb +1 -1
  33. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/hr.rb +1 -1
  34. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/ignore.rb +1 -1
  35. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/img.rb +27 -25
  36. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/li.rb +1 -1
  37. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/mark.rb +1 -1
  38. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/math.rb +3 -3
  39. data/lib/reverse_adoc/converters/note.rb +17 -0
  40. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/ol.rb +1 -1
  41. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/p.rb +1 -1
  42. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/pass_through.rb +1 -1
  43. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/pre.rb +1 -1
  44. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/q.rb +1 -1
  45. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/strong.rb +1 -1
  46. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/sub.rb +1 -1
  47. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/sup.rb +1 -1
  48. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/table.rb +1 -1
  49. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/td.rb +1 -1
  50. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/text.rb +1 -1
  51. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/th.rb +1 -1
  52. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/tr.rb +1 -1
  53. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/video.rb +1 -1
  54. data/lib/{reverse_asciidoctor → reverse_adoc}/errors.rb +1 -1
  55. data/lib/reverse_adoc/html_converter.rb +56 -0
  56. data/lib/reverse_adoc/smrl_description_converter.rb +45 -0
  57. data/lib/reverse_adoc/version.rb +3 -0
  58. data/reverse_adoc.gemspec +3 -2
  59. data/spec/assets/anchors.html +8 -0
  60. data/spec/assets/external_images.docx +0 -0
  61. data/spec/assets/external_images.html +35 -0
  62. data/spec/bin/reverse_adoc_spec.rb +32 -0
  63. data/spec/bin/w2a_spec.rb +35 -0
  64. data/spec/components/anchors_spec.rb +7 -2
  65. data/spec/components/basic_spec.rb +2 -2
  66. data/spec/components/code_spec.rb +4 -4
  67. data/spec/components/escapables_spec.rb +2 -2
  68. data/spec/components/from_the_wild_spec.rb +2 -2
  69. data/spec/components/html_fragment_spec.rb +2 -2
  70. data/spec/components/lists_spec.rb +2 -2
  71. data/spec/components/paragraphs_spec.rb +2 -2
  72. data/spec/components/quotation_spec.rb +2 -2
  73. data/spec/components/tables_spec.rb +2 -2
  74. data/spec/components/unknown_tags_spec.rb +9 -9
  75. data/spec/lib/reverse_adoc.rb +90 -0
  76. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/cleaner_spec.rb +28 -4
  77. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/config_spec.rb +5 -5
  78. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/aside_spec.rb +2 -2
  79. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/audio_spec.rb +2 -2
  80. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/blockquote_spec.rb +2 -2
  81. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/br_spec.rb +2 -2
  82. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/code_spec.rb +2 -2
  83. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/div_spec.rb +2 -2
  84. data/spec/lib/reverse_adoc/converters/example_spec.rb +22 -0
  85. data/spec/lib/reverse_adoc/converters/express_ref_spec.rb +14 -0
  86. data/spec/lib/reverse_adoc/converters/ext_description_spec.rb +20 -0
  87. data/spec/lib/reverse_adoc/converters/ext_descriptions_spec.rb +13 -0
  88. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/figure_spec.rb +2 -2
  89. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/img_spec.rb +2 -2
  90. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/li_spec.rb +2 -2
  91. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/mark_spec.rb +2 -2
  92. data/spec/lib/reverse_adoc/converters/note_spec.rb +22 -0
  93. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/p_spec.rb +2 -2
  94. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/pre_spec.rb +2 -2
  95. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/q_spec.rb +2 -2
  96. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/strong_spec.rb +2 -2
  97. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/text_spec.rb +2 -2
  98. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/video_spec.rb +2 -2
  99. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters_spec.rb +5 -5
  100. data/spec/spec_helper.rb +7 -2
  101. data/spec/support/shell_helpers.rb +15 -0
  102. metadata +125 -84
  103. data/lib/reverse_asciidoctor.rb +0 -70
  104. data/lib/reverse_asciidoctor/converters/h.rb +0 -19
  105. data/lib/reverse_asciidoctor/version.rb +0 -3
  106. data/spec/lib/reverse_asciidoctor_spec.rb +0 -37
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+ require 'nokogiri'
5
+ require 'reverse_adoc/version'
6
+ require 'reverse_adoc/errors'
7
+ require 'reverse_adoc/cleaner'
8
+ require 'reverse_adoc/config'
9
+ require 'reverse_adoc/converters'
10
+ require 'reverse_adoc/converters/base'
11
+
12
+ module ReverseAdoc
13
+ def self.convert(input, options = {})
14
+ type = config.input_format
15
+ name = "#{type}_converter"
16
+ require "reverse_adoc/#{type}_converter"
17
+ constant = name.split('_').map(&:capitalize).join.to_s
18
+ ReverseAdoc.const_get(constant).convert(input, options)
19
+ end
20
+
21
+ def self.config
22
+ @config ||= Config.new
23
+ yield @config if block_given?
24
+ @config
25
+ end
26
+
27
+ def self.cleaner
28
+ @cleaner ||= Cleaner.new
29
+ end
30
+ end
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  class Cleaner
3
3
 
4
4
  def tidy(string)
@@ -36,19 +36,19 @@ module ReverseAsciidoctor
36
36
  # Same for underscores and brackets.
37
37
  def clean_tag_borders(string)
38
38
  result = string.gsub(/\s?\*{2,}.*?\*{2,}\s?/) do |match|
39
- preserve_border_whitespaces(match, default_border: ReverseAsciidoctor.config.tag_border) do
39
+ preserve_border_whitespaces(match, default_border: ReverseAdoc.config.tag_border) do
40
40
  match.strip.sub('** ', '**').sub(' **', '**')
41
41
  end
42
42
  end
43
43
 
44
44
  result = result.gsub(/\s?\_{2,}.*?\_{2,}\s?/) do |match|
45
- preserve_border_whitespaces(match, default_border: ReverseAsciidoctor.config.tag_border) do
45
+ preserve_border_whitespaces(match, default_border: ReverseAdoc.config.tag_border) do
46
46
  match.strip.sub('__ ', '__').sub(' __', '__')
47
47
  end
48
48
  end
49
49
 
50
50
  result = result.gsub(/\s?~{2,}.*?~{2,}\s?/) do |match|
51
- preserve_border_whitespaces(match, default_border: ReverseAsciidoctor.config.tag_border) do
51
+ preserve_border_whitespaces(match, default_border: ReverseAdoc.config.tag_border) do
52
52
  match.strip.sub('~~ ', '~~').sub(' ~~', '~~')
53
53
  end
54
54
  end
@@ -64,6 +64,29 @@ module ReverseAsciidoctor
64
64
  string.gsub(/(\*\*|~~|__)\s([\.!\?'"])/, "\\1".strip + "\\2")
65
65
  end
66
66
 
67
+ # preprocesses HTML, rather than postprocessing it
68
+ def preprocess_word_html(string)
69
+ clean_headings(scrub_whitespace(string.dup))
70
+ end
71
+
72
+ def scrub_whitespace(string)
73
+ string.gsub!(/ |\ |\u00a0/i, ' ') # HTML encoded spaces
74
+ string.sub!(/^\A[[:space:]]+/m, '') # document leading whitespace
75
+ string.sub!(/[[:space:]]+\z$/m, '') # document trailing whitespace
76
+ string.gsub!(/([ ]+)$/, ' ') # line trailing whitespace
77
+ string.gsub!(/\n\n\n\n/, "\n\n") # Quadruple line breaks
78
+ #string.delete!('?| ') # Unicode non-breaking spaces, injected as tabs
79
+ string
80
+ end
81
+
82
+ # following added by me
83
+ def clean_headings(string)
84
+ string.gsub!(%r{<h([1-9])[^>]*></h\1>}, " ") # I don't know why Libre Office is inserting them, but they need to go
85
+ string.gsub!(%r{<h([1-9])[^>]* style="vertical-align: super;[^>]*>(.+?)</h\1>},
86
+ "<sup>\\2</sup>") # I absolutely don't know why Libre Office is rendering superscripts as h1
87
+ string
88
+ end
89
+
67
90
  private
68
91
 
69
92
  def preserve_border_whitespaces(string, options = {}, &block)
@@ -1,12 +1,13 @@
1
1
  require 'tmpdir'
2
2
 
3
- module ReverseAsciidoctor
3
+ module ReverseAdoc
4
4
  class Config
5
5
  attr_accessor :unknown_tags, :tag_border, :mathml2asciimath, :external_images,
6
- :destination, :sourcedir, :image_counter, :image_counter_pattern
6
+ :destination, :sourcedir, :image_counter, :image_counter_pattern, :input_format
7
7
 
8
8
  def initialize
9
9
  @unknown_tags = :pass_through
10
+ @input_format = :html
10
11
  @mathml2asciimath = false
11
12
  @external_images = false
12
13
 
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  def self.register(tag_name, converter)
4
4
  @@converters ||= {}
@@ -16,17 +16,17 @@ module ReverseAsciidoctor
16
16
  private
17
17
 
18
18
  def self.default_converter(tag_name)
19
- case ReverseAsciidoctor.config.unknown_tags.to_sym
19
+ case ReverseAdoc.config.unknown_tags.to_sym
20
20
  when :pass_through
21
- ReverseAsciidoctor::Converters::PassThrough.new
21
+ ReverseAdoc::Converters::PassThrough.new
22
22
  when :drop
23
- ReverseAsciidoctor::Converters::Drop.new
23
+ ReverseAdoc::Converters::Drop.new
24
24
  when :bypass
25
- ReverseAsciidoctor::Converters::Bypass.new
25
+ ReverseAdoc::Converters::Bypass.new
26
26
  when :raise
27
27
  raise UnknownTagError, "unknown tag: #{tag_name}"
28
28
  else
29
- raise InvalidConfigurationError, "unknown value #{ReverseAsciidoctor.config.unknown_tags.inspect} for ReverseAsciidoctor.config.unknown_tags"
29
+ raise InvalidConfigurationError, "unknown value #{ReverseAdoc.config.unknown_tags.inspect} for ReverseAdoc.config.unknown_tags"
30
30
  end
31
31
  end
32
32
  end
@@ -1,6 +1,6 @@
1
1
  require "uri"
2
2
 
3
- module ReverseAsciidoctor
3
+ module ReverseAdoc
4
4
  module Converters
5
5
  class A < Base
6
6
  def convert(node, state = {})
@@ -9,10 +9,14 @@ module ReverseAsciidoctor
9
9
  title = extract_title(node)
10
10
  id = node['id'] || node['name']
11
11
 
12
- if !id.nil? && !id.empty?
12
+ id = id&.gsub(/\s/, "")&.gsub(/__+/, "_")
13
+
14
+ if /^_Toc\d+$|^_GoBack$/.match id
15
+ ""
16
+ elsif !id.nil? && !id.empty?
13
17
  "[[#{id}]]"
14
18
  elsif href.to_s.start_with?('#')
15
- href = href.sub(/^#/, "")
19
+ href = href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_")
16
20
  if name.empty?
17
21
  "<<#{href}>>"
18
22
  else
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Aside < Base
4
4
  def convert(node, state = {})
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Audio < Base
4
4
  def convert(node, state = {})
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Base
4
4
  def treat_children(node, state)
@@ -8,7 +8,7 @@ module ReverseAsciidoctor
8
8
  end
9
9
 
10
10
  def treat(node, state)
11
- ReverseAsciidoctor::Converters.lookup(node.name).convert(node, state)
11
+ ReverseAdoc::Converters.lookup(node.name).convert(node, state)
12
12
  end
13
13
 
14
14
  def escape_keychars(string)
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Blockquote < Base
4
4
  def convert(node, state = {})
@@ -7,7 +7,7 @@ module ReverseAsciidoctor
7
7
  cite = node['cite']
8
8
  attrs = cite ? "[quote, #{cite}]\n" : ""
9
9
  content = treat_children(node, state).strip
10
- content = ReverseAsciidoctor.cleaner.remove_newlines(content)
10
+ content = ReverseAdoc.cleaner.remove_newlines(content)
11
11
  #"\n\n> " << content.lines.to_a.join('> ') << "\n\n"
12
12
  "\n\n#{attrs}____\n" << content.lines.to_a.join('') << "\n____\n\n"
13
13
  end
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Br < Base
4
4
  def convert(node, state = {})
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Bypass < Base
4
4
  def convert(node, state = {})
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Code < Base
4
4
  def convert(node, state = {})
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Div < Base
4
4
  def convert(node, state = {})
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Drop < Base
4
4
  def convert(node, state = {})
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Em < Base
4
4
  def convert(node, state = {})
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ReverseAdoc
4
+ module Converters
5
+ class Example < Base
6
+ def convert(node, state = {})
7
+ <<~TEMPLATE
8
+ [example]
9
+ ====
10
+ #{treat_children(node, state)}
11
+ ====
12
+ TEMPLATE
13
+ end
14
+ end
15
+ register :example, Example.new
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ReverseAdoc
4
+ module Converters
5
+ class ExpressRef < Base
6
+ def convert(node, _state = {})
7
+ "express_ref:[#{node['linkend']}]"
8
+ end
9
+ end
10
+ register :express_ref, ExpressRef.new
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ReverseAdoc
4
+ module Converters
5
+ class ExtDescription < Base
6
+ def convert(node, state = {})
7
+ <<~TEMPLATE
8
+ (*"#{node['linkend']}"
9
+ #{treat_children(node, state)}
10
+ *)
11
+ TEMPLATE
12
+ end
13
+ end
14
+ register :ext_description, ExtDescription.new
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ReverseAdoc
4
+ module Converters
5
+ class ExtDescriptions < Base
6
+ def convert(node, state = {})
7
+ treat_children(node, state)
8
+ end
9
+ end
10
+ register :ext_descriptions, ExtDescriptions.new
11
+ end
12
+ end
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Figure < Base
4
4
  def convert(node, state = {})
@@ -0,0 +1,34 @@
1
+ module ReverseAdoc
2
+ module Converters
3
+ class H < Base
4
+ def convert(node, state = {})
5
+ id = node['id']
6
+ anchor = id ? "[[#{id}]]" : ""
7
+ internal_anchor = treat_children_anchors(node, state) || ""
8
+ anchor.empty? and anchor = internal_anchor
9
+ anchor.empty? or anchor += "\n"
10
+ prefix = '=' * (node.name[/\d/].to_i + 1)
11
+ ["\n", anchor, prefix, ' ', treat_children_no_anchors(node, state), "\n"].join
12
+ end
13
+
14
+ def treat_children_no_anchors(node, state)
15
+ node.children.reject { |a| a.name == "a" }.inject('') do |memo, child|
16
+ memo << treat(child, state)
17
+ end
18
+ end
19
+
20
+ def treat_children_anchors(node, state)
21
+ node.children.select { |a| a.name == "a" }.inject('') do |memo, child|
22
+ memo << treat(child, state)
23
+ end
24
+ end
25
+ end
26
+
27
+ register :h1, H.new
28
+ register :h2, H.new
29
+ register :h3, H.new
30
+ register :h4, H.new
31
+ register :h5, H.new
32
+ register :h6, H.new
33
+ end
34
+ end
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Head < Base
4
4
  def convert(node, state = {})
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Hr < Base
4
4
  def convert(node, state = {})
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Ignore < Base
4
4
  def convert(node, state = {})
@@ -1,47 +1,32 @@
1
1
  require "fileutils"
2
2
  require "pathname"
3
+ require "tempfile"
4
+ require "base64"
5
+ require "mimemagic"
3
6
 
4
- module ReverseAsciidoctor
7
+ module ReverseAdoc
5
8
  module Converters
6
9
  class Img < Base
7
10
 
8
11
  def image_number
9
12
  sprintf(
10
- ReverseAsciidoctor.config.image_counter_pattern,
11
- ReverseAsciidoctor.config.image_counter
13
+ ReverseAdoc.config.image_counter_pattern,
14
+ ReverseAdoc.config.image_counter
12
15
  )
13
16
  end
14
17
 
15
18
  def image_number_increment
16
- ReverseAsciidoctor.config.image_counter += 1
19
+ ReverseAdoc.config.image_counter += 1
17
20
  end
18
21
 
19
22
  def datauri2file(src)
20
23
  %r{^data:image/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ src
21
24
 
22
- dest_dir = Pathname.new(ReverseAsciidoctor.config.destination).dirname
25
+ dest_dir = Pathname.new(ReverseAdoc.config.destination).dirname
23
26
  images_dir = dest_dir + 'images'
24
27
  FileUtils.mkdir_p(images_dir)
25
28
 
26
- ext = ""
27
-
28
- if imgdata
29
- file = Tempfile.new(["radoc", ".jpg"]) do |f|
30
- f.binmode
31
- f.write(Base64.strict_decode64(imgdata))
32
- f.rewind
33
- ext = MimeMagic.by_magic(f)
34
- end
35
-
36
- image_src_path = file.path
37
- # puts "tempfile: #{file}"
38
-
39
- else
40
- ext = File.extname(src).strip.downcase[1..-1]
41
- image_src_path = Pathname.new(ReverseAsciidoctor.config.sourcedir) + src
42
-
43
- end
44
-
29
+ ext, image_src_path = determine_image_src_path(src, imgdata)
45
30
  image_dest_path = images_dir + "#{image_number}.#{ext}"
46
31
 
47
32
  # puts "image_dest_path: #{image_dest_path.to_s}"
@@ -53,6 +38,23 @@ module ReverseAsciidoctor
53
38
  image_dest_path.relative_path_from(dest_dir)
54
39
  end
55
40
 
41
+ def determine_image_src_path(src, imgdata)
42
+ return copy_temp_file(imgdata) if imgdata
43
+
44
+ ext = File.extname(src).strip.downcase[1..-1]
45
+ [ext, Pathname.new(ReverseAdoc.config.sourcedir) + src]
46
+ end
47
+
48
+ def copy_temp_file(imgdata)
49
+ Tempfile.open(['radoc', '.jpg']) do |f|
50
+ f.binmode
51
+ f.write(Base64.strict_decode64(imgdata))
52
+ f.rewind
53
+ ext = MimeMagic.by_magic(f).subtype
54
+ [ext, f.path]
55
+ end
56
+ end
57
+
56
58
  def convert(node, state = {})
57
59
  alt = node['alt']
58
60
  src = node['src']
@@ -62,7 +64,7 @@ module ReverseAsciidoctor
62
64
  anchor = id ? "[[#{id}]]\n" : ""
63
65
  title = extract_title(node)
64
66
 
65
- if ReverseAsciidoctor.config.external_images
67
+ if ReverseAdoc.config.external_images
66
68
  # puts "external image conversion #{id}, #{src}"
67
69
  src = datauri2file(src)
68
70
  end