reverse_adoc 0.3.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +4 -3
  3. data/Gemfile +1 -1
  4. data/Rakefile +7 -7
  5. data/exe/reverse_adoc +11 -11
  6. data/exe/w2a +15 -16
  7. data/lib/reverse_adoc/cleaner.rb +17 -18
  8. data/lib/reverse_adoc/config.rb +7 -7
  9. data/lib/reverse_adoc/converters/a.rb +24 -24
  10. data/lib/reverse_adoc/converters/aside.rb +6 -4
  11. data/lib/reverse_adoc/converters/audio.rb +16 -21
  12. data/lib/reverse_adoc/converters/base.rb +79 -5
  13. data/lib/reverse_adoc/converters/blockquote.rb +16 -7
  14. data/lib/reverse_adoc/converters/br.rb +5 -1
  15. data/lib/reverse_adoc/converters/bypass.rb +38 -34
  16. data/lib/reverse_adoc/converters/code.rb +42 -1
  17. data/lib/reverse_adoc/converters/div.rb +7 -3
  18. data/lib/reverse_adoc/converters/drop.rb +6 -2
  19. data/lib/reverse_adoc/converters/em.rb +44 -7
  20. data/lib/reverse_adoc/converters/figure.rb +10 -6
  21. data/lib/reverse_adoc/converters/h.rb +19 -11
  22. data/lib/reverse_adoc/converters/head.rb +7 -2
  23. data/lib/reverse_adoc/converters/hr.rb +5 -1
  24. data/lib/reverse_adoc/converters/ignore.rb +6 -2
  25. data/lib/reverse_adoc/converters/img.rb +29 -19
  26. data/lib/reverse_adoc/converters/li.rb +6 -13
  27. data/lib/reverse_adoc/converters/mark.rb +11 -2
  28. data/lib/reverse_adoc/converters/math.rb +13 -2
  29. data/lib/reverse_adoc/converters/ol.rb +44 -26
  30. data/lib/reverse_adoc/converters/p.rb +13 -7
  31. data/lib/reverse_adoc/converters/pass_through.rb +5 -1
  32. data/lib/reverse_adoc/converters/pre.rb +23 -10
  33. data/lib/reverse_adoc/converters/q.rb +6 -2
  34. data/lib/reverse_adoc/converters/strong.rb +41 -6
  35. data/lib/reverse_adoc/converters/sub.rb +6 -2
  36. data/lib/reverse_adoc/converters/sup.rb +6 -2
  37. data/lib/reverse_adoc/converters/table.rb +28 -23
  38. data/lib/reverse_adoc/converters/td.rb +32 -16
  39. data/lib/reverse_adoc/converters/text.rb +19 -19
  40. data/lib/reverse_adoc/converters/th.rb +4 -6
  41. data/lib/reverse_adoc/converters/tr.rb +7 -7
  42. data/lib/reverse_adoc/converters/video.rb +16 -23
  43. data/lib/reverse_adoc/converters.rb +2 -3
  44. data/lib/reverse_adoc/html_converter.rb +48 -43
  45. data/lib/reverse_adoc/version.rb +1 -1
  46. data/lib/reverse_adoc.rb +9 -9
  47. data/reverse_adoc.gemspec +6 -3
  48. data/spec/assets/basic.html +3 -0
  49. data/spec/bin/reverse_adoc_spec.rb +9 -8
  50. data/spec/bin/w2a_spec.rb +12 -12
  51. data/spec/components/anchors_spec.rb +18 -12
  52. data/spec/components/basic_spec.rb +28 -14
  53. data/spec/components/code_spec.rb +2 -4
  54. data/spec/components/escapables_spec.rb +4 -6
  55. data/spec/components/from_the_wild_spec.rb +2 -4
  56. data/spec/components/html_fragment_spec.rb +2 -3
  57. data/spec/components/lists_spec.rb +12 -8
  58. data/spec/components/paragraphs_spec.rb +2 -3
  59. data/spec/components/quotation_spec.rb +5 -5
  60. data/spec/components/tables_spec.rb +22 -11
  61. data/spec/components/unknown_tags_spec.rb +13 -10
  62. data/spec/lib/reverse_adoc/cleaner_spec.rb +70 -71
  63. data/spec/lib/reverse_adoc/config_spec.rb +5 -6
  64. data/spec/lib/reverse_adoc/converters/aside_spec.rb +2 -3
  65. data/spec/lib/reverse_adoc/converters/audio_spec.rb +3 -5
  66. data/spec/lib/reverse_adoc/converters/blockquote_spec.rb +5 -6
  67. data/spec/lib/reverse_adoc/converters/br_spec.rb +2 -2
  68. data/spec/lib/reverse_adoc/converters/code_spec.rb +3 -5
  69. data/spec/lib/reverse_adoc/converters/div_spec.rb +3 -5
  70. data/spec/lib/reverse_adoc/converters/figure_spec.rb +2 -4
  71. data/spec/lib/reverse_adoc/converters/img_spec.rb +5 -7
  72. data/spec/lib/reverse_adoc/converters/li_spec.rb +2 -4
  73. data/spec/lib/reverse_adoc/converters/mark_spec.rb +4 -4
  74. data/spec/lib/reverse_adoc/converters/p_spec.rb +2 -3
  75. data/spec/lib/reverse_adoc/converters/pre_spec.rb +8 -9
  76. data/spec/lib/reverse_adoc/converters/q_spec.rb +3 -3
  77. data/spec/lib/reverse_adoc/converters/strong_spec.rb +9 -8
  78. data/spec/lib/reverse_adoc/converters/text_spec.rb +21 -16
  79. data/spec/lib/reverse_adoc/converters/video_spec.rb +7 -9
  80. data/spec/lib/reverse_adoc/converters_spec.rb +9 -6
  81. data/spec/lib/reverse_adoc.rb +25 -25
  82. data/spec/spec_helper.rb +11 -11
  83. data/spec/support/shell_helpers.rb +1 -1
  84. metadata +20 -6
