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.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +15 -0
  3. data/.github/workflows/rake.yml +32 -0
  4. data/.github/workflows/release.yml +45 -0
  5. data/.gitignore +10 -0
  6. data/.hound.yml +3 -1
  7. data/.rubocop.yml +7 -7
  8. data/Gemfile +1 -1
  9. data/README.adoc +6 -33
  10. data/Rakefile +1 -1
  11. data/exe/reverse_adoc +70 -0
  12. data/{bin → exe}/w2a +15 -15
  13. data/lib/reverse_adoc.rb +27 -0
  14. data/lib/{reverse_asciidoctor → reverse_adoc}/cleaner.rb +28 -27
  15. data/lib/{reverse_asciidoctor → reverse_adoc}/config.rb +1 -1
  16. data/lib/{reverse_asciidoctor → reverse_adoc}/converters.rb +6 -6
  17. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/a.rb +1 -1
  18. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/aside.rb +1 -1
  19. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/audio.rb +1 -1
  20. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/base.rb +5 -3
  21. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/blockquote.rb +2 -2
  22. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/br.rb +1 -1
  23. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/bypass.rb +1 -1
  24. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/code.rb +1 -1
  25. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/div.rb +1 -1
  26. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/drop.rb +1 -1
  27. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/em.rb +1 -1
  28. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/figure.rb +1 -1
  29. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/h.rb +1 -1
  30. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/head.rb +1 -1
  31. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/hr.rb +1 -1
  32. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/ignore.rb +1 -1
  33. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/img.rb +9 -9
  34. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/li.rb +1 -1
  35. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/mark.rb +1 -1
  36. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/math.rb +3 -3
  37. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/ol.rb +1 -1
  38. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/p.rb +1 -1
  39. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/pass_through.rb +1 -1
  40. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/pre.rb +1 -1
  41. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/q.rb +1 -1
  42. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/strong.rb +1 -1
  43. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/sub.rb +1 -1
  44. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/sup.rb +1 -1
  45. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/table.rb +1 -1
  46. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/td.rb +1 -1
  47. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/text.rb +1 -1
  48. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/th.rb +1 -1
  49. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/tr.rb +1 -1
  50. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/video.rb +1 -1
  51. data/lib/{reverse_asciidoctor → reverse_adoc}/errors.rb +1 -1
  52. data/lib/reverse_adoc/html_converter.rb +56 -0
  53. data/lib/reverse_adoc/version.rb +3 -0
  54. data/reverse_adoc.gemspec +18 -15
  55. data/spec/assets/escapables.html +2 -0
  56. data/spec/bin/reverse_adoc_spec.rb +2 -2
  57. data/spec/bin/w2a_spec.rb +7 -7
  58. data/spec/components/anchors_spec.rb +2 -2
  59. data/spec/components/basic_spec.rb +3 -3
  60. data/spec/components/code_spec.rb +4 -5
  61. data/spec/components/escapables_spec.rb +10 -2
  62. data/spec/components/from_the_wild_spec.rb +2 -2
  63. data/spec/components/html_fragment_spec.rb +2 -3
  64. data/spec/components/lists_spec.rb +2 -2
  65. data/spec/components/paragraphs_spec.rb +2 -2
  66. data/spec/components/quotation_spec.rb +2 -2
  67. data/spec/components/tables_spec.rb +2 -2
  68. data/spec/components/unknown_tags_spec.rb +9 -10
  69. data/spec/lib/{reverse_asciidoctor_spec.rb → reverse_adoc.rb} +17 -17
  70. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/cleaner_spec.rb +4 -4
  71. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/config_spec.rb +5 -5
  72. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/aside_spec.rb +2 -2
  73. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/audio_spec.rb +2 -3
  74. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/blockquote_spec.rb +2 -2
  75. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/br_spec.rb +2 -2
  76. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/code_spec.rb +2 -3
  77. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/div_spec.rb +2 -3
  78. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/figure_spec.rb +2 -3
  79. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/img_spec.rb +2 -3
  80. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/li_spec.rb +2 -2
  81. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/mark_spec.rb +2 -2
  82. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/p_spec.rb +2 -3
  83. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/pre_spec.rb +2 -3
  84. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/q_spec.rb +2 -2
  85. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/strong_spec.rb +2 -2
  86. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/text_spec.rb +2 -2
  87. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/video_spec.rb +2 -3
  88. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters_spec.rb +5 -5
  89. data/spec/spec_helper.rb +3 -3
  90. metadata +123 -125
  91. data/.github/workflows/macos.yml +0 -31
  92. data/.github/workflows/ubuntu.yml +0 -33
  93. data/.github/workflows/windows.yml +0 -37
  94. data/Gemfile.lock +0 -84
  95. data/bin/reverse_adoc +0 -74
  96. data/lib/reverse_asciidoctor.rb +0 -30
  97. data/lib/reverse_asciidoctor/converters/example.rb +0 -17
  98. data/lib/reverse_asciidoctor/converters/express_ref.rb +0 -12
  99. data/lib/reverse_asciidoctor/converters/ext_description.rb +0 -16
  100. data/lib/reverse_asciidoctor/converters/ext_descriptions.rb +0 -12
  101. data/lib/reverse_asciidoctor/converters/note.rb +0 -17
  102. data/lib/reverse_asciidoctor/html_converter.rb +0 -56
  103. data/lib/reverse_asciidoctor/smrl_description_converter.rb +0 -45
  104. data/lib/reverse_asciidoctor/version.rb +0 -3
  105. data/spec/lib/reverse_asciidoctor/converters/example_spec.rb +0 -22
  106. data/spec/lib/reverse_asciidoctor/converters/express_ref_spec.rb +0 -14
  107. data/spec/lib/reverse_asciidoctor/converters/ext_description_spec.rb +0 -20
  108. data/spec/lib/reverse_asciidoctor/converters/ext_descriptions_spec.rb +0 -13
  109. data/spec/lib/reverse_asciidoctor/converters/note_spec.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb34effa1c1af2e72ef8df7b6b1553c7c2574bcca9608e02cfaf561ed8a2bfec
