reverse_adoc 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/macos.yml +8 -1
- data/.github/workflows/ubuntu.yml +8 -1
- data/.github/workflows/windows.yml +8 -1
- data/Gemfile +1 -1
- data/README.adoc +5 -5
- data/Rakefile +1 -1
- data/bin/reverse_adoc +18 -18
- data/bin/w2a +15 -15
- data/lib/{reverse_asciidoctor.rb → reverse_adoc.rb} +9 -9
- data/lib/{reverse_asciidoctor → reverse_adoc}/cleaner.rb +4 -4
- 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 +2 -2
- 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/example.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/express_ref.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/ext_description.rb +1 -1
- data/lib/{reverse_asciidoctor → reverse_adoc}/converters/ext_descriptions.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 +7 -7
- 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/note.rb +1 -1
- 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/smrl_description_converter.rb +45 -0
- data/lib/reverse_adoc/version.rb +3 -0
- data/reverse_adoc.gemspec +2 -2
- data/spec/components/anchors_spec.rb +2 -2
- data/spec/components/basic_spec.rb +2 -2
- data/spec/components/code_spec.rb +4 -4
- data/spec/components/escapables_spec.rb +2 -2
- data/spec/components/from_the_wild_spec.rb +2 -2
- data/spec/components/html_fragment_spec.rb +2 -2
- 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 -9
- 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 -2
- 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 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/div_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/example_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/express_ref_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/ext_description_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/ext_descriptions_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/figure_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/img_spec.rb +2 -2
- 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/note_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/p_spec.rb +2 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/pre_spec.rb +2 -2
- 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 -2
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters_spec.rb +5 -5
- data/spec/spec_helper.rb +3 -3
- metadata +100 -100
- 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
@@ -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,7 +8,7 @@ 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)
|
@@ -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
|
@@ -4,25 +4,25 @@ require "tempfile"
|
|
4
4
|
require "base64"
|
5
5
|
require "mimemagic"
|
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)
|
@@ -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
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'reverse_adoc/converters/a'
|
4
|
+
require 'reverse_adoc/converters/blockquote'
|
5
|
+
require 'reverse_adoc/converters/bypass'
|
6
|
+
require 'reverse_adoc/converters/br'
|
7
|
+
require 'reverse_adoc/converters/code'
|
8
|
+
require 'reverse_adoc/converters/drop'
|
9
|
+
require 'reverse_adoc/converters/em'
|
10
|
+
require 'reverse_adoc/converters/example'
|
11
|
+
require 'reverse_adoc/converters/ext_descriptions'
|
12
|
+
require 'reverse_adoc/converters/ext_description'
|
13
|
+
require 'reverse_adoc/converters/express_ref'
|
14
|
+
require 'reverse_adoc/converters/head'
|
15
|
+
require 'reverse_adoc/converters/hr'
|
16
|
+
require 'reverse_adoc/converters/ignore'
|
17
|
+
require 'reverse_adoc/converters/note'
|
18
|
+
require 'reverse_adoc/converters/p'
|
19
|
+
require 'reverse_adoc/converters/pass_through'
|
20
|
+
require 'reverse_adoc/converters/q'
|
21
|
+
require 'reverse_adoc/converters/strong'
|
22
|
+
require 'reverse_adoc/converters/sup'
|
23
|
+
require 'reverse_adoc/converters/sub'
|
24
|
+
require 'reverse_adoc/converters/text'
|
25
|
+
|
26
|
+
module ReverseAdoc
|
27
|
+
class SmrlDescriptionConverter
|
28
|
+
def self.convert(input, options = {})
|
29
|
+
root = if input.is_a?(String)
|
30
|
+
then Nokogiri::XML(input).root
|
31
|
+
elsif input.is_a?(Nokogiri::XML::Document)
|
32
|
+
then input.root
|
33
|
+
elsif input.is_a?(Nokogiri::XML::Node)
|
34
|
+
then input
|
35
|
+
end
|
36
|
+
|
37
|
+
root || (return '')
|
38
|
+
|
39
|
+
ReverseAdoc.config.with(options) do
|
40
|
+
result = ReverseAdoc::Converters.lookup(root.name).convert(root)
|
41
|
+
ReverseAdoc.cleaner.tidy(result)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|