@@ -1,9 +1,13 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class PassThrough < Base
4
- def convert(node, state = {})
4
+ def to_coradoc(node, _state = {})
5
5
  node.to_s
6
6
  end
7
+
8
+ def convert(node, state = {})
9
+ to_coradoc(node, state)
10
+ end
7
11
  end
8
12
  end
9
13
  end
@@ -1,21 +1,34 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class Pre < Base
4
- def convert(node, state = {})
5
- id = node['id']
6
- anchor = id ? "[[#{id}]]\n" : ""
4
+ def to_coradoc(node, state = {})
5
+ id = node["id"]
7
6
  lang = language(node)
8
7
  content = treat_children(node, state)
9
- if lang
10
- "\n\n#{anchor}[source,#{lang}]\n----\n" << content.lines.to_a.join("") << "\n----\n\n"
11
- else
12
- "\n\n#{anchor}....\n" << content.lines.to_a.join("") << "\n....\n\n"
8
+
9
+ unless lang
10
+ return Coradoc::Element::Block::Literal.new(
11
+ nil,
12
+ lines: content,
13
+ id: id,
14
+ )
13
15
  end
16
+
17
+ Coradoc::Element::Block::SourceCode.new(
18
+ nil,
19
+ lines: content,
20
+ lang: lang,
21
+ id: id,
22
+ )
23
+ end
24
+
25
+ def convert(node, state = {})
26
+ Coradoc::Generator.gen_adoc(to_coradoc(node, state))
14
27
  end
15
28
 
16
29
  private
17
30
 
18
- def treat(node, state)
31
+ def treat(node, _state)
19
32
  return "\n" if node.name == "br"
20
33
 
21
34
  prefix = postfix = "\n\n" if node.name == "p"
@@ -29,11 +42,11 @@ module ReverseAdoc
29
42
  end
30
43
 
31
44
  def language_from_highlight_class(node)
32
- node.parent['class'].to_s[/highlight-([a-zA-Z0-9]+)/, 1]
45
+ node.parent["class"].to_s[/highlight-([a-zA-Z0-9]+)/, 1]
33
46
  end
34
47
 
35
48
  def language_from_confluence_class(node)
36
- node['class'].to_s[/brush:\s?(:?.*);/, 1]
49
+ node["class"].to_s[/brush:\s?(:?.*);/, 1]
37
50
  end