4
- data.tar.gz: e18b3b9cf2d936a48fdf2e6d5f265aa5c945c9493bd232a4d8fb311df780e81f
3
+ metadata.gz: c47e4d9eb1123a3b243cbb8f525eb3a4e5292d3cb721d09b1a0dc5a308521c24
4
+ data.tar.gz: 15602c27effe49fd669aa0114c655b30879d71fefe1019a5333962860e88375d
5
5
  SHA512:
6
- metadata.gz: ca8454b96ad3064c16018f09198f8450f9a15e6525c1df6e63b7a0e3dd3254f66f2bee56e69e8c7088087962911480513f3608c759f955489b2e602dc2251890
7
- data.tar.gz: 49c2198645f22b9ac26ea78aa36e1073a27807dca8364ad076250dccfc6b307055775894962d70d6400d7c8ec6b3dfa02cb31c84c922c60d8c18cbbf5ee55171
6
+ metadata.gz: ce264bc1decfc19683b4fc5c5f72d96a71be82bfb5ffbbe7f6c1e2428ca78eae48f6df66d473e712c925f04afa8fca887c858549dddf2fe0568dd953b2fe6a01
7
+ data.tar.gz: 460f744b26878bf13783393f8a0776dd74c15450072cc9b7654221da3b122c28457353aec3560a8f3bb5c88db70cf8568e84cafae63b29154539ba789f0d1045
data/.editorconfig ADDED
@@ -0,0 +1,15 @@
1
+ # EditorConfig is awesome: http://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ # Unix-style newlines with a newline ending every file
7
+ [*]
8
+ charset = utf-8
9
+ end_of_line = lf
10
+
11
+ [{*.adoc,*.html,*.js,*.json,*.rake,*.rb,*.rf,*.yaml,*.yml,Rakefile,rakefile}]
12
+ indent_style = space
13
+ indent_size = 2
14
+ insert_final_newline = true
15
+ trim_trailing_whitespace = true
@@ -0,0 +1,32 @@
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: [ '3.0', '2.7', '2.6', '2.5', '2.4' ]
20
+ os: [ ubuntu-latest, windows-latest, macos-latest ]
21
+ experimental: [ false ]
22
+ steps:
23
+ - uses: actions/checkout@master
24
+
25
+ - uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby }}
28
+ bundler-cache: true
29
+
30
+ - uses: metanorma/metanorma-build-scripts/libreoffice-setup-action@master
31
+
32
+ - run: bundle exec rake
@@ -0,0 +1,45 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: release
4
+
5
+ on:
6
+ workflow_dispatch:
7
+ inputs:
8
+ next_version:
9
+ description: |
10
+ Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
11
+ required: true
12
+ default: 'skip'
13
+ push:
14
+ tags: [ v* ]
15
+
16
+ jobs:
17
+ release:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+
22
+ - uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: '2.6'
25
+ bundler-cache: true
26
+
27
+ - run: gem install gem-release
28
+
29
+ - if: ${{ github.event_name == 'workflow_dispatch' }} && ${{ github.event.inputs.next_version != 'skip' }}
30
+ run: |
31
+ git config user.name github-actions
32
+ git config user.email github-actions@github.com
33
+ gem bump --version ${{ github.event.inputs.next_version }} --tag --push
34
+
35
+ - name: publish to rubygems.org
36
+ env:
37
+ RUBYGEMS_API_KEY: ${{secrets.METANORMA_CI_RUBYGEMS_API_KEY}}
38
+ run: |
39
+ gem install gem-release
40
+ envsubst << 'EOF' > ~/.gem/credentials
41
+ ---
42
+ :rubygems_api_key: ${RUBYGEMS_API_KEY}
43
+ EOF
44
+ chmod 0600 ~/.gem/credentials
45
+ gem release
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /coverage
2
+ /Gemfile.lock
3
+
4
+ .DS_Store
5
+
6
+ # RuboCop's remote style books
7
+ .rubocop-https---*
8
+
9
+ # Some odd files created by specs
10
+ /test1
data/.hound.yml CHANGED
@@ -1,3 +1,5 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
1
3
  ruby:
