reverse_adoc 1.0.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +16 -3
- data/.github/workflows/release.yml +19 -2
- data/Gemfile +5 -3
- data/README.adoc +21 -280
- data/Rakefile +4 -10
- data/lib/reverse_adoc/version.rb +3 -1
- data/lib/reverse_adoc.rb +16 -21
- data/reverse_adoc.gemspec +13 -21
- data/spec/reverse_adoc_spec.rb +28 -0
- data/spec/spec_helper.rb +5 -20
- metadata +21 -228
- data/.editorconfig +0 -15
- data/.gitignore +0 -10
- data/.hound.yml +0 -5
- data/.rubocop.yml +0 -10
- data/LICENSE.txt +0 -25
- data/exe/reverse_adoc +0 -70
- data/exe/w2a +0 -72
- data/lib/reverse_adoc/cleaner.rb +0 -113
- data/lib/reverse_adoc/config.rb +0 -54
- data/lib/reverse_adoc/converters/a.rb +0 -42
- data/lib/reverse_adoc/converters/aside.rb +0 -16
- data/lib/reverse_adoc/converters/audio.rb +0 -29
- data/lib/reverse_adoc/converters/base.rb +0 -100
- data/lib/reverse_adoc/converters/blockquote.rb +0 -27
- data/lib/reverse_adoc/converters/br.rb +0 -15
- data/lib/reverse_adoc/converters/bypass.rb +0 -81
- data/lib/reverse_adoc/converters/code.rb +0 -56
- data/lib/reverse_adoc/converters/div.rb +0 -18
- data/lib/reverse_adoc/converters/drop.rb +0 -22
- data/lib/reverse_adoc/converters/em.rb +0 -55
- data/lib/reverse_adoc/converters/figure.rb +0 -25
- data/lib/reverse_adoc/converters/h.rb +0 -42
- data/lib/reverse_adoc/converters/head.rb +0 -23
- data/lib/reverse_adoc/converters/hr.rb +0 -15
- data/lib/reverse_adoc/converters/ignore.rb +0 -16
- data/lib/reverse_adoc/converters/img.rb +0 -93
- data/lib/reverse_adoc/converters/li.rb +0 -17
- data/lib/reverse_adoc/converters/mark.rb +0 -21
- data/lib/reverse_adoc/converters/math.rb +0 -31
- data/lib/reverse_adoc/converters/ol.rb +0 -64
- data/lib/reverse_adoc/converters/p.rb +0 -23
- data/lib/reverse_adoc/converters/pass_through.rb +0 -13
- data/lib/reverse_adoc/converters/pre.rb +0 -55
- data/lib/reverse_adoc/converters/q.rb +0 -16
- data/lib/reverse_adoc/converters/strong.rb +0 -52
- data/lib/reverse_adoc/converters/sub.rb +0 -16
- data/lib/reverse_adoc/converters/sup.rb +0 -16
- data/lib/reverse_adoc/converters/table.rb +0 -69
- data/lib/reverse_adoc/converters/td.rb +0 -83
- data/lib/reverse_adoc/converters/text.rb +0 -65
- data/lib/reverse_adoc/converters/th.rb +0 -14
- data/lib/reverse_adoc/converters/tr.rb +0 -22
- data/lib/reverse_adoc/converters/video.rb +0 -29
- data/lib/reverse_adoc/converters.rb +0 -32
- data/lib/reverse_adoc/errors.rb +0 -10
- data/lib/reverse_adoc/html_converter.rb +0 -61
- data/spec/assets/anchors.html +0 -30
- data/spec/assets/basic.html +0 -61
- data/spec/assets/code.html +0 -22
- data/spec/assets/escapables.html +0 -17
- data/spec/assets/external_images.docx +0 -0
- data/spec/assets/external_images.html +0 -35
- data/spec/assets/from_the_wild.html +0 -23
- data/spec/assets/full_example.html +0 -49
- data/spec/assets/html_fragment.html +0 -3
- data/spec/assets/lists.html +0 -137
- data/spec/assets/minimum.html +0 -4
- data/spec/assets/paragraphs.html +0 -24
- data/spec/assets/quotation.html +0 -12
- data/spec/assets/tables.html +0 -99
- data/spec/assets/unknown_tags.html +0 -9
- data/spec/bin/reverse_adoc_spec.rb +0 -33
- data/spec/bin/w2a_spec.rb +0 -35
- data/spec/components/anchors_spec.rb +0 -32
- data/spec/components/basic_spec.rb +0 -63
- data/spec/components/code_spec.rb +0 -25
- data/spec/components/escapables_spec.rb +0 -30
- data/spec/components/from_the_wild_spec.rb +0 -15
- data/spec/components/html_fragment_spec.rb +0 -9
- data/spec/components/lists_spec.rb +0 -90
- data/spec/components/paragraphs_spec.rb +0 -14
- data/spec/components/quotation_spec.rb +0 -12
- data/spec/components/tables_spec.rb +0 -42
- data/spec/components/unknown_tags_spec.rb +0 -41
- data/spec/lib/reverse_adoc/cleaner_spec.rb +0 -180
- data/spec/lib/reverse_adoc/config_spec.rb +0 -25
- data/spec/lib/reverse_adoc/converters/aside_spec.rb +0 -11
- data/spec/lib/reverse_adoc/converters/audio_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters/blockquote_spec.rb +0 -23
- data/spec/lib/reverse_adoc/converters/br_spec.rb +0 -9
- data/spec/lib/reverse_adoc/converters/code_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters/div_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters/figure_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/img_spec.rb +0 -25
- data/spec/lib/reverse_adoc/converters/li_spec.rb +0 -11
- data/spec/lib/reverse_adoc/converters/mark_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/p_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/pre_spec.rb +0 -43
- data/spec/lib/reverse_adoc/converters/q_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/strong_spec.rb +0 -21
- data/spec/lib/reverse_adoc/converters/text_spec.rb +0 -67
- data/spec/lib/reverse_adoc/converters/video_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters_spec.rb +0 -22
- data/spec/lib/reverse_adoc.rb +0 -90
- data/spec/support/shell_helpers.rb +0 -15
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
require "fileutils"
|
|
2
|
-
require "pathname"
|
|
3
|
-
require "tempfile"
|
|
4
|
-
require "base64"
|
|
5
|
-
require "marcel"
|
|
6
|
-
|
|
7
|
-
module ReverseAdoc
|
|
8
|
-
module Converters
|
|
9
|
-
class Img < Base
|
|
10
|
-
def image_number
|
|
11
|
-
sprintf(
|
|
12
|
-
ReverseAdoc.config.image_counter_pattern,
|
|
13
|
-
ReverseAdoc.config.image_counter,
|
|
14
|
-
)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def image_number_increment
|
|
18
|
-
ReverseAdoc.config.image_counter += 1
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def datauri2file(src)
|
|
22
|
-
%r{^data:image/(?:[^;]+);base64,(?<imgdata>.+)$} =~ src
|
|
23
|
-
|
|
24
|
-
dest_dir = Pathname.new(ReverseAdoc.config.destination).dirname
|
|
25
|
-
images_dir = dest_dir.join("images")
|
|
26
|
-
FileUtils.mkdir_p(images_dir)
|
|
27
|
-
|
|
28
|
-
ext, image_src_path = determine_image_src_path(src, imgdata)
|
|
29
|
-
image_dest_path = images_dir + "#{image_number}.#{ext}"
|
|
30
|
-
|
|
31
|
-
# puts "image_dest_path: #{image_dest_path.to_s}"
|
|
32
|
-
# puts "image_src_path: #{image_src_path.to_s}"
|
|
33
|
-
|
|
34
|
-
FileUtils.cp(image_src_path, image_dest_path)
|
|
35
|
-
image_number_increment
|
|
36
|
-
|
|
37
|
-
image_dest_path.relative_path_from(dest_dir)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def determine_image_src_path(src, imgdata)
|
|
41
|
-
return copy_temp_file(imgdata) if imgdata
|
|
42
|
-
|
|
43
|
-
ext = File.extname(src).strip.downcase[1..-1]
|
|
44
|
-
[ext, Pathname.new(ReverseAdoc.config.sourcedir).join(src)]
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def copy_temp_file(imgdata)
|
|
48
|
-
Tempfile.open(["radoc", ".jpg"]) do |f|
|
|
49
|
-
f.binmode
|
|
50
|
-
f.write(Base64.strict_decode64(imgdata))
|
|
51
|
-
f.rewind
|
|
52
|
-
ext = Marcel::MimeType.for(f).sub(%r{^[^/]+/}, "")
|
|
53
|
-
[ext, f.path]
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def to_coradoc(node, _state = {})
|
|
58
|
-
id = node["id"]
|
|
59
|
-
alt = node["alt"]
|
|
60
|
-
src = node["src"]
|
|
61
|
-
width = node["width"]
|
|
62
|
-
height = node["height"]
|
|
63
|
-
|
|
64
|
-
title = extract_title(node)
|
|
65
|
-
|
|
66
|
-
if ReverseAdoc.config.external_images
|
|
67
|
-
# puts "external image conversion #{id}, #{src}"
|
|
68
|
-
src = datauri2file(src)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
attributes = Coradoc::Element::AttributeList.new
|
|
72
|
-
# attributes.add_named("id", id) if id
|
|
73
|
-
if alt # && !alt.to_s.empty?
|
|
74
|
-
attributes.add_positional(alt)
|
|
75
|
-
elsif width || height
|
|
76
|
-
attributes.add_positional("\"\"")
|
|
77
|
-
end
|
|
78
|
-
# attributes.add_named("title", title) if title
|
|
79
|
-
attributes.add_positional(width) if width
|
|
80
|
-
attributes.add_positional(height) if height
|
|
81
|
-
|
|
82
|
-
Coradoc::Element::Image::BlockImage.new(title, id, src,
|
|
83
|
-
attributes: attributes)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def convert(node, state = {})
|
|
87
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
register :img, Img.new
|
|
92
|
-
end
|
|
93
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
module ReverseAdoc
|
|
2
|
-
module Converters
|
|
3
|
-
class Li < Base
|
|
4
|
-
def to_coradoc(node, state = {})
|
|
5
|
-
id = node["id"]
|
|
6
|
-
content = treat_children_coradoc(node, state)
|
|
7
|
-
Coradoc::Element::ListItem.new(content, id: id)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def convert(node, state = {})
|
|
11
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
register :li, Li.new
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module ReverseAdoc
|
|
2
|
-
module Converters
|
|
3
|
-
class Mark < Base
|
|
4
|
-
def to_coradoc(node, state = {})
|
|
5
|
-
content = treat_children(node, state.merge(already_strong: true))
|
|
6
|
-
|
|
7
|
-
if content.strip.empty? || state[:already_strong]
|
|
8
|
-
return content
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
Coradoc::Element::Inline::Highlight.new(content, constrained?(node))
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def convert(node, state = {})
|
|
15
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
register :mark, Mark.new
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# Unless run with ReverseAdoc.config.mathml2asciimath,
|
|
2
|
-
# this is cheating: we're injecting MathML into Asciidoctor, but
|
|
3
|
-
# Asciidoctor only understands AsciiMath or LaTeX
|
|
4
|
-
|
|
5
|
-
require "mathml2asciimath"
|
|
6
|
-
|
|
7
|
-
module ReverseAdoc
|
|
8
|
-
module Converters
|
|
9
|
-
class Math < Base
|
|
10
|
-
# FIXIT
|
|
11
|
-
def to_coradoc(node, state = {})
|
|
12
|
-
convert(node, state)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def convert(node, _state = {})
|
|
16
|
-
stem = node.to_s.gsub(/\n/, " ")
|
|
17
|
-
stem = MathML2AsciiMath.m2a(stem) if ReverseAdoc.config.mathml2asciimath
|
|
18
|
-
unless stem.nil?
|
|
19
|
-
stem = stem.gsub(/\[/, "\\[").gsub(/\]/, "\\]").gsub(
|
|
20
|
-
/\(\(([^\)]+)\)\)/, "(\\1)"
|
|
21
|
-
)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# TODO: This is to be done in Coradoc
|
|
25
|
-
" stem:[" << stem << "] "
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
register :math, Math.new
|
|
30
|
-
end
|
|
31
|
-
end
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
module ReverseAdoc
|
|
2
|
-
module Converters
|
|
3
|
-
class Ol < Base
|
|
4
|
-
# FIXIT
|
|
5
|
-
def to_coradoc(node, state = {})
|
|
6
|
-
# convert(node, state)
|
|
7
|
-
id = node["id"]
|
|
8
|
-
ol_count = state.fetch(:ol_count, 0) + 1
|
|
9
|
-
attrs = ol_attrs(node)
|
|
10
|
-
items = treat_children_coradoc(node, state.merge(ol_count: ol_count))
|
|
11
|
-
|
|
12
|
-
options = {}.tap do |hash|
|
|
13
|
-
hash[:id] = id
|
|
14
|
-
hash[:ol_count] = ol_count
|
|
15
|
-
hash[:attrs] = attrs
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
case get_list_type(node, state)
|
|
19
|
-
when :ordered
|
|
20
|
-
Coradoc::Element::List::Ordered.new(items, options)
|
|
21
|
-
when :unordered
|
|
22
|
-
Coradoc::Element::List::Unordered.new(items, options)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def convert(node, state = {})
|
|
27
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def get_list_type(node, _state)
|
|
31
|
-
case node.name
|
|
32
|
-
when "ol"
|
|
33
|
-
:ordered
|
|
34
|
-
when "ul"
|
|
35
|
-
:unordered
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def number_style(node)
|
|
40
|
-
case node["style"]
|
|
41
|
-
when "1" then "arabic"
|
|
42
|
-
when "A" then "upperalpha"
|
|
43
|
-
when "a" then "loweralpha"
|
|
44
|
-
when "I" then "upperroman"
|
|
45
|
-
when "i" then "lowerroman"
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def ol_attrs(node)
|
|
50
|
-
attrs = Coradoc::Element::AttributeList.new
|
|
51
|
-
style = number_style(node)
|
|
52
|
-
attrs.add_positional(style) if style
|
|
53
|
-
attrs.add_positional("%reversed") if node["reversed"]
|
|
54
|
-
attrs.add_named("start", node["start"]) if node["start"]
|
|
55
|
-
attrs.add_named("type", node["type"]) if node["type"]
|
|
56
|
-
attrs
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
register :ol, Ol.new
|
|
61
|
-
register :ul, Ol.new
|
|
62
|
-
register :dir, Ol.new
|
|
63
|
-
end
|
|
64
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
module ReverseAdoc
|
|
2
|
-
module Converters
|
|
3
|
-
class P < Base
|
|
4
|
-
def to_coradoc(node, state = {})
|
|
5
|
-
id = node["id"]
|
|
6
|
-
content = treat_children_coradoc(node, state)
|
|
7
|
-
|
|
8
|
-
options = {}.tap do |hash|
|
|
9
|
-
hash[:id] = id if id
|
|
10
|
-
hash[:tdsinglepara] = true if state[:tdsinglepara]
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
Coradoc::Element::Paragraph.new(content, options)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def convert(node, state = {})
|
|
17
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
register :p, P.new
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
module ReverseAdoc
|
|
2
|
-
module Converters
|
|
3
|
-
class Pre < Base
|
|
4
|
-
def to_coradoc(node, state = {})
|
|
5
|
-
id = node["id"]
|
|
6
|
-
lang = language(node)
|
|
7
|
-
content = treat_children(node, state)
|
|
8
|
-
|
|
9
|
-
unless lang
|
|
10
|
-
return Coradoc::Element::Block::Literal.new(
|
|
11
|
-
nil,
|
|
12
|
-
lines: content,
|
|
13
|
-
id: id,
|
|
14
|
-
)
|
|
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))
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
private
|
|
30
|
-
|
|
31
|
-
def treat(node, _state)
|
|
32
|
-
return "\n" if node.name == "br"
|
|
33
|
-
|
|
34
|
-
prefix = postfix = "\n\n" if node.name == "p"
|
|
35
|
-
|
|
36
|
-
"#{prefix}#{node.text}#{postfix}"
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def language(node)
|
|
40
|
-
lang = language_from_highlight_class(node)
|
|
41
|
-
lang || language_from_confluence_class(node)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def language_from_highlight_class(node)
|
|
45
|
-
node.parent["class"].to_s[/highlight-([a-zA-Z0-9]+)/, 1]
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def language_from_confluence_class(node)
|
|
49
|
-
node["class"].to_s[/brush:\s?(:?.*);/, 1]
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
register :pre, Pre.new
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
module ReverseAdoc
|
|
2
|
-
module Converters
|
|
3
|
-
class Q < Base
|
|
4
|
-
def to_coradoc(node, state = {})
|
|
5
|
-
content = treat_children(node, state)
|
|
6
|
-
Coradoc::Element::Inline::Quotation.new(content)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def convert(node, state = {})
|
|
10
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
register :q, Q.new
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
module ReverseAdoc
|
|
2
|
-
module Converters
|
|
3
|
-
class Strong < Base
|
|
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
|
|
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))
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
register :strong, Strong.new
|
|
50
|
-
register :b, Strong.new
|
|
51
|
-
end
|
|
52
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
module ReverseAdoc
|
|
2
|
-
module Converters
|
|
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
|
-
|
|
9
|
-
def convert(node, state = {})
|
|
10
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
register :sub, Sub.new
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
module ReverseAdoc
|
|
2
|
-
module Converters
|
|
3
|
-
class Sup < Base
|
|
4
|
-
def to_coradoc(node, state = {})
|
|
5
|
-
content = treat_children(node, state)
|
|
6
|
-
Coradoc::Element::Inline::Superscript.new(content)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def convert(node, state = {})
|
|
10
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
register :sup, Sup.new
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
module ReverseAdoc
|
|
2
|
-
module Converters
|
|
3
|
-
class Table < Base
|
|
4
|
-
def to_coradoc(node, state = {})
|
|
5
|
-
id = node["id"]
|
|
6
|
-
title = extract_title(node)
|
|
7
|
-
attrs = style(node)
|
|
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))
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def extract_title(node)
|
|
17
|
-
title = node.at("./caption")
|
|
18
|
-
return "" if title.nil?
|
|
19
|
-
|
|
20
|
-
treat_children(title, {})
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def frame(node)
|
|
24
|
-
case node["frame"]
|
|
25
|
-
when "void"
|
|
26
|
-
"none"
|
|
27
|
-
when "hsides"
|
|
28
|
-
"topbot"
|
|
29
|
-
when "vsides"
|
|
30
|
-
"sides"
|
|
31
|
-
when "box", "border"
|
|
32
|
-
"all"
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def rules(node)
|
|
37
|
-
case node["rules"]
|
|
38
|
-
when "all"
|
|
39
|
-
"all"
|
|
40
|
-
when "rows"
|
|
41
|
-
"rows"
|
|
42
|
-
when "cols"
|
|
43
|
-
"cols"
|
|
44
|
-
when "none"
|
|
45
|
-
"none"
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def style(node)
|
|
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
|
-
|
|
54
|
-
frame_attr = frame(node)
|
|
55
|
-
attrs.add_named("frame", frame_attr) if frame_attr
|
|
56
|
-
|
|
57
|
-
rules_attr = rules(node)
|
|
58
|
-
attrs.add_named("rules", rules_attr) if rules_attr
|
|
59
|
-
|
|
60
|
-
# This line should be removed.
|
|
61
|
-
return "" if attrs.empty?
|
|
62
|
-
|
|
63
|
-
attrs
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
register :table, Table.new
|
|
68
|
-
end
|
|
69
|
-
end
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
module ReverseAdoc
|
|
2
|
-
module Converters
|
|
3
|
-
class Td < Base
|
|
4
|
-
def to_coradoc(node, state = {})
|
|
5
|
-
# convert(node, state)
|
|
6
|
-
id = node["id"]
|
|
7
|
-
colrowattr = colrow(node["colspan"], node["rowspan"])
|
|
8
|
-
alignattr = alignstyle(node)
|
|
9
|
-
style = cellstyle(node)
|
|
10
|
-
|
|
11
|
-
singlepara = node.elements.size == 1 && node.elements.first.name == "p"
|
|
12
|
-
state[:tdsinglepara] = singlepara if singlepara
|
|
13
|
-
|
|
14
|
-
adoccell = node.at(".//ul | .//ol | .//pre | .//blockquote | .//br | .//hr") ||
|
|
15
|
-
node.at(".//p") && !singlepara
|
|
16
|
-
|
|
17
|
-
style = "a" if adoccell
|
|
18
|
-
delim = adoccell ? "\n" : " "
|
|
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))
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def cellstyle(_node)
|
|
37
|
-
""
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def colrow(colspan, rowspan)
|
|
41
|
-
if colspan && rowspan && colspan != "1" && rowspan != "1"
|
|
42
|
-
"#{colspan}.#{rowspan}+"
|
|
43
|
-
elsif colspan && colspan != "1"
|
|
44
|
-
"#{colspan}+"
|
|
45
|
-
elsif rowspan && rowspan != "1"
|
|
46
|
-
".#{rowspan}+"
|
|
47
|
-
else
|
|
48
|
-
""
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def alignstyle(node)
|
|
53
|
-
align = node["align"]
|
|
54
|
-
valign = node["valign"]
|
|
55
|
-
a = case align
|
|
56
|
-
when "left" then "<"
|
|
57
|
-
when "center" then "^"
|
|
58
|
-
when "right" then ">"
|
|
59
|
-
else
|
|
60
|
-
""
|
|
61
|
-
end
|
|
62
|
-
v = case valign
|
|
63
|
-
when "top" then "<"
|
|
64
|
-
when "middle" then "^"
|
|
65
|
-
when "bottom" then ">"
|
|
66
|
-
else
|
|
67
|
-
""
|
|
68
|
-
end
|
|
69
|
-
if align && valign
|
|
70
|
-
"#{a}.#{v}"
|
|
71
|
-
elsif align
|
|
72
|
-
a
|
|
73
|
-
elsif valign
|
|
74
|
-
".#{v}"
|
|
75
|
-
else
|
|
76
|
-
""
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
register :td, Td.new
|
|
82
|
-
end
|
|
83
|
-
end
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
module ReverseAdoc
|
|
2
|
-
module Converters
|
|
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
|
-
|
|
10
|
-
def convert(node, state = {})
|
|
11
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
def treat_empty(node, state)
|
|
17
|
-
parent = node.parent.name.to_sym
|
|
18
|
-
if %i[ol ul].include?(parent) # Otherwise the identation is broken
|
|
19
|
-
""
|
|
20
|
-
elsif state[:tdsinglepara]
|
|
21
|
-
""
|
|
22
|
-
elsif node.text == " " # Regular whitespace text node
|
|
23
|
-
" "
|
|
24
|
-
else
|
|
25
|
-
""
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def treat_text(node)
|
|
30
|
-
text = node.text
|
|
31
|
-
text = preserve_nbsp(text)
|
|
32
|
-
text = remove_border_newlines(text)
|
|
33
|
-
text = remove_inner_newlines(text)
|
|
34
|
-
text = escape_keychars(text)
|
|
35
|
-
|
|
36
|
-
text = preserve_keychars_within_backticks(text)
|
|
37
|
-
escape_links(text)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def preserve_nbsp(text)
|
|
41
|
-
text.gsub(/\u00A0/, " ")
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def escape_links(text)
|
|
45
|
-
text.gsub(/<<([^>]*)>>/, "\\<<\\1>>")
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def remove_border_newlines(text)
|
|
49
|
-
text.gsub(/\A\n+/, "").gsub(/\n+\z/, "")
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def remove_inner_newlines(text)
|
|
53
|
-
text.tr("\n\t", " ").squeeze(" ")
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def preserve_keychars_within_backticks(text)
|
|
57
|
-
text.gsub(/`.*?`/) do |match|
|
|
58
|
-
match.gsub('\_', "_").gsub('\*', "*")
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
register :text, Text.new
|
|
64
|
-
end
|
|
65
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module ReverseAdoc
|
|
2
|
-
module Converters
|
|
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
|
-
|
|
10
|
-
def convert(node, state = {})
|
|
11
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def table_header_row?(node)
|
|
15
|
-
# node.element_children.all? {|child| child.name.to_sym == :th}
|
|
16
|
-
node.previous_element.nil?
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
register :tr, Tr.new
|
|
21
|
-
end
|
|
22
|
-
end
|