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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +19 -5
  3. data/.github/workflows/ubuntu.yml +18 -5
  4. data/.github/workflows/windows.yml +20 -6
  5. data/Gemfile +2 -2
  6. data/Gemfile.lock +85 -0
  7. data/README.adoc +12 -25
  8. data/Rakefile +1 -1
  9. data/bin/reverse_adoc +20 -17
  10. data/bin/w2a +18 -31
  11. data/lib/reverse_adoc.rb +27 -0
  12. data/lib/{reverse_asciidoctor → reverse_adoc}/cleaner.rb +27 -4
  13. data/lib/{reverse_asciidoctor → reverse_adoc}/config.rb +3 -2
  14. data/lib/{reverse_asciidoctor → reverse_adoc}/converters.rb +6 -6
  15. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/a.rb +1 -1
  16. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/aside.rb +1 -1
  17. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/audio.rb +1 -1
  18. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/base.rb +2 -2
  19. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/blockquote.rb +2 -2
  20. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/br.rb +1 -1
  21. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/bypass.rb +1 -1
  22. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/code.rb +1 -1
  23. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/div.rb +1 -1
  24. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/drop.rb +1 -1
  25. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/em.rb +1 -1
  26. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/figure.rb +1 -1
  27. data/lib/reverse_adoc/converters/h.rb +34 -0
  28. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/head.rb +1 -1
  29. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/hr.rb +1 -1
  30. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/ignore.rb +1 -1
  31. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/img.rb +27 -29
  32. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/li.rb +1 -1
  33. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/mark.rb +1 -1
  34. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/math.rb +3 -3
  35. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/ol.rb +1 -1
  36. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/p.rb +1 -1
  37. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/pass_through.rb +1 -1
  38. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/pre.rb +1 -1
  39. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/q.rb +1 -1
  40. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/strong.rb +1 -1
  41. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/sub.rb +1 -1
  42. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/sup.rb +1 -1
  43. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/table.rb +1 -1
  44. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/td.rb +1 -1
  45. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/text.rb +1 -1
  46. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/th.rb +1 -1
  47. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/tr.rb +1 -1
  48. data/lib/{reverse_asciidoctor → reverse_adoc}/converters/video.rb +1 -1
  49. data/lib/{reverse_asciidoctor → reverse_adoc}/errors.rb +1 -1
  50. data/lib/reverse_adoc/html_converter.rb +56 -0
  51. data/lib/reverse_adoc/version.rb +3 -0
  52. data/reverse_adoc.gemspec +4 -2
  53. data/spec/assets/anchors.html +2 -0
  54. data/spec/assets/external_images.docx +0 -0
  55. data/spec/assets/external_images.html +35 -0
  56. data/spec/bin/reverse_adoc_spec.rb +32 -0
  57. data/spec/bin/w2a_spec.rb +35 -0
  58. data/spec/components/anchors_spec.rb +3 -2
  59. data/spec/components/basic_spec.rb +2 -2
  60. data/spec/components/code_spec.rb +4 -4
  61. data/spec/components/escapables_spec.rb +2 -2
  62. data/spec/components/from_the_wild_spec.rb +2 -2
  63. data/spec/components/html_fragment_spec.rb +2 -2
  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 -9
  69. data/spec/lib/reverse_adoc.rb +90 -0
  70. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/cleaner_spec.rb +28 -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 -2
  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 -2
  77. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/div_spec.rb +2 -2
  78. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/figure_spec.rb +2 -2
  79. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/img_spec.rb +2 -2
  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 -2
  83. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters/pre_spec.rb +2 -2
  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 -2
  88. data/spec/lib/{reverse_asciidoctor → reverse_adoc}/converters_spec.rb +5 -5
  89. data/spec/spec_helper.rb +7 -2
  90. data/spec/support/shell_helpers.rb +15 -0
  91. metadata +126 -87
  92. data/lib/reverse_asciidoctor.rb +0 -70
  93. data/lib/reverse_asciidoctor/converters/h.rb +0 -19
  94. data/lib/reverse_asciidoctor/version.rb +0 -3
  95. data/spec/lib/reverse_asciidoctor_spec.rb +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de7821c8ca445117a045f3c2c28ae78f20a2185f61af5de3fff7ed064dd98c3e
