reverse_adoc 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/README.adoc +4 -294
- data/Rakefile +2 -13
- data/reverse_adoc.gemspec +2 -20
- metadata +5 -246
- data/.editorconfig +0 -15
- data/.github/workflows/rake.yml +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/lib/reverse_adoc/version.rb +0 -3
- data/lib/reverse_adoc.rb +0 -27
- 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/spec_helper.rb +0 -25
- data/spec/support/shell_helpers.rb +0 -15
@@ -1,56 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Code < Base
|
4
|
-
def to_coradoc(node, state = {})
|
5
|
-
content = treat_children_coradoc(node, state)
|
6
|
-
|
7
|
-
if Coradoc::Generator.gen_adoc(content).strip.empty?
|
8
|
-
return ""
|
9
|
-
end
|
10
|
-
|
11
|
-
if node_has_ancestor?(node, ["code", "tt", "kbd", "samp", "var"])
|
12
|
-
return content
|
13
|
-
end
|
14
|
-
|
15
|
-
node.text =~ /^(\s+)/
|
16
|
-
leading_whitespace = $1
|
17
|
-
has_leading_whitespace = !leading_whitespace.nil?
|
18
|
-
|
19
|
-
if has_leading_whitespace
|
20
|
-
first_text = node.at_xpath("./text()[1]")
|
21
|
-
first_text.replace(first_text.text.lstrip)
|
22
|
-
leading_whitespace = " "
|
23
|
-
end
|
24
|
-
|
25
|
-
node.text =~ /(\s+)$/
|
26
|
-
trailing_whitespace = $1
|
27
|
-
has_trailing_whitespace = !trailing_whitespace.nil?
|
28
|
-
|
29
|
-
if has_trailing_whitespace
|
30
|
-
last_text = node.at_xpath("./text()[last()]")
|
31
|
-
last_text.replace(last_text.text.rstrip)
|
32
|
-
trailing_whitespace = " "
|
33
|
-
end
|
34
|
-
|
35
|
-
u_before = unconstrained_before?(node)
|
36
|
-
u_after = unconstrained_after?(node)
|
37
|
-
u = !((!u_before || has_leading_whitespace) && (!u_after || has_trailing_whitespace))
|
38
|
-
e = Coradoc::Element::Inline::Monospace.new(
|
39
|
-
Coradoc::Element::TextElement.new(content), u
|
40
|
-
)
|
41
|
-
|
42
|
-
[leading_whitespace, e, trailing_whitespace]
|
43
|
-
end
|
44
|
-
|
45
|
-
def convert(node, state = {})
|
46
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
register :code, Code.new
|
51
|
-
register :tt, Code.new
|
52
|
-
register :kbd, Code.new
|
53
|
-
register :samp, Code.new
|
54
|
-
register :var, Code.new
|
55
|
-
end
|
56
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Div < Base
|
4
|
-
def to_coradoc(node, state = {})
|
5
|
-
id = node["id"]
|
6
|
-
contents = treat_children_coradoc(node, state)
|
7
|
-
Coradoc::Element::Section.new(nil, id: id, contents: contents)
|
8
|
-
end
|
9
|
-
|
10
|
-
def convert(node, state = {})
|
11
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
register :div, Div.new
|
16
|
-
register :article, Div.new
|
17
|
-
end
|
18
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Drop < Base
|
4
|
-
def to_coradoc(node, state = {})
|
5
|
-
convert(node, state)
|
6
|
-
end
|
7
|
-
|
8
|
-
def convert(_node, _state = {})
|
9
|
-
""
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
register :caption, Drop.new
|
14
|
-
register :figcaption, Drop.new
|
15
|
-
register :title, Drop.new
|
16
|
-
register :link, Drop.new
|
17
|
-
register :style, Drop.new
|
18
|
-
register :meta, Drop.new
|
19
|
-
register :script, Drop.new
|
20
|
-
register :comment, Drop.new
|
21
|
-
end
|
22
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Em < Base
|
4
|
-
def to_coradoc(node, state = {})
|
5
|
-
content = treat_children_coradoc(node,
|
6
|
-
state.merge(already_italic: true))
|
7
|
-
|
8
|
-
if Coradoc::Generator.gen_adoc(content).strip.empty?
|
9
|
-
return ""
|
10
|
-
end
|
11
|
-
|
12
|
-
if node_has_ancestor?(node, ["em", "i", "cite"])
|
13
|
-
return content
|
14
|
-
end
|
15
|
-
|
16
|
-
node.text =~ /^(\s+)/
|
17
|
-
leading_whitespace = $1
|
18
|
-
has_leading_whitespace = !leading_whitespace.nil?
|
19
|
-
|
20
|
-
if has_leading_whitespace
|
21
|
-
first_text = node.at_xpath("./text()[1]")
|
22
|
-
first_text.replace(first_text.text.lstrip)
|
23
|
-
leading_whitespace = " "
|
24
|
-
end
|
25
|
-
|
26
|
-
node.text =~ /(\s+)$/
|
27
|
-
trailing_whitespace = $1
|
28
|
-
has_trailing_whitespace = !trailing_whitespace.nil?
|
29
|
-
|
30
|
-
if has_trailing_whitespace
|
31
|
-
last_text = node.at_xpath("./text()[last()]")
|
32
|
-
last_text.replace(last_text.text.rstrip)
|
33
|
-
trailing_whitespace = " "
|
34
|
-
end
|
35
|
-
|
36
|
-
u_before = unconstrained_before?(node)
|
37
|
-
u_after = unconstrained_after?(node)
|
38
|
-
u = !((!u_before || has_leading_whitespace) && (!u_after || has_trailing_whitespace))
|
39
|
-
e = Coradoc::Element::Inline::Italic.new(
|
40
|
-
Coradoc::Element::TextElement.new(content), u
|
41
|
-
)
|
42
|
-
|
43
|
-
[leading_whitespace, e, trailing_whitespace]
|
44
|
-
end
|
45
|
-
|
46
|
-
def convert(node, state = {})
|
47
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
register :em, Em.new
|
52
|
-
register :i, Em.new
|
53
|
-
register :cite, Em.new
|
54
|
-
end
|
55
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Figure < Base
|
4
|
-
def to_coradoc(node, state = {})
|
5
|
-
id = node["id"]
|
6
|
-
title = extract_title(node)
|
7
|
-
content = treat_children_coradoc(node, state)
|
8
|
-
Coradoc::Element::Block::Example.new(title, lines: content, id: id)
|
9
|
-
end
|
10
|
-
|
11
|
-
def convert(node, state = {})
|
12
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
13
|
-
end
|
14
|
-
|
15
|
-
def extract_title(node)
|
16
|
-
title = node.at("./figcaption")
|
17
|
-
return "" if title.nil?
|
18
|
-
|
19
|
-
treat_children_coradoc(title, {})
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
register :figure, Figure.new
|
24
|
-
end
|
25
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class H < Base
|
4
|
-
def to_coradoc(node, state = {})
|
5
|
-
id = node["id"]
|
6
|
-
internal_anchor = treat_children_anchors(node, state)
|
7
|
-
|
8
|
-
if id.to_s.empty? && internal_anchor.size.positive?
|
9
|
-
id = internal_anchor.first.id
|
10
|
-
end
|
11
|
-
|
12
|
-
level = node.name[/\d/].to_i
|
13
|
-
content = treat_children_no_anchors(node, state)
|
14
|
-
|
15
|
-
Coradoc::Element::Title.new(content, level, id: id)
|
16
|
-
end
|
17
|
-
|
18
|
-
def convert(node, state = {})
|
19
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
20
|
-
end
|
21
|
-
|
22
|
-
def treat_children_no_anchors(node, state)
|
23
|
-
node.children.reject { |a| a.name == "a" }.inject([]) do |memo, child|
|
24
|
-
memo << treat_coradoc(child, state)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def treat_children_anchors(node, state)
|
29
|
-
node.children.select { |a| a.name == "a" }.inject([]) do |memo, child|
|
30
|
-
memo << treat_coradoc(child, state)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
register :h1, H.new
|
36
|
-
register :h2, H.new
|
37
|
-
register :h3, H.new
|
38
|
-
register :h4, H.new
|
39
|
-
register :h5, H.new
|
40
|
-
register :h6, H.new
|
41
|
-
end
|
42
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Head < Base
|
4
|
-
def to_coradoc(node, _state = {})
|
5
|
-
title = extract_title(node)
|
6
|
-
Coradoc::Element::Header.new(title)
|
7
|
-
end
|
8
|
-
|
9
|
-
def convert(node, state = {})
|
10
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
11
|
-
end
|
12
|
-
|
13
|
-
def extract_title(node)
|
14
|
-
title = node.at("./title")
|
15
|
-
return "(???)" if title.nil?
|
16
|
-
|
17
|
-
title.text
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
register :head, Head.new
|
22
|
-
end
|
23
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Hr < Base
|
4
|
-
def to_coradoc(_node, _state = {})
|
5
|
-
Coradoc::Element::Break::ThematicBreak.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def convert(node, state = {})
|
9
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
register :hr, Hr.new
|
14
|
-
end
|
15
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Ignore < Base
|
4
|
-
def to_coradoc(node, state = {})
|
5
|
-
convert(node, state)
|
6
|
-
end
|
7
|
-
|
8
|
-
def convert(_node, _state = {})
|
9
|
-
"" # noop
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
register :colgroup, Ignore.new
|
14
|
-
register :col, Ignore.new
|
15
|
-
end
|
16
|
-
end
|
@@ -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
|