reverse_adoc 0.2.5 → 0.2.10
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 +19 -5
- data/.github/workflows/ubuntu.yml +18 -5
- data/.github/workflows/windows.yml +20 -6
- data/Gemfile +2 -2
- data/Gemfile.lock +85 -0
- data/README.adoc +12 -25
- data/Rakefile +1 -1
- data/bin/reverse_adoc +20 -17
- data/bin/w2a +18 -31
- data/lib/reverse_adoc.rb +27 -0
- data/lib/{reverse_asciidoctor → reverse_adoc}/cleaner.rb +27 -4
- data/lib/{reverse_asciidoctor → reverse_adoc}/config.rb +3 -2
- 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/figure.rb +1 -1
- data/lib/reverse_adoc/converters/h.rb +34 -0
- 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 +27 -29
- 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 +4 -2
- data/spec/assets/anchors.html +2 -0
- data/spec/assets/external_images.docx +0 -0
- data/spec/assets/external_images.html +35 -0
- data/spec/bin/reverse_adoc_spec.rb +32 -0
- data/spec/bin/w2a_spec.rb +35 -0
- data/spec/components/anchors_spec.rb +3 -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_adoc.rb +90 -0
- data/spec/lib/{reverse_asciidoctor → reverse_adoc}/cleaner_spec.rb +28 -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/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/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 +7 -2
- data/spec/support/shell_helpers.rb +15 -0
- metadata +126 -87
- data/lib/reverse_asciidoctor.rb +0 -70
- data/lib/reverse_asciidoctor/converters/h.rb +0 -19
- data/lib/reverse_asciidoctor/version.rb +0 -3
- data/spec/lib/reverse_asciidoctor_spec.rb +0 -37
data/lib/reverse_asciidoctor.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'digest'
|
2
|
-
require 'nokogiri'
|
3
|
-
require 'reverse_asciidoctor/version'
|
4
|
-
require 'reverse_asciidoctor/errors'
|
5
|
-
require 'reverse_asciidoctor/cleaner'
|
6
|
-
require 'reverse_asciidoctor/config'
|
7
|
-
require 'reverse_asciidoctor/converters'
|
8
|
-
require 'reverse_asciidoctor/converters/base'
|
9
|
-
require 'reverse_asciidoctor/converters/a'
|
10
|
-
require 'reverse_asciidoctor/converters/aside'
|
11
|
-
require 'reverse_asciidoctor/converters/audio'
|
12
|
-
require 'reverse_asciidoctor/converters/blockquote'
|
13
|
-
require 'reverse_asciidoctor/converters/br'
|
14
|
-
require 'reverse_asciidoctor/converters/bypass'
|
15
|
-
require 'reverse_asciidoctor/converters/code'
|
16
|
-
require 'reverse_asciidoctor/converters/div'
|
17
|
-
require 'reverse_asciidoctor/converters/drop'
|
18
|
-
require 'reverse_asciidoctor/converters/em'
|
19
|
-
require 'reverse_asciidoctor/converters/figure'
|
20
|
-
require 'reverse_asciidoctor/converters/h'
|
21
|
-
require 'reverse_asciidoctor/converters/head'
|
22
|
-
require 'reverse_asciidoctor/converters/hr'
|
23
|
-
require 'reverse_asciidoctor/converters/ignore'
|
24
|
-
require 'reverse_asciidoctor/converters/img'
|
25
|
-
require 'reverse_asciidoctor/converters/mark'
|
26
|
-
require 'reverse_asciidoctor/converters/li'
|
27
|
-
require 'reverse_asciidoctor/converters/ol'
|
28
|
-
require 'reverse_asciidoctor/converters/p'
|
29
|
-
require 'reverse_asciidoctor/converters/pass_through'
|
30
|
-
require 'reverse_asciidoctor/converters/pre'
|
31
|
-
require 'reverse_asciidoctor/converters/q'
|
32
|
-
require 'reverse_asciidoctor/converters/strong'
|
33
|
-
require 'reverse_asciidoctor/converters/sup'
|
34
|
-
require 'reverse_asciidoctor/converters/sub'
|
35
|
-
require 'reverse_asciidoctor/converters/table'
|
36
|
-
require 'reverse_asciidoctor/converters/td'
|
37
|
-
require 'reverse_asciidoctor/converters/th'
|
38
|
-
require 'reverse_asciidoctor/converters/text'
|
39
|
-
require 'reverse_asciidoctor/converters/tr'
|
40
|
-
require 'reverse_asciidoctor/converters/video'
|
41
|
-
require 'reverse_asciidoctor/converters/math'
|
42
|
-
|
43
|
-
module ReverseAsciidoctor
|
44
|
-
|
45
|
-
def self.convert(input, options = {})
|
46
|
-
root = case input
|
47
|
-
when String then Nokogiri::HTML(input).root
|
48
|
-
when Nokogiri::XML::Document then input.root
|
49
|
-
when Nokogiri::XML::Node then input
|
50
|
-
end
|
51
|
-
|
52
|
-
root or return ''
|
53
|
-
|
54
|
-
config.with(options) do
|
55
|
-
result = ReverseAsciidoctor::Converters.lookup(root.name).convert(root)
|
56
|
-
cleaner.tidy(result)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.config
|
61
|
-
@config ||= Config.new
|
62
|
-
yield @config if block_given?
|
63
|
-
@config
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.cleaner
|
67
|
-
@cleaner ||= Cleaner.new
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module ReverseAsciidoctor
|
2
|
-
module Converters
|
3
|
-
class H < Base
|
4
|
-
def convert(node, state = {})
|
5
|
-
id = node['id']
|
6
|
-
anchor = id ? "[[#{id}]]\n" : ""
|
7
|
-
prefix = '=' * (node.name[/\d/].to_i + 1)
|
8
|
-
["\n", anchor, prefix, ' ', treat_children(node, state), "\n"].join
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
register :h1, H.new
|
13
|
-
register :h2, H.new
|
14
|
-
register :h3, H.new
|
15
|
-
register :h4, H.new
|
16
|
-
register :h5, H.new
|
17
|
-
register :h6, H.new
|
18
|
-
end
|
19
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ReverseAsciidoctor do
|
4
|
-
let(:input) { File.read('spec/assets/minimum.html') }
|
5
|
-
let(:document) { Nokogiri::HTML(input) }
|
6
|
-
|
7
|
-
it "parses nokogiri documents" do
|
8
|
-
expect { ReverseAsciidoctor.convert(document) }.not_to raise_error
|
9
|
-
end
|
10
|
-
|
11
|
-
it "parses nokogiri elements" do
|
12
|
-
expect { ReverseAsciidoctor.convert(document.root) }.not_to raise_error
|
13
|
-
end
|
14
|
-
|
15
|
-
it "parses string input" do
|
16
|
-
expect { ReverseAsciidoctor.convert(input) }.not_to raise_error
|
17
|
-
end
|
18
|
-
|
19
|
-
it "behaves in a sane way when root element is nil" do
|
20
|
-
expect(ReverseAsciidoctor.convert(nil)).to eq ''
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '#config' do
|
24
|
-
it 'stores a given configuration option' do
|
25
|
-
ReverseAsciidoctor.config.tag_border = true
|
26
|
-
expect(ReverseAsciidoctor.config.tag_border).to eq true
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'can be used as a block configurator as well' do
|
30
|
-
ReverseAsciidoctor.config do |config|
|
31
|
-
expect(config.tag_border).to eq " "
|
32
|
-
config.tag_border = true
|
33
|
-
end
|
34
|
-
expect(ReverseAsciidoctor.config.tag_border).to eq true
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|