4
- data.tar.gz: 53151bcdd028e693da6b496df31c7a7da5ffa1dea8b0ee22696011a91fae074a
3
+ metadata.gz: abd0bf0dce3d437c176a1c3486d565fedd235d4b4e58cfdb4259188a1a94e090
4
+ data.tar.gz: '08926fcde9721aecc4672ac81c1dce18bf750763fe60621f57eb4cc32605eb70'
5
5
  SHA512:
6
- metadata.gz: 4ae2e50d201e868dc7caa44a599695c6d03f155dd72013888d3cdee5505b074aa37cfc93cfc96435e43fa9bc0096ed46742dd2ff77280957c99cde1ca6454cee
7
- data.tar.gz: 8a628ecfe850737831d5f1e10ef30ee65390f9599d7d75f7323de4ca39445c2d873fbaca49db7178b913d696a8fce85c50ce780a7e1715a37a12dce7c4e63cc4
6
+ metadata.gz: 39bf9ee3868bbb02440e2d853839a267f4c385e84204aedaeabe1000a7fa3fdc3f9e6baf381025548633b02b5c9e8f7d87925044c3ec992ca1eca2b83e7722b6
7
+ data.tar.gz: 5c34f9d71fa904a05c2e726b627d944f61a09f08e50ff587a102cc6e42c107600e08ad4b583fb5c9a07d678c09f06bc86fe25c15b94ae2dbefa0f29d046796bf
@@ -1,27 +1,41 @@
1
- # Auto-generated !!! Do not edit it manually
2
- # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
3
  name: macos
4
4
 
5
- on: [push]
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
9
+ paths-ignore:
10
+ - .github/workflows/ubuntu.yml
11
+ - .github/workflows/windows.yml
6
12
 
7
13
  jobs:
8
14
  test-macos:
9
15
  name: Test on Ruby ${{ matrix.ruby }} macOS
10
16
  runs-on: macos-latest
17
+ continue-on-error: ${{ matrix.experimental }}
11
18
  strategy:
19
+ fail-fast: false
12
20
  matrix:
13
21
  ruby: [ '2.6', '2.5', '2.4' ]
22
+ experimental: [false]
23
+ include:
24
+ - ruby: '2.7'
25
+ experimental: true
14
26
  steps:
15
27
  - uses: actions/checkout@master
16
28
  - name: Use Ruby
17
29
  uses: actions/setup-ruby@v1
18
30
  with:
19
31
  ruby-version: ${{ matrix.ruby }}
20
- architecture: 'x64'
21
32
  - name: Update gems
22
33
  run: |
23
- sudo gem install bundler -v "~> 2" --force
34
+ sudo gem install bundler --force
24
35
  bundle install --jobs 4 --retry 3
36
+ - name: Install LibreOffice
37
+ run: |
38
+ brew cask install libreoffice
25
39
  - name: Run specs
26
40
  run: |
27
41
  bundle exec rake
@@ -1,26 +1,39 @@
1
- # Auto-generated !!! Do not edit it manually
2
- # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
3
  name: ubuntu
4
4
 
5
- on: [push]
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
9
+ paths-ignore:
10
+ - .github/workflows/macos.yml
11
+ - .github/workflows/windows.yml
6
12
 
7
13
  jobs:
8
14
  test-linux:
9
15
  name: Test on Ruby ${{ matrix.ruby }} Ubuntu
10
16
  runs-on: ubuntu-latest
17
+ continue-on-error: ${{ matrix.experimental }}
11
18
  strategy:
19
+ fail-fast: false
12
20
  matrix:
13
21
  ruby: [ '2.6', '2.5', '2.4' ]
22
+ experimental: [false]
23
+ include:
24
+ - ruby: '2.7'
25
+ experimental: true
14
26
  steps:
15
27
  - uses: actions/checkout@master
16
28
  - name: Use Ruby
17
29
  uses: actions/setup-ruby@v1
18
30
  with:
19
31
  ruby-version: ${{ matrix.ruby }}
20
- architecture: 'x64'
32
+ - name: Install LibreOffice
33
+ run: sudo apt-get -y --no-install-recommends install libreoffice
21
34
  - name: Update gems
22
35
  run: |
23
- gem install bundler -v "~> 2"
36
+ gem install bundler
24
37
  bundle install --jobs 4 --retry 3
25
38
  - name: Run specs
26
39
  run: |
@@ -1,29 +1,43 @@
1
- # Auto-generated !!! Do not edit it manually
2
- # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
3
  name: windows
4
4
 
5
- on: [push]
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
9
+ paths-ignore:
10
+ - .github/workflows/macos.yml
11
+ - .github/workflows/ubuntu.yml
6
12
 
