reverse_adoc 0.2.6 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +42 -0
- data/Gemfile +2 -2
- data/README.adoc +6 -22
- data/Rakefile +1 -1
- data/bin/reverse_adoc +17 -17
- data/bin/w2a +17 -17
- data/lib/reverse_adoc.rb +27 -0
- data/lib/{reverse_asciidoctor → reverse_adoc}/cleaner.rb +4 -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_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 +11 -11
- 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 +5 -4
- data/spec/assets/{test.docx → external_images.docx} +0 -0
- data/spec/assets/{test.html → external_images.html} +0 -0
- data/spec/bin/reverse_adoc_spec.rb +32 -0
- data/spec/bin/w2a_spec.rb +35 -0
- 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_adoc.rb +90 -0
- 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/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 +119 -101
- data/.github/workflows/macos.yml +0 -27
- data/.github/workflows/ubuntu.yml +0 -27
- data/.github/workflows/windows.yml +0 -30
- data/lib/reverse_asciidoctor.rb +0 -70
- data/lib/reverse_asciidoctor/version.rb +0 -3
- data/spec/lib/reverse_asciidoctor_spec.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 151922bd17ae4f65700977c109db7d8c55698e7eab9b22f7879df019b84c0923
|
4
|
+
data.tar.gz: b18bfb38f7d53ba8eae5cca00798824c8d4c6726a6d9c7baf0ab3a86f69c0d9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8cf25df3279d0bd4b33c105be476e15dcb0c8e4aca7812e3332daf3bc5ac4ea671281266ec8c70b83c7d906fa87593ce65e24a0a0a009382eb0921e6072e669
|
7
|
+
data.tar.gz: 5431dacaa7627908c4bb1e2583d56e7b982bd73f6ad44bf6a348ccc99cb632743ea701db79d53c46d5f0e263961abd676570f9c1d02417855dfc9d9b91deb3fa
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
name: rake
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches: [ master, main ]
|
8
|
+
tags: [ v* ]
|
9
|
+
pull_request:
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
rake:
|
13
|
+
name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
|
14
|
+
runs-on: ${{ matrix.os }}
|
15
|
+
continue-on-error: ${{ matrix.experimental }}
|
16
|
+
strategy:
|
17
|
+
fail-fast: false
|
18
|
+
matrix:
|
19
|
+
ruby: [ '2.7', '2.6', '2.5', '2.4' ]
|
20
|
+
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
|
+
experimental: [ false ]
|
22
|
+
include:
|
23
|
+
- ruby: '3.0'
|
24
|
+
os: 'ubuntu-latest'
|
25
|
+
experimental: true
|
26
|
+
- ruby: '3.0'
|
27
|
+
os: 'windows-latest'
|
28
|
+
experimental: true
|
29
|
+
- ruby: '3.0'
|
30
|
+
os: 'macos-latest'
|
31
|
+
experimental: true
|
32
|
+
steps:
|
33
|
+
- uses: actions/checkout@master
|
34
|
+
|
35
|
+
- uses: ruby/setup-ruby@v1
|
36
|
+
with:
|
37
|
+
ruby-version: ${{ matrix.ruby }}
|
38
|
+
bundler-cache: true
|
39
|
+
|
40
|
+
- uses: metanorma/metanorma-build-scripts/libreoffice-setup-action@master
|
41
|
+
|
42
|
+
- run: bundle exec rake
|
data/Gemfile
CHANGED
data/README.adoc
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
= AsciiDoc from HTML and Microsoft Word: reverse_adoc
|
2
2
|
|
3
3
|
https://github.com/metanorma/reverse_adoc[reverse_adoc] image:https://img.shields.io/gem/v/reverse_adoc.svg["Gem Version", link="https://rubygems.org/gems/reverse_adoc"]::
|
4
|
-
image:https://github.com/metanorma/reverse_adoc/workflows/
|
5
|
-
image:https://github.com/metanorma/reverse_adoc/workflows/windows/badge.svg["Build Status", link="https://github.com/metanorma/reverse_adoc/actions?workflow=windows"]
|
6
|
-
image:https://github.com/metanorma/reverse_adoc/workflows/ubuntu/badge.svg["Build Status", link="https://github.com/metanorma/reverse_adoc/actions?workflow=ubuntu"]
|
4
|
+
image:https://github.com/metanorma/reverse_adoc/workflows/rake/badge.svg["Build Status", link="https://github.com/metanorma/reverse_adoc/actions?workflow=rake"]
|
7
5
|
image:https://codeclimate.com/github/metanorma/reverse_adoc/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/reverse_adoc"]
|
8
6
|
image:https://img.shields.io/github/issues-pr-raw/metanorma/reverse_adoc.svg["Pull Requests", link="https://github.com/metanorma/reverse_adoc/pulls"]
|
9
7
|
image:https://img.shields.io/github/commits-since/metanorma/reverse_adoc/latest.svg["Commits since latest",link="https://github.com/metanorma/reverse_adoc/releases"]
|
@@ -44,20 +42,6 @@ $ reverse_adoc file.html > file.adoc
|
|
44
42
|
$ cat file.html | reverse_adoc > file.adoc
|
45
43
|
----
|
46
44
|
|
47
|
-
[source,console]
|
48
|
-
----
|
49
|
-
$ reverse_adoc -h
|
50
|
-
Usage: reverse_adoc [options] <file>
|
51
|
-
-m, --mathml2asciimath Convert MathML to AsciiMath
|
52
|
-
-o, --output=FILENAME Output file to write to
|
53
|
-
-e, --external-images Export images if data URI
|
54
|
-
-u [pass_through, drop, bypass, raise],
|
55
|
-
--unknown_tags Unknown tag handling (default: pass_through)
|
56
|
-
-v, --version Version information
|
57
|
-
-h, --help Prints this help
|
58
|
-
----
|
59
|
-
|
60
|
-
|
61
45
|
|
62
46
|
=== Microsoft Word to AsciiDoc: `w2a`
|
63
47
|
|
@@ -236,7 +220,7 @@ The gem does not support:
|
|
236
220
|
=== MathML support
|
237
221
|
|
238
222
|
If you are using this gem in the context of https://www.metanorma.com[Metanorma],
|
239
|
-
Metanorma
|
223
|
+
Metanorma AsciiDoc accepts MathML as a native mathematical format. So you do not need
|
240
224
|
to convert the MathML to AsciiMath.
|
241
225
|
|
242
226
|
The gem will optionally invoke the https://github.com/metanorma/mathml2asciimath
|
@@ -254,7 +238,7 @@ uses the output) as such; so this is still much better than nothing for stem pro
|
|
254
238
|
|
255
239
|
=== Word cleanup
|
256
240
|
|
257
|
-
This gem is routinely used in the Metanorma project to export Word documents to
|
241
|
+
This gem is routinely used in the Metanorma project to export Word documents to AsciiDoc.
|
258
242
|
The HTML export from Word that the gem uses, from LibreOffice, is much cleaner than the
|
259
243
|
native HTML 4 export from Word; but it has some infelicities which this gem cleans up:
|
260
244
|
|
@@ -273,7 +257,7 @@ Simple to use.
|
|
273
257
|
|
274
258
|
[source,ruby]
|
275
259
|
----
|
276
|
-
result =
|
260
|
+
result = ReverseAdoc.convert input
|
277
261
|
result.inspect # " *feelings* "
|
278
262
|
----
|
279
263
|
|
@@ -283,7 +267,7 @@ Just pass your chosen configuration options in after the input. The given option
|
|
283
267
|
|
284
268
|
[source,ruby]
|
285
269
|
----
|
286
|
-
|
270
|
+
ReverseAdoc.convert(input, unknown_tags: :raise, mathml2asciimath: true)
|
287
271
|
----
|
288
272
|
|
289
273
|
|
@@ -293,7 +277,7 @@ Or configure it block style on a initializer level. These configurations will la
|
|
293
277
|
|
294
278
|
[source,ruby]
|
295
279
|
----
|
296
|
-
|
280
|
+
ReverseAdoc.config do |config|
|
297
281
|
config.unknown_tags = :bypass
|
298
282
|
config.mathml2asciimath = true
|
299
283
|
config.tag_border = ''
|
data/Rakefile
CHANGED
data/bin/reverse_adoc
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# Usage:
|
3
|
-
# Usage: cat FILE |
|
2
|
+
# Usage: reverse_adoc [FILE]...
|
3
|
+
# Usage: cat FILE | reverse_adoc
|
4
4
|
require 'rubygems'
|
5
5
|
require 'bundler/setup'
|
6
6
|
|
7
|
-
require '
|
7
|
+
require 'reverse_adoc'
|
8
8
|
require 'optparse'
|
9
9
|
require 'fileutils'
|
10
10
|
|
11
11
|
OptionParser.new do |opts|
|
12
12
|
opts.banner = "Usage: reverse_adoc [options] <file>"
|
13
13
|
opts.on('-m', '--mathml2asciimath', 'Convert MathML to AsciiMath') do |v|
|
14
|
-
|
14
|
+
ReverseAdoc.config.mathml2asciimath = true
|
15
15
|
end
|
16
16
|
|
17
17
|
opts.on('-oFILENAME', '--output=FILENAME', 'Output file to write to') do |v|
|
18
|
-
|
19
|
-
# puts "output goes to #{
|
18
|
+
ReverseAdoc.config.destination = File.expand_path(v)
|
19
|
+
# puts "output goes to #{ReverseAdoc.config.destination}"
|
20
20
|
end
|
21
21
|
|
22
22
|
opts.on('-e', '--external-images', 'Export images if data URI') do |v|
|
23
|
-
|
23
|
+
ReverseAdoc.config.external_images = true
|
24
24
|
end
|
25
25
|
|
26
26
|
opts.on('-u', '--unknown_tags [pass_through, drop, bypass, raise]', 'Unknown tag handling (default: pass_through)') do |v|
|
27
|
-
|
27
|
+
ReverseAdoc.config.unknown_tags = v
|
28
28
|
end
|
29
29
|
|
30
30
|
opts.on('-v', '--version', 'Version information') do |v|
|
31
|
-
puts "reverse_adoc: v#{
|
31
|
+
puts "reverse_adoc: v#{ReverseAdoc::VERSION}"
|
32
32
|
exit
|
33
33
|
end
|
34
34
|
|
@@ -41,30 +41,30 @@ end.parse!
|
|
41
41
|
|
42
42
|
if filename = ARGV.pop
|
43
43
|
input_content = IO.read(filename)
|
44
|
-
|
44
|
+
ReverseAdoc.config.sourcedir = File.dirname(File.expand_path(filename))
|
45
45
|
else
|
46
|
-
if
|
46
|
+
if ReverseAdoc.config.external_images
|
47
47
|
raise "The -e | --external-images feature cannot be used with STDIN input. Exiting."
|
48
48
|
end
|
49
49
|
|
50
50
|
input_content = ARGF.read
|
51
51
|
end
|
52
52
|
|
53
|
-
if
|
53
|
+
if ReverseAdoc.config.external_images && ReverseAdoc.config.destination.nil?
|
54
54
|
raise "The -e | --external-images feature must be used with -o | --output. Exiting."
|
55
55
|
end
|
56
56
|
|
57
57
|
# Read from STDIN
|
58
|
-
adoc_content =
|
58
|
+
adoc_content = ReverseAdoc.convert(input_content)
|
59
59
|
|
60
60
|
# Print to STDOUT
|
61
|
-
unless
|
61
|
+
unless ReverseAdoc.config.destination
|
62
62
|
puts adoc_content
|
63
63
|
exit
|
64
64
|
end
|
65
65
|
|
66
|
-
# Write output to
|
67
|
-
FileUtils.mkdir_p(File.dirname(
|
68
|
-
File.open(
|
66
|
+
# Write output to ReverseAdoc.config.destination
|
67
|
+
FileUtils.mkdir_p(File.dirname(ReverseAdoc.config.destination))
|
68
|
+
File.open(ReverseAdoc.config.destination, "w") do |file|
|
69
69
|
file.write(adoc_content)
|
70
70
|
end
|
data/bin/w2a
CHANGED
@@ -1,31 +1,32 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
|
+
|
3
4
|
require 'rubygems'
|
4
5
|
require 'bundler/setup'
|
5
6
|
|
6
7
|
require 'word-to-markdown'
|
7
8
|
require 'optparse'
|
8
|
-
require '
|
9
|
+
require 'reverse_adoc'
|
9
10
|
|
10
11
|
ARGV.push('-h') if ARGV.empty?
|
11
12
|
|
12
13
|
OptionParser.new do |opts|
|
13
14
|
opts.banner = "Usage: w2a [options] <file>"
|
14
15
|
opts.on('-m', '--mathml2asciimath', 'Convert MathML to AsciiMath') do |v|
|
15
|
-
|
16
|
+
ReverseAdoc.config.mathml2asciimath = true
|
16
17
|
end
|
17
18
|
|
18
19
|
opts.on('-oFILENAME', '--output=FILENAME', 'Output file to write to') do |v|
|
19
|
-
|
20
|
-
# puts "output goes to #{
|
20
|
+
ReverseAdoc.config.destination = File.expand_path(v)
|
21
|
+
# puts "output goes to #{ReverseAdoc.config.destination}"
|
21
22
|
end
|
22
23
|
|
23
24
|
opts.on('-e', '--external-images', 'Export images if data URI') do |v|
|
24
|
-
|
25
|
+
ReverseAdoc.config.external_images = true
|
25
26
|
end
|
26
27
|
|
27
28
|
opts.on('-v', '--version', 'Version information') do |v|
|
28
|
-
puts "reverse_adoc: v#{
|
29
|
+
puts "reverse_adoc: v#{ReverseAdoc::VERSION}"
|
29
30
|
puts "[dependency] WordToMarkdown: v#{WordToMarkdown::VERSION}"
|
30
31
|
unless Gem.win_platform?
|
31
32
|
puts "[dependency] LibreOffice: v#{WordToMarkdown.soffice.version}"
|
@@ -45,29 +46,28 @@ end.parse!
|
|
45
46
|
filename = ARGV.pop
|
46
47
|
raise "Please provide an input file to process. Exiting." unless filename
|
47
48
|
|
48
|
-
if
|
49
|
+
if ReverseAdoc.config.external_images && ReverseAdoc.config.destination.nil?
|
49
50
|
raise "The -e | --external-images feature must be used with -o | --output. Exiting."
|
50
51
|
end
|
51
52
|
|
52
|
-
|
53
|
-
# puts "ReverseAsciidoctor.config.sourcedir #{ReverseAsciidoctor.config.sourcedir}"
|
53
|
+
ReverseAdoc.config.sourcedir = Dir.mktmpdir
|
54
54
|
|
55
|
-
doc = WordToMarkdown.new(filename,
|
56
|
-
File.open("test.html", "w:UTF-8") { |f| f.write doc.document.html }
|
57
|
-
adoc_content =
|
58
|
-
|
55
|
+
doc = WordToMarkdown.new(filename, ReverseAdoc.config.sourcedir)
|
56
|
+
#File.open("test.html", "w:UTF-8") { |f| f.write doc.document.html }
|
57
|
+
adoc_content = ReverseAdoc.convert(
|
58
|
+
ReverseAdoc.cleaner.preprocess_word_html(doc.document.html),
|
59
59
|
WordToMarkdown::REVERSE_MARKDOWN_OPTIONS
|
60
60
|
)
|
61
61
|
# puts scrub_whitespace(doc.document.html)
|
62
62
|
|
63
63
|
# Print to STDOUT
|
64
|
-
unless
|
64
|
+
unless ReverseAdoc.config.destination
|
65
65
|
puts adoc_content
|
66
66
|
exit
|
67
67
|
end
|
68
68
|
|
69
|
-
# Write output to
|
70
|
-
FileUtils.mkdir_p(File.dirname(
|
71
|
-
File.open(
|
69
|
+
# Write output to ReverseAdoc.config.destination
|
70
|
+
FileUtils.mkdir_p(File.dirname(ReverseAdoc.config.destination))
|
71
|
+
File.open(ReverseAdoc.config.destination, "w") do |file|
|
72
72
|
file.write(adoc_content)
|
73
73
|
end
|
data/lib/reverse_adoc.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'reverse_adoc/version'
|
6
|
+
require 'reverse_adoc/errors'
|
7
|
+
require 'reverse_adoc/cleaner'
|
8
|
+
require 'reverse_adoc/config'
|
9
|
+
require 'reverse_adoc/converters'
|
10
|
+
require 'reverse_adoc/converters/base'
|
11
|
+
require "reverse_adoc/html_converter"
|
12
|
+
|
13
|
+
module ReverseAdoc
|
14
|
+
def self.convert(input, options = {})
|
15
|
+
ReverseAdoc::HtmlConverter.convert(input, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.config
|
19
|
+
@config ||= Config.new
|
20
|
+
yield @config if block_given?
|
21
|
+
@config
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.cleaner
|
25
|
+
@cleaner ||= Cleaner.new
|
26
|
+
end
|
27
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ReverseAdoc
|
2
2
|
class Cleaner
|
3
3
|
|
4
4
|
def tidy(string)
|
@@ -36,19 +36,19 @@ module ReverseAsciidoctor
|
|
36
36
|
# Same for underscores and brackets.
|
37
37
|
def clean_tag_borders(string)
|
38
38
|
result = string.gsub(/\s?\*{2,}.*?\*{2,}\s?/) do |match|
|
39
|
-
preserve_border_whitespaces(match, default_border:
|
39
|
+
preserve_border_whitespaces(match, default_border: ReverseAdoc.config.tag_border) do
|
40
40
|
match.strip.sub('** ', '**').sub(' **', '**')
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
result = result.gsub(/\s?\_{2,}.*?\_{2,}\s?/) do |match|
|
45
|
-
preserve_border_whitespaces(match, default_border:
|
45
|
+
preserve_border_whitespaces(match, default_border: ReverseAdoc.config.tag_border) do
|
46
46
|
match.strip.sub('__ ', '__').sub(' __', '__')
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
result = result.gsub(/\s?~{2,}.*?~{2,}\s?/) do |match|
|
51
|
-
preserve_border_whitespaces(match, default_border:
|
51
|
+
preserve_border_whitespaces(match, default_border: ReverseAdoc.config.tag_border) do
|
52
52
|
match.strip.sub('~~ ', '~~').sub(' ~~', '~~')
|
53
53
|
end
|
54
54
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'tmpdir'
|
2
2
|
|
3
|
-
module
|
3
|
+
module ReverseAdoc
|
4
4
|
class Config
|
5
5
|
attr_accessor :unknown_tags, :tag_border, :mathml2asciimath, :external_images,
|
6
|
-
:destination, :sourcedir, :image_counter, :image_counter_pattern
|
6
|
+
:destination, :sourcedir, :image_counter, :image_counter_pattern, :input_format
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@unknown_tags = :pass_through
|
10
|
+
@input_format = :html
|
10
11
|
@mathml2asciimath = false
|
11
12
|
@external_images = false
|
12
13
|
|
@@ -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,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)
|