reverse_adoc 0.2.8 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +15 -0
- data/.github/workflows/rake.yml +32 -0
- data/.github/workflows/release.yml +45 -0
- data/.gitignore +10 -0
- data/.hound.yml +3 -1
- data/.rubocop.yml +7 -7
- data/Gemfile +1 -1
- data/README.adoc +6 -33
- data/Rakefile +1 -1
- data/exe/reverse_adoc +70 -0
- data/{bin → exe}/w2a +15 -15
- data/lib/reverse_adoc.rb +27 -0
- data/lib/{reverse_asciidoctor → reverse_adoc}/cleaner.rb +28 -27
- data/lib/{reverse_asciidoctor → reverse_adoc}/config.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters.rb +6 -6
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/a.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/aside.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/audio.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/base.rb +5 -3
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/blockquote.rb +2 -2
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/br.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/bypass.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/code.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/div.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/drop.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/em.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/figure.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/h.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/head.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/hr.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/ignore.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/img.rb +9 -9
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/li.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/mark.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/math.rb +3 -3
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/ol.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/p.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/pass_through.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/pre.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/q.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/strong.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/sub.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/sup.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/table.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/td.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/text.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/th.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/tr.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/video.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/errors.rb +1 -1
- data/lib/reverse_adoc/html_converter.rb +56 -0
- data/lib/reverse_adoc/version.rb +3 -0
- data/reverse_adoc.gemspec +18 -15
- data/spec/assets/escapables.html +2 -0
- data/spec/bin/reverse_adoc_spec.rb +2 -2
- data/spec/bin/w2a_spec.rb +7 -7
- data/spec/components/anchors_spec.rb +2 -2
- data/spec/components/basic_spec.rb +3 -3
- data/spec/components/code_spec.rb +4 -5
- data/spec/components/escapables_spec.rb +10 -2
- data/spec/components/from_the_wild_spec.rb +2 -2
- data/spec/components/html_fragment_spec.rb +2 -3
- data/spec/components/lists_spec.rb +2 -2
- data/spec/components/paragraphs_spec.rb +2 -2
- data/spec/components/quotation_spec.rb +2 -2
- data/spec/components/tables_spec.rb +2 -2
- data/spec/components/unknown_tags_spec.rb +9 -10
- data/spec/lib/{reverse_asciidoctor_spec.rb → reverse_adoc.rb} +17 -17
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/cleaner_spec.rb +4 -4
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/config_spec.rb +5 -5
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/aside_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/audio_spec.rb +2 -3
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/blockquote_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/br_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/code_spec.rb +2 -3
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/div_spec.rb +2 -3
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/figure_spec.rb +2 -3
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/img_spec.rb +2 -3
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/li_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/mark_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/p_spec.rb +2 -3
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/pre_spec.rb +2 -3
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/q_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/strong_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/text_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/video_spec.rb +2 -3
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters_spec.rb +5 -5
- data/spec/spec_helper.rb +3 -3
- metadata +123 -125
- data/.github/workflows/macos.yml +0 -31
- data/.github/workflows/ubuntu.yml +0 -33
- data/.github/workflows/windows.yml +0 -37
- data/Gemfile.lock +0 -84
- data/bin/reverse_adoc +0 -74
- data/lib/reverse_asciidoctor.rb +0 -30
- data/lib/reverse_asciidoctor/converters/example.rb +0 -17
- data/lib/reverse_asciidoctor/converters/express_ref.rb +0 -12
- data/lib/reverse_asciidoctor/converters/ext_description.rb +0 -16
- data/lib/reverse_asciidoctor/converters/ext_descriptions.rb +0 -12
- data/lib/reverse_asciidoctor/converters/note.rb +0 -17
- data/lib/reverse_asciidoctor/html_converter.rb +0 -56
- data/lib/reverse_asciidoctor/smrl_description_converter.rb +0 -45
- data/lib/reverse_asciidoctor/version.rb +0 -3
- data/spec/lib/reverse_asciidoctor/converters/example_spec.rb +0 -22
- data/spec/lib/reverse_asciidoctor/converters/express_ref_spec.rb +0 -14
- data/spec/lib/reverse_asciidoctor/converters/ext_description_spec.rb +0 -20
- data/spec/lib/reverse_asciidoctor/converters/ext_descriptions_spec.rb +0 -13
- data/spec/lib/reverse_asciidoctor/converters/note_spec.rb +0 -22
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
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
|
19
|
+
case ReverseAdoc.config.unknown_tags.to_sym
|
20
20
|
when :pass_through
|
21
|
-
|
21
|
+
ReverseAdoc::Converters::PassThrough.new
|
22
22
|
when :drop
|
23
|
-
|
23
|
+
ReverseAdoc::Converters::Drop.new
|
24
24
|
when :bypass
|
25
|
-
|
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 #{
|
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,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Base
|
4
4
|
def treat_children(node, state)
|
@@ -8,11 +8,13 @@ module ReverseAsciidoctor
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def treat(node, state)
|
11
|
-
|
11
|
+
ReverseAdoc::Converters.lookup(node.name).convert(node, state)
|
12
12
|
end
|
13
13
|
|
14
14
|
def escape_keychars(string)
|
15
|
-
|
15
|
+
subs = { '*' => '\*', '_' => '\_' }
|
16
|
+
string
|
17
|
+
.gsub(/((?<=\s)[\*_]+)|[\*_]+(?=\s)/) { |n| n.chars.map { |char| subs[char] }.join }
|
16
18
|
end
|
17
19
|
|
18
20
|
def extract_title(node)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
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 =
|
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
|
@@ -2,27 +2,27 @@ require "fileutils"
|
|
2
2
|
require "pathname"
|
3
3
|
require "tempfile"
|
4
4
|
require "base64"
|
5
|
-
require "
|
5
|
+
require "marcel"
|
6
6
|
|
7
|
-
module
|
7
|
+
module ReverseAdoc
|
8
8
|
module Converters
|
9
9
|
class Img < Base
|
10
10
|
|
11
11
|
def image_number
|
12
12
|
sprintf(
|
13
|
-
|
14
|
-
|
13
|
+
ReverseAdoc.config.image_counter_pattern,
|
14
|
+
ReverseAdoc.config.image_counter
|
15
15
|
)
|
16
16
|
end
|
17
17
|
|
18
18
|
def image_number_increment
|
19
|
-
|
19
|
+
ReverseAdoc.config.image_counter += 1
|
20
20
|
end
|
21
21
|
|
22
22
|
def datauri2file(src)
|
23
23
|
%r{^data:image/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ src
|
24
24
|
|
25
|
-
dest_dir = Pathname.new(
|
25
|
+
dest_dir = Pathname.new(ReverseAdoc.config.destination).dirname
|
26
26
|
images_dir = dest_dir + 'images'
|
27
27
|
FileUtils.mkdir_p(images_dir)
|
28
28
|
|
@@ -42,7 +42,7 @@ module ReverseAsciidoctor
|
|
42
42
|
return copy_temp_file(imgdata) if imgdata
|
43
43
|
|
44
44
|
ext = File.extname(src).strip.downcase[1..-1]
|
45
|
-
[ext, Pathname.new(
|
45
|
+
[ext, Pathname.new(ReverseAdoc.config.sourcedir) + src]
|
46
46
|
end
|
47
47
|
|
48
48
|
def copy_temp_file(imgdata)
|
@@ -50,7 +50,7 @@ module ReverseAsciidoctor
|
|
50
50
|
f.binmode
|
51
51
|
f.write(Base64.strict_decode64(imgdata))
|
52
52
|
f.rewind
|
53
|
-
ext =
|
53
|
+
ext = Marcel::MimeType.for(f).sub(%r{^[^/]+/}, "")
|
54
54
|
[ext, f.path]
|
55
55
|
end
|
56
56
|
end
|
@@ -64,7 +64,7 @@ module ReverseAsciidoctor
|
|
64
64
|
anchor = id ? "[[#{id}]]\n" : ""
|
65
65
|
title = extract_title(node)
|
66
66
|
|
67
|
-
if
|
67
|
+
if ReverseAdoc.config.external_images
|
68
68
|
# puts "external image conversion #{id}, #{src}"
|
69
69
|
src = datauri2file(src)
|
70
70
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
# Unless run with
|
1
|
+
# Unless run with ReverseAdoc.config.mathml2asciimath,
|
2
2
|
# this is cheating: we're injecting MathML into Asciidoctor, but
|
3
3
|
# Asciidoctor only understands AsciiMath or LaTeX
|
4
4
|
|
5
5
|
require "mathml2asciimath"
|
6
6
|
|
7
|
-
module
|
7
|
+
module ReverseAdoc
|
8
8
|
module Converters
|
9
9
|
class Math < Base
|
10
10
|
def convert(node, state = {})
|
11
11
|
stem = node.to_s.gsub(/\n/, " ")
|
12
|
-
stem = MathML2AsciiMath.m2a(stem) if
|
12
|
+
stem = MathML2AsciiMath.m2a(stem) if ReverseAdoc.config.mathml2asciimath
|
13
13
|
stem = stem.gsub(/\[/, "\\[").gsub(/\]/, "\\]").gsub(/\(\(([^\)]+)\)\)/, "(\\1)") unless stem.nil?
|
14
14
|
" stem:[" << stem << "] "
|
15
15
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
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"
|
36
|
+
|
37
|
+
module ReverseAdoc
|
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
|
46
|
+
end
|
47
|
+
|
48
|
+
root || (return "")
|
49
|
+
|
50
|
+
ReverseAdoc.config.with(options) do
|
51
|
+
result = ReverseAdoc::Converters.lookup(root.name).convert(root)
|
52
|
+
ReverseAdoc.cleaner.tidy(result)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|