7
13
  jobs:
8
14
  test-windows:
9
15
  name: Test on Ruby ${{ matrix.ruby }} Windows
10
16
  runs-on: windows-latest
17
+ continue-on-error: ${{ matrix.experimental }}
11
18
  strategy:
19
+ fail-fast: false
12
20
  matrix:
13
21
  ruby: [ '2.6', '2.5', '2.4' ]
22
+ experimental: [false]
23
+ include:
24
+ - ruby: '2.7'
25
+ experimental: true
14
26
  steps:
15
27
  - uses: actions/checkout@master
16
28
  - name: Use Ruby
17
29
  uses: actions/setup-ruby@v1
18
30
  with:
19
31
  ruby-version: ${{ matrix.ruby }}
20
- architecture: 'x64'
32
+ - name: Install LibreOffice
33
+ run: |
34
+ choco install libreoffice-still
35
+ echo "::add-path::C:\Program Files\LibreOffice\program"
21
36
  - name: Update gems
22
37
  shell: pwsh
23
38
  run: |
24
- gem install bundler -v "~> 2"
39
+ gem install bundler
25
40
  bundle config --local path vendor/bundle
26
- bundle update
27
41
  bundle install --jobs 4 --retry 3
28
42
  - name: Run specs
29
43
  run: |
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"
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ reverse_adoc (0.2.10)
5
+ mathml2asciimath
6
+ mimemagic
7
+ nokogiri (>= 1.10.4)
8
+ premailer (~> 1.11.0)
9
+ word-to-markdown
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ addressable (2.7.0)
15
+ public_suffix (>= 2.0.2, < 5.0)
16
+ byebug (11.1.1)
17
+ cliver (0.3.2)
18
+ codeclimate-test-reporter (1.0.7)
19
+ simplecov
20
+ css_parser (1.7.1)
21
+ addressable
22
+ descriptive_statistics (2.5.1)
23
+ diff-lcs (1.3)
24
+ docile (1.3.2)
25
+ ffi (1.13.1)
26
+ htmlentities (4.3.4)
27
+ mathml2asciimath (0.0.10)
28
+ htmlentities (~> 4.3.4)
29
+ nokogiri (>= 1.10.4)
30
+ mimemagic (0.3.5)
31
+ mini_portile2 (2.4.0)
32
+ nokogiri (1.10.10)
33
+ mini_portile2 (~> 2.4.0)
34
+ nokogiri-styles (0.1.2)
35
+ nokogiri
36
+ premailer (1.11.1)
37
+ addressable
38
+ css_parser (>= 1.6.0)
39
+ htmlentities (>= 4.0.0)
40
+ public_suffix (4.0.6)
41
+ rake (13.0.1)
42
+ redcarpet (3.5.0)
43
+ reverse_markdown (1.4.0)
44
+ nokogiri
45
+ rspec (3.9.0)
46
+ rspec-core (~> 3.9.0)
47
+ rspec-expectations (~> 3.9.0)
48
+ rspec-mocks (~> 3.9.0)
49
+ rspec-core (3.9.1)
50
+ rspec-support (~> 3.9.1)
51
+ rspec-expectations (3.9.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.9.0)
54
+ rspec-mocks (3.9.1)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.9.0)
57
+ rspec-support (3.9.2)
58
+ simplecov (0.18.5)
59
+ docile (~> 1.1)
60
+ simplecov-html (~> 0.11)
61
+ simplecov-html (0.12.1)
62
+ sys-proctable (1.2.6)
63
+ ffi
64
+ word-to-markdown (1.1.8)
65
+ cliver (~> 0.3)
66
+ descriptive_statistics (~> 2.5)
67
+ nokogiri-styles (~> 0.1)
68
+ premailer (~> 1.8)
69
+ reverse_markdown (~> 1.0)
70
+ sys-proctable (~> 1.0)
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ byebug
77
+ codeclimate-test-reporter
78
+ rake
79
+ redcarpet
80
+ reverse_adoc!
81
+ rspec
82
+ simplecov
83
+
84
+ BUNDLED WITH
85
+ 2.0.2
@@ -1,11 +1,12 @@
1
1
  = AsciiDoc from HTML and Microsoft Word: reverse_adoc
2
2
 