2
- Enabled: true
4
+ enabled: true
3
5
  config_file: .rubocop.yml
data/.rubocop.yml CHANGED
@@ -1,10 +1,10 @@
1
- # This project follows the Ribose OSS style guide.
2
- # https://github.com/riboseinc/oss-guides
3
- # All project-specific additions and overrides should be specified in this file.
4
-
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
5
3
  inherit_from:
6
4
  - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
5
+
6
+ # local repo-specific modifications
7
+ # ...
8
+
7
9
  AllCops:
8
- TargetRubyVersion: 2.3
9
- Rails:
10
- Enabled: true
10
+ TargetRubyVersion: 2.4
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ 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,31 +42,6 @@ $ reverse_adoc file.html > file.adoc
44
42
  $ cat file.html | reverse_adoc > file.adoc
45
43
  ----
46
44
 
47
- === XML smrl description to AsciiDoc: `reverse_adoc`
48
-
49
- Convert XML smrl description files to AsciiDoc:
50
-
51
- [source,console]
52
- ----
53
- $ reverse_adoc -f smrl_description descriptions.xml > file.adoc
54
- $ cat descriptions.xml | reverse_adoc -f smrl_description > file.adoc
55
- ----
56
-
57
- [source,console]
58
- ----
59
- $ reverse_adoc -h
60
- Usage: reverse_adoc [options] <file>
61
- -f, --input_format Supply input format to choose converter(html or smrl_description)
62
- -m, --mathml2asciimath Convert MathML to AsciiMath
63
- -o, --output=FILENAME Output file to write to
64
- -e, --external-images Export images if data URI
65
- -u [pass_through, drop, bypass, raise],
66
- --unknown_tags Unknown tag handling (default: pass_through)
67
- -v, --version Version information
68
- -h, --help Prints this help
69
- ----
70
-
71
-
72
45
 
73
46
  === Microsoft Word to AsciiDoc: `w2a`
74
47
 
@@ -247,7 +220,7 @@ The gem does not support:
247
220
  === MathML support
248
221
 
249
222
  If you are using this gem in the context of https://www.metanorma.com[Metanorma],
250
- 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
251
224
  to convert the MathML to AsciiMath.
252
225
 
253
226
  The gem will optionally invoke the https://github.com/metanorma/mathml2asciimath
@@ -265,7 +238,7 @@ uses the output) as such; so this is still much better than nothing for stem pro
265
238
 
266
239
  === Word cleanup
267
240
 
268
- 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.
269
242
  The HTML export from Word that the gem uses, from LibreOffice, is much cleaner than the
270
243
  native HTML 4 export from Word; but it has some infelicities which this gem cleans up:
271
244
 
@@ -284,7 +257,7 @@ Simple to use.
284
257
 
285
258
  [source,ruby]
286
259
  ----