38
51
  end
39
52
 
@@ -1,9 +1,13 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class Q < Base
4
- def convert(node, state = {})
4
+ def to_coradoc(node, state = {})
5
5
  content = treat_children(node, state)
6
- "#{content[/^\s*/]}\"#{content.strip}\"#{content[/\s*$/]}"
6
+ Coradoc::Element::Inline::Quotation.new(content)
7
+ end
8
+
9
+ def convert(node, state = {})
10
+ Coradoc::Generator.gen_adoc(to_coradoc(node, state))
7
11
  end
8
12
  end
9
13
 
@@ -1,13 +1,48 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class Strong < Base
4
- def convert(node, state = {})
5
- content = treat_children(node, state.merge(already_strong: true))
6
- if content.strip.empty? || state[:already_strong]
7
- content
8
- else
9
- "#{content[/^\s*/]}*#{content.strip}*#{content[/\s*$/]}"
4
+ def to_coradoc(node, state = {})
5
+ content = treat_children_coradoc(node,
6
+ state.merge(already_strong: true))
7
+
8
+ if Coradoc::Generator.gen_adoc(content).strip.empty?
9
+ return ""
10
+ end
11
+
12
+ if node_has_ancestor?(node, ["strong", "b"])
13
+ return content
10
14
  end
15
+
16
+ u_before = unconstrained_before?(node)
17
+ u_after = unconstrained_after?(node)
18
+ node.text =~ /^(\s+)/
19
+ leading_whitespace = $1
20
+ has_leading_whitespace = !leading_whitespace.nil?
21
+
22
+ if has_leading_whitespace
23
+ first_text = node.at_xpath("./text()[1]")
24
+ first_text.replace(first_text.text.lstrip)
25
+ leading_whitespace = u_before ? " " : " " # ########################33 somethings wrong in here
26
+ end
27
+
28
+ node.text =~ /(\s+)$/
29
+ trailing_whitespace = $1
30
+ has_trailing_whitespace = !trailing_whitespace.nil?
31
+
32
+ if has_trailing_whitespace
33
+ last_text = node.at_xpath("./text()[last()]")
34
+ last_text.replace(last_text.text.rstrip)
35
+ trailing_whitespace = u_after ? "" : "" ###############################
36
+ end
37
+
38
+ u = !((!u_before || has_leading_whitespace) && (!u_after || has_trailing_whitespace))
39
+ e = Coradoc::Element::Inline::Bold.new(content, u)
40
+
41
+ [leading_whitespace, e, trailing_whitespace]
42
+ end
43
+
44
+ def convert(node, state = {})
45
+ Coradoc::Generator.gen_adoc(to_coradoc(node, state))
11
46
  end
12
47
  end
13
48
 
@@ -1,9 +1,13 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class Sub < Base
4
+ def to_coradoc(node, state = {})
5
+ content = treat_children_coradoc(node, state)
6
+ Coradoc::Element::Inline::Subscript.new(content)
7
+ end
8
+
4
9
  def convert(node, state = {})
5
- content = treat_children(node, state)
6
- "#{content[/^\s*/]}~#{content.strip}~#{content[/\s*$/]}"
10
+ Coradoc::Generator.gen_adoc(to_coradoc(node, state))
7
11
  end
8
12
  end
9
13
 
@@ -1,9 +1,13 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class Sup < Base
4
- def convert(node, state = {})
4
+ def to_coradoc(node, state = {})
5
5
  content = treat_children(node, state)
6
- "#{content[/^\s*/]}^#{content.strip}^#{content[/\s*$/]}"
6
+ Coradoc::Element::Inline::Superscript.new(content)
7
+ end
8
+
9
+ def convert(node, state = {})
10
+ Coradoc::Generator.gen_adoc(to_coradoc(node, state))
7
11
  end
8
12
  end
9
13
 
@@ -1,61 +1,66 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class Table < Base
4
- def convert(node, state = {})
5
- id = node['id']
6
- anchor = id ? "[[#{id}]]\n" : ""
4
+ def to_coradoc(node, state = {})
5
+ id = node["id"]
7
6
  title = extract_title(node)
8
- title = ".#{title}\n" unless title.empty?
9
7
  attrs = style(node)
