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.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +42 -0
  3. data/Gemfile +2 -2
  4. data/README.adoc +6 -22
  5. data/Rakefile +1 -1
  6. data/bin/reverse_adoc +17 -17
  7. data/bin/w2a +17 -17
  8. data/lib/reverse_adoc.rb +27 -0
  9. data/lib/{reverse_asciidoctor → reverse_adoc}/cleaner.rb +4 -4
  10. data/lib/{reverse_asciidoctor → reverse_adoc}/config.rb +3 -2
  11. data/lib/{reverse_asciidoctor → reverse_adoc}/converters.rb +6 -6
  12. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/a.rb +1 -1
  13. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/aside.rb +1 -1
  14. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/audio.rb +1 -1
  15. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/base.rb +2 -2
  16. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/blockquote.rb +2 -2
  17. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/br.rb +1 -1
  18. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/bypass.rb +1 -1
  19. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/code.rb +1 -1
  20. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/div.rb +1 -1
  21. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/drop.rb +1 -1
  22. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/em.rb +1 -1
  23. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/figure.rb +1 -1
  24. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/h.rb +1 -1
  25. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/head.rb +1 -1
  26. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/hr.rb +1 -1
  27. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/ignore.rb +1 -1
  28. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/img.rb +11 -11
  29. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/li.rb +1 -1
  30. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/mark.rb +1 -1
  31. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/math.rb +3 -3
  32. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/ol.rb +1 -1
  33. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/p.rb +1 -1
  34. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/pass_through.rb +1 -1
  35. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/pre.rb +1 -1
  36. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/q.rb +1 -1
  37. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/strong.rb +1 -1
  38. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/sub.rb +1 -1
  39. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/sup.rb +1 -1
  40. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/table.rb +1 -1
  41. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/td.rb +1 -1
  42. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/text.rb +1 -1
  43. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/th.rb +1 -1
  44. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/tr.rb +1 -1
  45. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/video.rb +1 -1
  46. data/lib/{reverse_asciidoctor → reverse_adoc}/errors.rb +1 -1
  47. data/lib/reverse_adoc/html_converter.rb +56 -0
  48. data/lib/reverse_adoc/version.rb +3 -0
  49. data/reverse_adoc.gemspec +5 -4
  50. data/spec/assets/{test.docx → external_images.docx} +0 -0
  51. data/spec/assets/{test.html → external_images.html} +0 -0
  52. data/spec/bin/reverse_adoc_spec.rb +32 -0
  53. data/spec/bin/w2a_spec.rb +35 -0
  54. data/spec/components/anchors_spec.rb +2 -2
  55. data/spec/components/basic_spec.rb +2 -2
  56. data/spec/components/code_spec.rb +4 -4
  57. data/spec/components/escapables_spec.rb +2 -2
  58. data/spec/components/from_the_wild_spec.rb +2 -2
  59. data/spec/components/html_fragment_spec.rb +2 -2
  60. data/spec/components/lists_spec.rb +2 -2
  61. data/spec/components/paragraphs_spec.rb +2 -2
  62. data/spec/components/quotation_spec.rb +2 -2
  63. data/spec/components/tables_spec.rb +2 -2
  64. data/spec/components/unknown_tags_spec.rb +9 -9
  65. data/spec/lib/reverse_adoc.rb +90 -0
  66. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/cleaner_spec.rb +4 -4
  67. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/config_spec.rb +5 -5
  68. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/aside_spec.rb +2 -2
  69. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/audio_spec.rb +2 -2
  70. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/blockquote_spec.rb +2 -2
  71. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/br_spec.rb +2 -2
  72. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/code_spec.rb +2 -2
  73. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/div_spec.rb +2 -2
  74. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/figure_spec.rb +2 -2
  75. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/img_spec.rb +2 -2
  76. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/li_spec.rb +2 -2
  77. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/mark_spec.rb +2 -2
  78. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/p_spec.rb +2 -2
  79. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/pre_spec.rb +2 -2
  80. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/q_spec.rb +2 -2
  81. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/strong_spec.rb +2 -2
  82. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/text_spec.rb +2 -2
  83. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/video_spec.rb +2 -2
  84. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters_spec.rb +5 -5
  85. data/spec/spec_helper.rb +7 -2
  86. data/spec/support/shell_helpers.rb +15 -0
  87. metadata +119 -101
  88. data/.github/workflows/macos.yml +0 -27
  89. data/.github/workflows/ubuntu.yml +0 -27
  90. data/.github/workflows/windows.yml +0 -30
  91. data/lib/reverse_asciidoctor.rb +0 -70
  92. data/lib/reverse_asciidoctor/version.rb +0 -3
  93. data/spec/lib/reverse_asciidoctor_spec.rb +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3d387a4fbedd246900150be67a80bf62ee70a70cf697b1a2a7a247080d879ad