287
- result = ReverseAsciidoctor.convert input
260
+ result = ReverseAdoc.convert input
288
261
  result.inspect # " *feelings* "
289
262
  ----
290
263
 
@@ -294,7 +267,7 @@ Just pass your chosen configuration options in after the input. The given option
294
267
 
295
268
  [source,ruby]
296
269
  ----
297
- ReverseAsciidoctor.convert(input, unknown_tags: :raise, mathml2asciimath: true)
270
+ ReverseAdoc.convert(input, unknown_tags: :raise, mathml2asciimath: true)
298
271
  ----
299
272
 
300
273
 
@@ -304,7 +277,7 @@ Or configure it block style on a initializer level. These configurations will la
304
277
 
305
278
  [source,ruby]
306
279
  ----
307
- ReverseAsciidoctor.config do |config|
280
+ ReverseAdoc.config do |config|
308
281
  config.unknown_tags = :bypass
309
282
  config.mathml2asciimath = true
310
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/exe/reverse_adoc ADDED
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+ # Usage: reverse_adoc [FILE]...
3
+ # Usage: cat FILE | reverse_adoc
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
+
7
+ require 'reverse_adoc'
8
+ require 'optparse'
9
+ require 'fileutils'
10
+
11
+ OptionParser.new do |opts|
12
+ opts.banner = "Usage: reverse_adoc [options] <file>"
13
+ opts.on('-m', '--mathml2asciimath', 'Convert MathML to AsciiMath') do |v|
14
+ ReverseAdoc.config.mathml2asciimath = true
15
+ end
16
+
17
+ opts.on('-oFILENAME', '--output=FILENAME', 'Output file to write to') do |v|
18
+ ReverseAdoc.config.destination = File.expand_path(v)
19
+ # puts "output goes to #{ReverseAdoc.config.destination}"
20
+ end
21
+
22
+ opts.on('-e', '--external-images', 'Export images if data URI') do |v|
23
+ ReverseAdoc.config.external_images = true
24
+ end
25
+
26
+ opts.on('-u', '--unknown_tags [pass_through, drop, bypass, raise]', 'Unknown tag handling (default: pass_through)') do |v|
27
+ ReverseAdoc.config.unknown_tags = v
28
+ end
29
+
30
+ opts.on('-v', '--version', 'Version information') do |v|
31
+ puts "reverse_adoc: v#{ReverseAdoc::VERSION}"
32
+ exit
33
+ end
34
+
35
+ opts.on("-h", "--help", "Prints this help") do
36
+ puts opts
37
+ exit
38
+ end
39
+
40
+ end.parse!
41
+
42
+ if filename = ARGV.pop
43
+ input_content = IO.read(filename)
44
+ ReverseAdoc.config.sourcedir = File.dirname(File.expand_path(filename))
45
+ else
46
+ if ReverseAdoc.config.external_images
47
+ raise "The -e | --external-images feature cannot be used with STDIN input. Exiting."
48
+ end
49
+
50
+ input_content = ARGF.read
51
+ end
52
+
53
+ if ReverseAdoc.config.external_images && ReverseAdoc.config.destination.nil?
54
+ raise "The -e | --external-images feature must be used with -o | --output. Exiting."
55
+ end
56
+
57
+ # Read from STDIN
58
+ adoc_content = ReverseAdoc.convert(input_content)
59
+
60
+ # Print to STDOUT
61
+ unless ReverseAdoc.config.destination
62
+ puts adoc_content
63
+ exit
64
+ end
65
+
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
+ file.write(adoc_content)
70
+ end
data/{bin → exe}/w2a RENAMED
@@ -6,27 +6,27 @@ require 'bundler/setup'
6
6
 
7
7
  require 'word-to-markdown'
8
8
  require 'optparse'
9
- require 'reverse_asciidoctor'
9
+ require 'reverse_adoc'
10
10
 
11
11
  ARGV.push('-h') if ARGV.empty?
12
12
 
13
13
  OptionParser.new do |opts|
14
14
  opts.banner = "Usage: w2a [options] <file>"
15
15
  opts.on('-m', '--mathml2asciimath', 'Convert MathML to AsciiMath') do |v|
16
- ReverseAsciidoctor.config.mathml2asciimath = true
16
+ ReverseAdoc.config.mathml2asciimath = true
17
17
  end
18
18
 
19
19
  opts.on('-oFILENAME', '--output=FILENAME', 'Output file to write to') do |v|