10
- "\n\n#{anchor}#{attrs}#{title}|===\n" << treat_children(node, state) << "\n|===\n"
8
+ content = treat_children_coradoc(node, state)
9
+ Coradoc::Element::Table.new(title, content, { id: id, attrs: attrs })
10
+ end
11
+
12
+ def convert(node, state = {})
13
+ Coradoc::Generator.gen_adoc(to_coradoc(node, state))
11
14
  end
12
15
 
13
16
  def extract_title(node)
14
17
  title = node.at("./caption")
15
18
  return "" if title.nil?
19
+
16
20
  treat_children(title, {})
17
21
  end
18
22
 
19
23
  def frame(node)
20
24
  case node["frame"]
21
25
  when "void"
22
- "frame=none"
26
+ "none"
23
27
  when "hsides"
24
- "frame=topbot"
28
+ "topbot"
25
29
  when "vsides"
26
- "frame=sides"
30
+ "sides"
27
31
  when "box", "border"
28
- "frame=all"
29
- else
30
- nil
32
+ "all"
31
33
  end
32
34
  end
33
35
 
34
36
  def rules(node)
35
37
  case node["rules"]
36
38
  when "all"
37
- "rules=all"
39
+ "all"
38
40
  when "rows"
39
- "rules=rows"
41
+ "rows"
40
42
  when "cols"
41
- "rules=cols"
43
+ "cols"
42
44
  when "none"
43
- "rules=none"
44
- else
45
- nil
45
+ "none"
46
46
  end
47
47
  end
48
48
 
49
49
  def style(node)
50
- width = "width=#{node['width']}" if node['width']
51
- attrs = []
50
+ attrs = Coradoc::Element::AttributeList.new
51
+ # Width is disabled on tables for now. (From #88)
52
+ # attrs.add_named("width", node["width"]) if node["width"]
53
+
52
54
  frame_attr = frame(node)
55
+ attrs.add_named("frame", frame_attr) if frame_attr
56
+
53
57
  rules_attr = rules(node)
54
- attrs << width if width
55
- attrs << frame_attr if frame_attr
56
- attrs << rules_attr if rules_attr
58
+ attrs.add_named("rules", rules_attr) if rules_attr
59
+
60
+ # This line should be removed.
57
61
  return "" if attrs.empty?
58
- "[#{attrs.join(',')}]\n"
62
+
63
+ attrs
59
64
  end
60
65
  end
61
66
 
@@ -1,32 +1,48 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class Td < Base
4
- def convert(node, state = {})
5
- id = node['id']
6
- anchor = id ? "[[#{id}]]" : ""
7
- colrowattr = colrow(node['colspan'], node['rowspan'])
4
+ def to_coradoc(node, state = {})
5
+ # convert(node, state)
6
+ id = node["id"]
7
+ colrowattr = colrow(node["colspan"], node["rowspan"])
8
8
  alignattr = alignstyle(node)
9
9
  style = cellstyle(node)
10
+
10
11
  singlepara = node.elements.size == 1 && node.elements.first.name == "p"
11
12
  state[:tdsinglepara] = singlepara if singlepara
13
+
12
14
  adoccell = node.at(".//ul | .//ol | .//pre | .//blockquote | .//br | .//hr") ||
13
15
  node.at(".//p") && !singlepara
16
+
14
17
  style = "a" if adoccell
15
18
  delim = adoccell ? "\n" : " "
16
- content = treat_children(node, state)
17
- "#{colrowattr}#{alignattr}#{style}| #{anchor}#{content}#{delim}"
19
+ content = treat_children_coradoc(node, state)
20
+ options = {}.tap do |hash|
21
+ hash[:id] = id
22
+ hash[:colrowattr] = colrowattr
23
+ hash[:alignattr] = alignattr
24
+ hash[:style] = style
25
+ hash[:content] = content
26
+ hash[:delim] = delim
27
+ end
28
+
29
+ Coradoc::Element::Table::Cell.new(options)
30
+ end
31
+
32
+ def convert(node, state = {})
33
+ Coradoc::Generator.gen_adoc(to_coradoc(node, state))
18
34
  end
19
35
 