3
- image:https://img.shields.io/gem/v/reverse_asciidoctor.svg["Gem Version", link="https://rubygems.org/gems/reverse_asciidoctor"]
4
- image:https://travis-ci.com/metanorma/reverse_asciidoctor.svg["Build Status", link="https://travis-ci.com/metanorma/reverse_asciidoctor"]
5
- image:https://ci.appveyor.com/api/projects/status/9dui2fs4pc590f4k?svg=true["Appveyor Build Status", link="https://ci.appveyor.com/project/metanorma/reverse-asciidoctor"]
6
- image:https://codeclimate.com/github/metanorma/reverse_asciidoctor/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/reverse_asciidoctor"]
7
- image:https://img.shields.io/github/issues-pr-raw/metanorma/reverse_asciidoctor.svg["Pull Requests", link="https://github.com/metanorma/reverse_asciidoctor/pulls"]
8
- image:https://img.shields.io/github/commits-since/metanorma/reverse_asciidoctor/latest.svg["Commits since latest",link="https://github.com/metanorma/reverse_asciidoctor/releases"]
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"]
7
+ image:https://codeclimate.com/github/metanorma/reverse_adoc/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/reverse_adoc"]
8
+ image:https://img.shields.io/github/issues-pr-raw/metanorma/reverse_adoc.svg["Pull Requests", link="https://github.com/metanorma/reverse_adoc/pulls"]
9
+ image:https://img.shields.io/github/commits-since/metanorma/reverse_adoc/latest.svg["Commits since latest",link="https://github.com/metanorma/reverse_adoc/releases"]
9
10
 
10
11
  == Purpose
11
12
 
@@ -43,20 +44,6 @@ $ reverse_adoc file.html > file.adoc
43
44
  $ cat file.html | reverse_adoc > file.adoc
44
45
  ----
45
46
 
46
- [source,console]
47
- ----
48
- $ reverse_adoc -h
49
- Usage: reverse_adoc [options] <file>
50
- -m, --mathml2asciimath Convert MathML to AsciiMath
51
- -o, --output=FILENAME Output file to write to
52
- -e, --external-images Export images if data URI
53
- -u [pass_through, drop, bypass, raise],
54
- --unknown_tags Unknown tag handling (default: pass_through)
55
- -v, --version Version information
56
- -h, --help Prints this help
57
- ----
58
-
59
-
60
47
 
61
48
  === Microsoft Word to AsciiDoc: `w2a`
62
49
 
@@ -235,7 +222,7 @@ The gem does not support:
235
222
  === MathML support
236
223
 
237
224
  If you are using this gem in the context of https://www.metanorma.com[Metanorma],
238
- Metanorma Asciidoctor accepts MathML as a native mathematical format. So you do not need
225
+ Metanorma AsciiDoc accepts MathML as a native mathematical format. So you do not need
239
226
  to convert the MathML to AsciiMath.
240
227
 
241
228
  The gem will optionally invoke the https://github.com/metanorma/mathml2asciimath
@@ -253,7 +240,7 @@ uses the output) as such; so this is still much better than nothing for stem pro
253
240
 
254
241
  === Word cleanup
255
242
 
256
- This gem is routinely used in the Metanorma project to export Word documents to Asciidoctor.
243
+ This gem is routinely used in the Metanorma project to export Word documents to AsciiDoc.
257
244
  The HTML export from Word that the gem uses, from LibreOffice, is much cleaner than the
258
245
  native HTML 4 export from Word; but it has some infelicities which this gem cleans up:
259
246
 
@@ -272,7 +259,7 @@ Simple to use.
272
259
 
273
260
  [source,ruby]
274
261
  ----
275
- result = ReverseAsciidoctor.convert input
262
+ result = ReverseAdoc.convert input
276
263
  result.inspect # " *feelings* "
277
264
  ----
278
265
 
@@ -282,7 +269,7 @@ Just pass your chosen configuration options in after the input. The given option
282
269
 
283
270
  [source,ruby]
284
271
  ----
285
- ReverseAsciidoctor.convert(input, unknown_tags: :raise, mathml2asciimath: true)
272
+ ReverseAdoc.convert(input, unknown_tags: :raise, mathml2asciimath: true)
286
273
  ----
287
274
 
288
275
 
@@ -292,7 +279,7 @@ Or configure it block style on a initializer level. These configurations will la
292
279
 
293
280
  [source,ruby]
294
281
  ----
295
- ReverseAsciidoctor.config do |config|
282
+ ReverseAdoc.config do |config|
296
283
  config.unknown_tags = :bypass
297
284
  config.mathml2asciimath = true