20
- ReverseAsciidoctor.config.destination = File.expand_path(v)
21
- # puts "output goes to #{ReverseAsciidoctor.config.destination}"
20
+ ReverseAdoc.config.destination = File.expand_path(v)
21
+ # puts "output goes to #{ReverseAdoc.config.destination}"
22
22
  end
23
23
 
24
24
  opts.on('-e', '--external-images', 'Export images if data URI') do |v|
25
- ReverseAsciidoctor.config.external_images = true
25
+ ReverseAdoc.config.external_images = true
26
26
  end
27
27
 
28
28
  opts.on('-v', '--version', 'Version information') do |v|
29
- puts "reverse_adoc: v#{ReverseAsciidoctor::VERSION}"
29
+ puts "reverse_adoc: v#{ReverseAdoc::VERSION}"
30
30
  puts "[dependency] WordToMarkdown: v#{WordToMarkdown::VERSION}"
31
31
  unless Gem.win_platform?
32
32
  puts "[dependency] LibreOffice: v#{WordToMarkdown.soffice.version}"
@@ -46,28 +46,28 @@ end.parse!
46
46
  filename = ARGV.pop
47
47
  raise "Please provide an input file to process. Exiting." unless filename
48
48
 
49
- if ReverseAsciidoctor.config.external_images && ReverseAsciidoctor.config.destination.nil?
49
+ if ReverseAdoc.config.external_images && ReverseAdoc.config.destination.nil?
50
50
  raise "The -e | --external-images feature must be used with -o | --output. Exiting."
51
51
  end
52
52
 
53
- ReverseAsciidoctor.config.sourcedir = Dir.mktmpdir
53
+ ReverseAdoc.config.sourcedir = Dir.mktmpdir
54
54
 
55
- doc = WordToMarkdown.new(filename, ReverseAsciidoctor.config.sourcedir)
55
+ doc = WordToMarkdown.new(filename, ReverseAdoc.config.sourcedir)
56
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),
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,6 +1,5 @@
1
- module ReverseAsciidoctor
1
+ module ReverseAdoc
2
2
  class Cleaner
3
-
4
3
  def tidy(string)
5
4
  result = remove_inner_whitespaces(string)
6
5
  result = remove_newlines(result)
@@ -14,7 +13,7 @@ module ReverseAsciidoctor
14
13
  end
15
14
 
16
15
  def remove_leading_newlines(string)
17
- string.gsub(/\A\n+/, '')
16
+ string.gsub(/\A\n+/, "")
18
17
  end
19
18
 
20
19
  def remove_inner_whitespaces(string)
@@ -25,7 +24,7 @@ module ReverseAsciidoctor
25
24
  end
26
25
  string.each_line.inject("") do |memo, line|
27
26
  memo + preserve_border_whitespaces(line) do
28
- line.strip.gsub(/[ \t]{2,}/, ' ')
27
+ line.strip.gsub(/[ \t]{2,}/, " ")
29
28
  end
30
29
  end
31
30
  end
@@ -36,65 +35,68 @@ module ReverseAsciidoctor
36
35
  # Same for underscores and brackets.
37
36
  def clean_tag_borders(string)
38
37
  result = string.gsub(/\s?\*{2,}.*?\*{2,}\s?/) do |match|
39
- preserve_border_whitespaces(match, default_border: ReverseAsciidoctor.config.tag_border) do
40
- match.strip.sub('** ', '**').sub(' **', '**')
38
+ preserve_border_whitespaces(match, default_border: ReverseAdoc.config.tag_border) do
39
+ match.strip.sub("** ", "**").sub(" **", "**")
41
40
  end
42
41
  end
43
42
 
44
- result = result.gsub(/\s?\_{2,}.*?\_{2,}\s?/) do |match|
45
- preserve_border_whitespaces(match, default_border: ReverseAsciidoctor.config.tag_border) do
46
- match.strip.sub('__ ', '__').sub(' __', '__')
43
+ result = result.gsub(/\s?_{2,}.*?_{2,}\s?/) do |match|
44
+ preserve_border_whitespaces(match, default_border: ReverseAdoc.config.tag_border) do
45
+ match.strip.sub("__ ", "__").sub(" __", "__")
47
46
  end
48
47
  end
49
48
 
50
49
  result = result.gsub(/\s?~{2,}.*?~{2,}\s?/) do |match|