4
- data.tar.gz: 956f8db0ca1d2f34e1f165f323e6db6d1f5e68a91dc886d6fd3cf3f1f7aa0886
3
+ metadata.gz: 151922bd17ae4f65700977c109db7d8c55698e7eab9b22f7879df019b84c0923
4
+ data.tar.gz: b18bfb38f7d53ba8eae5cca00798824c8d4c6726a6d9c7baf0ab3a86f69c0d9a
5
5
  SHA512:
6
- metadata.gz: a72c96ffc8e41f7e38b28108107b12bec33a22e3b1722416e7b4d5a493ab3f47d6c3fab49a98b27969ba8235cb3ed6fff86f027a8c9ff5e4b3276af8d2d0a752
7
- data.tar.gz: 1f0de4f61007133d49c0dfcd0dd85e8a87f8445a59fb41ba5dd1001eeec4e1405402449389b3e1355a453ff5a21bf6fa7d4b8bfd1fc883c654feee83600e55f3
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
@@ -1,8 +1,8 @@
1
1
  source "https://rubygems.org"
2
-
2
+
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
- # Specify your gem's dependencies in reverse_asciidoctor.gemspec
5
+ # Specify your gem's dependencies in reverse_adoc.gemspec
6
6
  gemspec
7
7
 
8
8
  gem "byebug"
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/macos/badge.svg["Build Status", link="https://github.com/metanorma/reverse_adoc/actions?workflow=macos"]
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 Asciidoctor accepts MathML as a native mathematical format. So you do not need
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 Asciidoctor.
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 = ReverseAsciidoctor.convert input
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
- ReverseAsciidoctor.convert(input, unknown_tags: :raise, mathml2asciimath: true)
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
- ReverseAsciidoctor.config do |config|
280
+ ReverseAdoc.config do |config|
297
281
  config.unknown_tags = :bypass
298
282
  config.mathml2asciimath = true
299
283
  config.tag_border = ''
data/Rakefile CHANGED
@@ -10,5 +10,5 @@ task :default => :spec
10
10
 
11
11
  desc 'Open an irb session preloaded with this library'
12
12
  task :console do
13
- sh 'irb -rubygems -I lib -r reverse_asciidoctor.rb'
13
+ sh 'irb -rubygems -I lib -r reverse_adoc.rb'
14
14
  end
data/bin/reverse_adoc CHANGED
@@ -1,34 +1,34 @@
1
1
  #!/usr/bin/env ruby
2
- # Usage: reverse_asciidoctor [FILE]...
3
- # Usage: cat FILE | reverse_asciidoctor
2
+ # Usage: reverse_adoc [FILE]...
3
+ # Usage: cat FILE | reverse_adoc
4
4
  require 'rubygems'
5
5
  require 'bundler/setup'
6
6
 
7
- require 'reverse_asciidoctor'
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
- ReverseAsciidoctor.config.mathml2asciimath = true
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
- ReverseAsciidoctor.config.destination = File.expand_path(v)
19
- # puts "output goes to #{ReverseAsciidoctor.config.destination}"
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
- ReverseAsciidoctor.config.external_images = true
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
- ReverseAsciidoctor.config.unknown_tags = v
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#{ReverseAsciidoctor::VERSION}"
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
- ReverseAsciidoctor.config.sourcedir = File.dirname(File.expand_path(filename))
44
+ ReverseAdoc.config.sourcedir = File.dirname(File.expand_path(filename))
45
45
  else