298
285
  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
@@ -1,31 +1,34 @@
1
1
  #!/usr/bin/env ruby
2
- # Usage: reverse_asciidoctor [FILE]...
3
- # Usage: cat FILE | reverse_asciidoctor
4
- require 'reverse_asciidoctor'
2
+ # Usage: reverse_adoc [FILE]...
3
+ # Usage: cat FILE | reverse_adoc
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
+
7
+ require 'reverse_adoc'
5
8
  require 'optparse'
6
9
  require 'fileutils'
7
10
 
8
11
  OptionParser.new do |opts|
9
12
  opts.banner = "Usage: reverse_adoc [options] <file>"
10
13
  opts.on('-m', '--mathml2asciimath', 'Convert MathML to AsciiMath') do |v|
11
- ReverseAsciidoctor.config.mathml2asciimath = true
14
+ ReverseAdoc.config.mathml2asciimath = true
12
15
  end
13
16
 
14
17
  opts.on('-oFILENAME', '--output=FILENAME', 'Output file to write to') do |v|
15
- ReverseAsciidoctor.config.destination = File.expand_path(v)
16
- # puts "output goes to #{ReverseAsciidoctor.config.destination}"
18
+ ReverseAdoc.config.destination = File.expand_path(v)
19
+ # puts "output goes to #{ReverseAdoc.config.destination}"
17
20
  end
18
21
 
19
22
  opts.on('-e', '--external-images', 'Export images if data URI') do |v|
20
- ReverseAsciidoctor.config.external_images = true
23
+ ReverseAdoc.config.external_images = true
21
24
  end
22
25
 
23
26
  opts.on('-u', '--unknown_tags [pass_through, drop, bypass, raise]', 'Unknown tag handling (default: pass_through)') do |v|
24
- ReverseAsciidoctor.config.unknown_tags = v
27
+ ReverseAdoc.config.unknown_tags = v
25
28
  end
26
29
 
27
30
  opts.on('-v', '--version', 'Version information') do |v|
28
- puts "reverse_adoc: v#{ReverseAsciidoctor::VERSION}"
31
+ puts "reverse_adoc: v#{ReverseAdoc::VERSION}"
29
32
  exit
30
33
  end
31
34
 
@@ -38,30 +41,30 @@ end.parse!
38
41
 
39
42
  if filename = ARGV.pop
40
43
  input_content = IO.read(filename)
41
- ReverseAsciidoctor.config.sourcedir = File.dirname(File.expand_path(filename))
44
+ ReverseAdoc.config.sourcedir = File.dirname(File.expand_path(filename))
42
45
  else
43
- if ReverseAsciidoctor.config.external_images
46
+ if ReverseAdoc.config.external_images
44
47
  raise "The -e | --external-images feature cannot be used with STDIN input. Exiting."
45
48
  end
46
49
 
47
50
  input_content = ARGF.read
48
51
  end
49
52
 
50
- if ReverseAsciidoctor.config.external_images && ReverseAsciidoctor.config.destination.nil?
53
+ if ReverseAdoc.config.external_images && ReverseAdoc.config.destination.nil?
51
54
  raise "The -e | --external-images feature must be used with -o | --output. Exiting."
52
55
  end
53
56
 
54
57
  # Read from STDIN
55
- adoc_content = ReverseAsciidoctor.convert(input_content)
58
+ adoc_content = ReverseAdoc.convert(input_content)
56
59
 
57
60
  # Print to STDOUT
58
- unless ReverseAsciidoctor.config.destination
61
+ unless ReverseAdoc.config.destination
59
62
  puts adoc_content
60
63
  exit
61
64
  end
62
65
 
63
- # Write output to ReverseAsciidoctor.config.destination
64
- FileUtils.mkdir_p(File.dirname(ReverseAsciidoctor.config.destination))
65
- 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|
66
69
  file.write(adoc_content)
67
70
  end
data/bin/w2a CHANGED
@@ -1,44 +1,32 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
+
4
7
  require 'word-to-markdown'
5
8
  require 'optparse'