51
- preserve_border_whitespaces(match, default_border: ReverseAsciidoctor.config.tag_border) do
52
- match.strip.sub('~~ ', '~~').sub(' ~~', '~~')
50
+ preserve_border_whitespaces(match, default_border: ReverseAdoc.config.tag_border) do
51
+ match.strip.sub("~~ ", "~~").sub(" ~~", "~~")
53
52
  end
54
53
  end
55
54
 
56
55
  result.gsub(/\s?\[.*?\]\s?/) do |match|
57
56
  preserve_border_whitespaces(match) do
58
- match.strip.sub('[ ', '[').sub(' ]', ']')
57
+ match.strip.sub("[ ", "[").sub(" ]", "]")
59
58
  end
60
59
  end
61
60
  end
62
61
 
63
62
  def clean_punctuation_characters(string)
64
- string.gsub(/(\*\*|~~|__)\s([\.!\?'"])/, "\\1".strip + "\\2")
63
+ string.gsub(/(\*\*|~~|__)\s([.!?'"])/, "\\1".strip + "\\2")
65
64
  end
66
65
 
67
- # preprocesses HTML, rather than postprocessing it
66
+ # preprocesses HTML, rather than postprocessing it
68
67
  def preprocess_word_html(string)
69
68
  clean_headings(scrub_whitespace(string.dup))
70
69
  end
71
70
 
72
71
  def scrub_whitespace(string)
73
- string.gsub!(/&nbsp;|\&#xA0;|\u00a0/i, '&#xA0;') # HTML encoded spaces
74
- string.sub!(/^\A[[:space:]]+/m, '') # document leading whitespace
75
- string.sub!(/[[:space:]]+\z$/m, '') # document trailing whitespace
76
- string.gsub!(/([ ]+)$/, ' ') # line trailing whitespace
77
- string.gsub!(/\n\n\n\n/, "\n\n") # Quadruple line breaks
78
- #string.delete!('?| ') # Unicode non-breaking spaces, injected as tabs
72
+ string.gsub!(/&nbsp;|&#xA0;|\u00a0/i, "&#xA0;") # HTML encoded spaces
73
+ string.sub!(/^\A[[:space:]]+/m, "") # document leading whitespace
74
+ string.sub!(/[[:space:]]+\z$/m, "") # document trailing whitespace
75
+ string.gsub!(/( +)$/, " ") # line trailing whitespace
76
+ string.gsub!(/\n\n\n\n/, "\n\n") # Quadruple line breaks
77
+ # string.delete!('?| ') # Unicode non-breaking spaces, injected as tabs
79
78
  string
80
79
  end
81
80
 
82
81
  # following added by me
83
82
  def clean_headings(string)
84
- string.gsub!(%r{<h([1-9])[^>]*></h\1>}, " ") # I don't know why Libre Office is inserting them, but they need to go
83
+ string.gsub!(%r{<h([1-9])[^>]*></h\1>}, " ")
84
+ # I don't know why Libre Office is inserting them, but they need to go
85
85
  string.gsub!(%r{<h([1-9])[^>]* style="vertical-align: super;[^>]*>(.+?)</h\1>},
86
- "<sup>\\2</sup>") # I absolutely don't know why Libre Office is rendering superscripts as h1
86
+ "<sup>\\2</sup>")
87
+ # I absolutely don't know why Libre Office is rendering superscripts as h1
87
88
  string
88
89
  end
89
90
 
90
91
  private
91
92
 
92
- def preserve_border_whitespaces(string, options = {}, &block)
93
- return string if string =~ /\A\s*\Z/
94
- default_border = options.fetch(:default_border, '')
93
+ def preserve_border_whitespaces(string, options = {})
94
+ return string if /\A\s*\Z/.match?(string)
95
+
96
+ default_border = options.fetch(:default_border, "")
95
97
  # If the string contains part of a link so the characters [,],(,)
96
98
  # then don't add any extra spaces
97
- default_border = '' if string =~ /[\[\(\]\)]/
99
+ default_border = "" if /[\[(\])]/.match?(string)
98
100
  string_start = present_or_default(string[/\A\s*/], default_border)
99
101
  string_end = present_or_default(string[/\s*\Z/], default_border)
100
102
  result = yield
@@ -108,6 +110,5 @@ module ReverseAsciidoctor
108
110
  string
109
111
  end
110
112
  end
111
-
112
113
  end
113
114
  end