20
- def cellstyle(node)
36
+ def cellstyle(_node)
21
37
  ""
22
38
  end
23
39
 
24
40
  def colrow(colspan, rowspan)
25
- if colspan && rowspan
41
+ if colspan && rowspan && colspan != "1" && rowspan != "1"
26
42
  "#{colspan}.#{rowspan}+"
27
- elsif colspan
43
+ elsif colspan && colspan != "1"
28
44
  "#{colspan}+"
29
- elsif rowspan
45
+ elsif rowspan && rowspan != "1"
30
46
  ".#{rowspan}+"
31
47
  else
32
48
  ""
@@ -37,16 +53,16 @@ module ReverseAdoc
37
53
  align = node["align"]
38
54
  valign = node["valign"]
39
55
  a = case align
40
- when "left" then "<"
41
- when "center" then "^"
42
- when "right" then ">"
56
+ when "left" then "<"
57
+ when "center" then "^"
58
+ when "right" then ">"
43
59
  else
44
60
  ""
45
61
  end
46
62
  v = case valign
47
- when "top" then "<"
48
- when "middle" then "^"
49
- when "bottom" then ">"
63
+ when "top" then "<"
64
+ when "middle" then "^"
65
+ when "bottom" then ">"
50
66
  else
51
67
  ""
52
68
  end
@@ -1,26 +1,28 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class Text < Base
4
+ def to_coradoc(node, state = {})
5
+ return treat_empty(node, state) if node.text.strip.empty?
6
+
7
+ Coradoc::Element::TextElement.new(treat_text(node))
8
+ end
9
+
4
10
  def convert(node, state = {})
5
- if node.text.strip.empty?
6
- treat_empty(node, state)
7
- else
8
- treat_text(node)
9
- end
11
+ Coradoc::Generator.gen_adoc(to_coradoc(node, state))
10
12
  end
11
13
 
12
14
  private
13
15
 
14
16
  def treat_empty(node, state)
15
17
  parent = node.parent.name.to_sym
16
- if [:ol, :ul].include?(parent) # Otherwise the identation is broken
17
- ''
18
+ if %i[ol ul].include?(parent) # Otherwise the identation is broken
19
+ ""
18
20
  elsif state[:tdsinglepara]
19
- ''
20
- elsif node.text == ' ' # Regular whitespace text node
21
- ' '
21
+ ""
22
+ elsif node.text == " " # Regular whitespace text node
23
+ " "
22
24
  else
23
- ''
25
+ ""
24
26
  end
25
27
  end
26
28
 
@@ -32,30 +34,28 @@ module ReverseAdoc
32
34
  text = escape_keychars(text)
33
35
 
34
36
  text = preserve_keychars_within_backticks(text)
35
- text = preserve_tags(text)
36
-
37
- text
37
+ escape_links(text)
38
38
  end
39
39
 
40
40
  def preserve_nbsp(text)
41
41
  text.gsub(/\u00A0/, "&nbsp;")
42
42
  end
43
43
 
44
- def preserve_tags(text)
45
- text.gsub(/[<>]/, '>' => '\>', '<' => '\<')
44
+ def escape_links(text)
45
+ text.gsub(/<<([^>]*)>>/, "\\<<\\1>>")
46
46
  end
47
47
 
48
48
  def remove_border_newlines(text)
49
- text.gsub(/\A\n+/, '').gsub(/\n+\z/, '')
49
+ text.gsub(/\A\n+/, "").gsub(/\n+\z/, "")
50
50
  end
51
51
 
52
52
  def remove_inner_newlines(text)
53
- text.tr("\n\t", ' ').squeeze(' ')
53
+ text.tr("\n\t", " ").squeeze(" ")
54
54
  end
55
55
 
56
56
  def preserve_keychars_within_backticks(text)
57
57
  text.gsub(/`.*?`/) do |match|
58
- match.gsub('\_', '_').gsub('\*', '*')
58
+ match.gsub('\_', "_").gsub('\*', "*")
59
59
  end
60
60
  end
61
61
  end
@@ -2,12 +2,10 @@ module ReverseAdoc
2
2
  module Converters
3
3
  class Th < Td
4
4
  def cellstyle(node)