6
- require 'reverse_asciidoctor'
7
-
8
- def scrub_whitespace(string)
9
- string = string.dup
10
- string.gsub!(/&nbsp;|\&#xA0;|\u00a0/i, '&#xA0;') # HTML encoded spaces
11
- string.sub!(/^\A[[:space:]]+/m, '') # document leading whitespace
12
- string.sub!(/[[:space:]]+\z$/m, '') # document trailing whitespace
13
- string.gsub!(/([ ]+)$/, ' ') # line trailing whitespace
14
- string.gsub!(/\n\n\n\n/, "\n\n") # Quadruple line breaks
15
- #string.delete!(' ') # Unicode non-breaking spaces, injected as tabs
16
- # following added by me
17
- string.gsub!(%r{<h[1-9][^>]*></h1>}, " ") # I don't know why Libre Office is inserting them, but they need to go
18
- string.gsub!(%r{<h1[^>]* style="vertical-align: super;[^>]*>([^<]+)</h1>},
19
- "<sup>\\1</sup>") # I absolutely don't know why Libre Office is rendering superscripts as h1
20
- string
21
- end
9
+ require 'reverse_adoc'
22
10
 
23
11
  ARGV.push('-h') if ARGV.empty?
24
12
 
25
13
  OptionParser.new do |opts|
26
14
  opts.banner = "Usage: w2a [options] <file>"
27
15
  opts.on('-m', '--mathml2asciimath', 'Convert MathML to AsciiMath') do |v|
28
- ReverseAsciidoctor.config.mathml2asciimath = true
16
+ ReverseAdoc.config.mathml2asciimath = true
29
17
  end
30
18
 
31
19
  opts.on('-oFILENAME', '--output=FILENAME', 'Output file to write to') do |v|
32
- ReverseAsciidoctor.config.destination = File.expand_path(v)
33
- # puts "output goes to #{ReverseAsciidoctor.config.destination}"
20
+ ReverseAdoc.config.destination = File.expand_path(v)
21
+ # puts "output goes to #{ReverseAdoc.config.destination}"
34
22
  end
35
23
 
36
24
  opts.on('-e', '--external-images', 'Export images if data URI') do |v|
37
- ReverseAsciidoctor.config.external_images = true
25
+ ReverseAdoc.config.external_images = true
38
26
  end
39
27
 
40
28
  opts.on('-v', '--version', 'Version information') do |v|
41
- puts "reverse_adoc: v#{ReverseAsciidoctor::VERSION}"
29
+ puts "reverse_adoc: v#{ReverseAdoc::VERSION}"
42
30
  puts "[dependency] WordToMarkdown: v#{WordToMarkdown::VERSION}"
43
31
  unless Gem.win_platform?
44
32
  puts "[dependency] LibreOffice: v#{WordToMarkdown.soffice.version}"
@@ -58,29 +46,28 @@ end.parse!
58
46
  filename = ARGV.pop
59
47
  raise "Please provide an input file to process. Exiting." unless filename
60
48
 
61
- if ReverseAsciidoctor.config.external_images && ReverseAsciidoctor.config.destination.nil?
49
+ if ReverseAdoc.config.external_images && ReverseAdoc.config.destination.nil?
62
50
  raise "The -e | --external-images feature must be used with -o | --output. Exiting."
63
51
  end
64
52
 
65
- ReverseAsciidoctor.config.sourcedir = Dir.mktmpdir
66
- # puts "ReverseAsciidoctor.config.sourcedir #{ReverseAsciidoctor.config.sourcedir}"
53
+ ReverseAdoc.config.sourcedir = Dir.mktmpdir
67
54
 
68
- doc = WordToMarkdown.new(filename, ReverseAsciidoctor.config.sourcedir)
55
+ doc = WordToMarkdown.new(filename, ReverseAdoc.config.sourcedir)
69
56
  #File.open("test.html", "w:UTF-8") { |f| f.write doc.document.html }
70
- adoc_content = ReverseAsciidoctor.convert(
71
- scrub_whitespace(doc.document.html),
57
+ adoc_content = ReverseAdoc.convert(
58
+ ReverseAdoc.cleaner.preprocess_word_html(doc.document.html),
72
59
  WordToMarkdown::REVERSE_MARKDOWN_OPTIONS
73
60
  )
74
61
  # puts scrub_whitespace(doc.document.html)
75
62
 
76
63
  # Print to STDOUT
77
- unless ReverseAsciidoctor.config.destination
64
+ unless ReverseAdoc.config.destination
78
65
  puts adoc_content
79
66
  exit
80
67
  end
81
68
 
82
- # Write output to ReverseAsciidoctor.config.destination
83
- FileUtils.mkdir_p(File.dirname(ReverseAsciidoctor.config.destination))
84
- 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|
85
72
  file.write(adoc_content)
86
73
  end