46
- if ReverseAsciidoctor.config.external_images
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 ReverseAsciidoctor.config.external_images && ReverseAsciidoctor.config.destination.nil?
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 = ReverseAsciidoctor.convert(input_content)
58
+ adoc_content = ReverseAdoc.convert(input_content)
59
59
 
60
60
  # Print to STDOUT
61
- unless ReverseAsciidoctor.config.destination
61
+ unless ReverseAdoc.config.destination
62
62
  puts adoc_content
63
63
  exit
64
64
  end
65
65
 
66
- # Write output to ReverseAsciidoctor.config.destination
67
- FileUtils.mkdir_p(File.dirname(ReverseAsciidoctor.config.destination))
68
- File.open(ReverseAsciidoctor.config.destination, "w") do |file|
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 'reverse_asciidoctor'
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
- ReverseAsciidoctor.config.mathml2asciimath = true
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
- ReverseAsciidoctor.config.destination = File.expand_path(v)
20
- # puts "output goes to #{ReverseAsciidoctor.config.destination}"
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
- ReverseAsciidoctor.config.external_images = true
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#{ReverseAsciidoctor::VERSION}"
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 ReverseAsciidoctor.config.external_images && ReverseAsciidoctor.config.destination.nil?
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
- ReverseAsciidoctor.config.sourcedir = Dir.mktmpdir
53
- # puts "ReverseAsciidoctor.config.sourcedir #{ReverseAsciidoctor.config.sourcedir}"
53
+ ReverseAdoc.config.sourcedir = Dir.mktmpdir
54
54
 
55
- doc = WordToMarkdown.new(filename, ReverseAsciidoctor.config.sourcedir)
56
- File.open("test.html", "w:UTF-8") { |f| f.write doc.document.html }
57
- adoc_content = ReverseAsciidoctor.convert(
58
- ReverseAsciidoctor.cleaner.preprocess_word_html(doc.document.html),
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 ReverseAsciidoctor.config.destination
64
+ unless ReverseAdoc.config.destination
65
65
  puts adoc_content
66
66
  exit
67
67
  end
68
68
 
69
- # Write output to ReverseAsciidoctor.config.destination
70
- FileUtils.mkdir_p(File.dirname(ReverseAsciidoctor.config.destination))
71
- File.open(ReverseAsciidoctor.config.destination, "w") do |file|
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
@@ -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 ReverseAsciidoctor
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: ReverseAsciidoctor.config.tag_border) do
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: ReverseAsciidoctor.config.tag_border) do
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: ReverseAsciidoctor.config.tag_border) do
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 ReverseAsciidoctor
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 ReverseAsciidoctor
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 ReverseAsciidoctor.config.unknown_tags.to_sym
19
+ case ReverseAdoc.config.unknown_tags.to_sym
20
20
  when :pass_through
21
- ReverseAsciidoctor::Converters::PassThrough.new
21
+ ReverseAdoc::Converters::PassThrough.new
22
22
  when :drop
23
- ReverseAsciidoctor::Converters::Drop.new
23
+ ReverseAdoc::Converters::Drop.new
24
24
  when :bypass
25
- ReverseAsciidoctor::Converters::Bypass.new
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 #{ReverseAsciidoctor.config.unknown_tags.inspect} for ReverseAsciidoctor.config.unknown_tags"
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,6 +1,6 @@
1
1
  require "uri"
2
2
 
3
- module ReverseAsciidoctor
3
+ module ReverseAdoc
4
4
  module Converters
5
5
  class A < Base
6
6
  def convert(node, state = {})
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Aside < Base
4
4
  def convert(node, state = {})
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  module Converters
3
3
  class Audio < Base
4
4
  def convert(node, state = {})
@@ -1,4 +1,4 @@
1
- module ReverseAsciidoctor
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
- ReverseAsciidoctor::Converters.lookup(node.name).convert(node, state)
11
+ ReverseAdoc::Converters.lookup(node.name).convert(node, state)
12
12
  end
13
13
 
14
14
  def escape_keychars(string)