5
- if node.parent.previous_element.nil?
6
- # this is the header row
7
- ""
8
- else
9
- "h"
10
- end
5
+ # this is the header row
6
+ return "" if node.parent.previous_element.nil?
7
+
8
+ "h"
11
9
  end
12
10
  end
13
11
 
@@ -1,20 +1,20 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class Tr < Base
4
+ def to_coradoc(node, state = {})
5
+ content = treat_children_coradoc(node, state)
6
+ header = table_header_row?(node)
7
+ Coradoc::Element::Table::Row.new(content, header)
8
+ end
9
+
4
10
  def convert(node, state = {})
5
- content = treat_children(node, state).rstrip
6
- result = "#{content}\n"
7
- table_header_row?(node) ? result + underline_for(node) : result
11
+ Coradoc::Generator.gen_adoc(to_coradoc(node, state))
8
12
  end
9
13
 
10
14
  def table_header_row?(node)
11
15
  # node.element_children.all? {|child| child.name.to_sym == :th}
12
16
  node.previous_element.nil?
13
17
  end
14
-
15
- def underline_for(node)
16
- "\n"
17
- end
18
18
  end
19
19
 
20
20
  register :tr, Tr.new
@@ -1,33 +1,26 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class Video < Base
4
- def convert(node, state = {})
5
- autoplay = node['autoplay']
6
- loop_attr = node['loop']
7
- controls = node['controls']
8
- src = node['src']
9
- id = node['id']
10
- anchor = id ? "[[#{id}]]\n" : ""
4
+ def to_coradoc(node, _state = {})
5
+ src = node["src"]
6
+ id = node["id"]
11
7
  title = extract_title(node)
12
- title = ".#{title}\n" unless title.empty?
13
- [anchor, title, "video::", src, "[", options(node), "]"].join("")
8
+ attributes = Coradoc::Element::AttributeList.new
9
+ options = options(node)
10
+ attributes.add_named("options", options) if options.any?
11
+ Coradoc::Element::Video.new(title, id: id, src: src,
12
+ attributes: attributes)
13
+ end
14
+
15
+ def convert(node, state = {})
16
+ Coradoc::Generator.gen_adoc(to_coradoc(node, state))
14
17
  end
15
18
 
16
19
  def options(node)
17
- autoplay = node['autoplay']
18
- loop_attr = node['loop']
19
- controls = node['controls']
20
- width = node['width']
21
- ret = ""
22
- if autoplay || loop_attr || controls
23
- out = []
24
- out << "autoplay" if autoplay
25
- out << "loop" if loop_attr
26
- out << "controls" if controls
27
- out << "width=#{width}" if width
28
- ret = %{options="#{out.join(',')}"}
29
- end
30
- ret
20
+ autoplay = node["autoplay"]
21
+ loop_attr = node["loop"]
22
+ controls = node["controls"]
23
+ [autoplay, loop_attr, controls].compact
31
24
  end
32
25
  end
33
26
 
@@ -13,8 +13,6 @@ module ReverseAdoc
13
13
  @@converters[tag_name.to_sym] or default_converter(tag_name)
14
14
  end
15
15
 
16
- private
17
-
18
16
  def self.default_converter(tag_name)
19
17
  case ReverseAdoc.config.unknown_tags.to_sym
20
18
  when :pass_through
@@ -26,7 +24,8 @@ module ReverseAdoc
26
24
  when :raise
27
25
  raise UnknownTagError, "unknown tag: #{tag_name}"
28
26
  else
29
- raise InvalidConfigurationError, "unknown value #{ReverseAdoc.config.unknown_tags.inspect} for ReverseAdoc.config.unknown_tags"
27
+ raise InvalidConfigurationError,
28
+ "unknown value #{ReverseAdoc.config.unknown_tags.inspect} for ReverseAdoc.config.unknown_tags"
30
29
  end
31
30
  end
32
31
  end
@@ -1,56 +1,61 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "reverse_adoc/converters/a"
4
- require "reverse_adoc/converters/aside"
5
- require "reverse_adoc/converters/audio"
6
- require "reverse_adoc/converters/blockquote"
7
- require "reverse_adoc/converters/br"
8
- require "reverse_adoc/converters/bypass"
9
- require "reverse_adoc/converters/code"
10
- require "reverse_adoc/converters/div"
11
- require "reverse_adoc/converters/drop"
12
- require "reverse_adoc/converters/em"
13
- require "reverse_adoc/converters/figure"
14
- require "reverse_adoc/converters/h"
15
- require "reverse_adoc/converters/head"
16
- require "reverse_adoc/converters/hr"
17
- require "reverse_adoc/converters/ignore"
18
- require "reverse_adoc/converters/img"
19
- require "reverse_adoc/converters/mark"
20
- require "reverse_adoc/converters/li"
21
- require "reverse_adoc/converters/ol"
22
- require "reverse_adoc/converters/p"
23
- require "reverse_adoc/converters/pass_through"
24
- require "reverse_adoc/converters/pre"
25
- require "reverse_adoc/converters/q"
26
- require "reverse_adoc/converters/strong"
27
- require "reverse_adoc/converters/sup"
28
- require "reverse_adoc/converters/sub"
29
- require "reverse_adoc/converters/table"
30
- require "reverse_adoc/converters/td"
31
- require "reverse_adoc/converters/th"
32
- require "reverse_adoc/converters/text"
33
- require "reverse_adoc/converters/tr"
34
- require "reverse_adoc/converters/video"
35
- require "reverse_adoc/converters/math"
3
+ require_relative "converters/a"
4
+ require_relative "converters/aside"
5
+ require_relative "converters/audio"
6
+ require_relative "converters/blockquote"
7
+ require_relative "converters/br"
8
+ require_relative "converters/bypass"
9
+ require_relative "converters/code"
10
+ require_relative "converters/div"
11
+ require_relative "converters/drop"
12
+ require_relative "converters/em"
13
+ require_relative "converters/figure"
14
+ require_relative "converters/h"
15
+ require_relative "converters/head"
16
+ require_relative "converters/hr"
17
+ require_relative "converters/ignore"
18
+ require_relative "converters/img"
19
+ require_relative "converters/mark"
20
+ require_relative "converters/li"
21
+ require_relative "converters/ol"
22
+ require_relative "converters/p"
23
+ require_relative "converters/pass_through"
24
+ require_relative "converters/pre"
25
+ require_relative "converters/q"
26
+ require_relative "converters/strong"
27
+ require_relative "converters/sup"
28
+ require_relative "converters/sub"
29
+ require_relative "converters/table"
30
+ require_relative "converters/td"
31
+ require_relative "converters/th"
32
+ require_relative "converters/text"
33
+ require_relative "converters/tr"
34
+ require_relative "converters/video"
35
+ require_relative "converters/math"
36
36
 
37
37
  module ReverseAdoc
38
38
  class HtmlConverter
39
- def self.convert(input, options = {})
40
- root = if input.is_a?(String)
41
- then Nokogiri::HTML(input).root
42
- elsif input.is_a?(Nokogiri::XML::Document)
43
- then input.root
44
- elsif input.is_a?(Nokogiri::XML::Node)
45
- then input
39
+ def self.to_coradoc(input, options = {})
40
+ root = case input
41
+ when String
42
+ Nokogiri::HTML(input).root
43
+ when Nokogiri::XML::Document
44
+ input.root
45
+ when Nokogiri::XML::Node
46
+ input
46
47
  end
47
48
 
48
- root || (return "")
49
+ return "" unless root
49
50
 
50
51
  ReverseAdoc.config.with(options) do
51
- result = ReverseAdoc::Converters.lookup(root.name).convert(root)
52
- ReverseAdoc.cleaner.tidy(result)
52
+ ReverseAdoc::Converters.lookup(root.name).to_coradoc(root)
53
53
  end
54
54
  end
55
+
56
+ def self.convert(input, options = {})
57
+ result = Coradoc::Generator.gen_adoc(to_coradoc(input, options))
58
+ ReverseAdoc.cleaner.tidy(result)
59
+ end
55
60
  end
56
61
  end
@@ -1,3 +1,3 @@
1
1
  module ReverseAdoc
2
- VERSION = "0.3.6".freeze
2
+ VERSION = "1.0.0".freeze
3
3
  end