reverse_adoc 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +8 -4
  3. data/.github/workflows/ubuntu.yml +10 -4
  4. data/.github/workflows/windows.yml +12 -5
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +84 -0
  7. data/README.adoc +11 -0
  8. data/bin/reverse_adoc +5 -1
  9. data/bin/w2a +2 -2
  10. data/lib/reverse_asciidoctor.rb +7 -47
  11. data/lib/reverse_asciidoctor/config.rb +2 -1
  12. data/lib/reverse_asciidoctor/converters/example.rb +17 -0
  13. data/lib/reverse_asciidoctor/converters/express_ref.rb +12 -0
  14. data/lib/reverse_asciidoctor/converters/ext_description.rb +16 -0
  15. data/lib/reverse_asciidoctor/converters/ext_descriptions.rb +12 -0
  16. data/lib/reverse_asciidoctor/converters/img.rb +2 -2
  17. data/lib/reverse_asciidoctor/converters/note.rb +17 -0
  18. data/lib/reverse_asciidoctor/html_converter.rb +56 -0
  19. data/lib/reverse_asciidoctor/smrl_description_converter.rb +45 -0
  20. data/lib/reverse_asciidoctor/version.rb +1 -1
  21. data/spec/assets/{test.docx → external_images.docx} +0 -0
  22. data/spec/assets/{test.html → external_images.html} +0 -0
  23. data/spec/bin/reverse_adoc_spec.rb +32 -0
  24. data/spec/bin/w2a_spec.rb +35 -0
  25. data/spec/lib/reverse_asciidoctor/converters/example_spec.rb +22 -0
  26. data/spec/lib/reverse_asciidoctor/converters/express_ref_spec.rb +14 -0
  27. data/spec/lib/reverse_asciidoctor/converters/ext_description_spec.rb +20 -0
  28. data/spec/lib/reverse_asciidoctor/converters/ext_descriptions_spec.rb +13 -0
  29. data/spec/lib/reverse_asciidoctor/converters/note_spec.rb +22 -0
  30. data/spec/lib/reverse_asciidoctor_spec.rb +58 -5
  31. data/spec/spec_helper.rb +5 -0
  32. data/spec/support/shell_helpers.rb +15 -0
  33. metadata +31 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f60fbebeee21569fdf9af0bb7153a06ac7f3a8d3431d143750e96185c701c7e
4
- data.tar.gz: 72f47514bce560d201ac2b22c6b6034a02550f2e50f76200e96fa003628756f5
3
+ metadata.gz: eb34effa1c1af2e72ef8df7b6b1553c7c2574bcca9608e02cfaf561ed8a2bfec
4
+ data.tar.gz: e18b3b9cf2d936a48fdf2e6d5f265aa5c945c9493bd232a4d8fb311df780e81f
5
5
  SHA512:
6
- metadata.gz: 82babe7f90eb4445d2d2bebb16dcf5a1af869da69ac5fc4da0d14e24d456a00d80f390097b10b597dbc8ec69bf782dd04d1464ef0a73cd513b4f164267ca67e1
7
- data.tar.gz: 38b3887266e6c666b117d85d8df810b8e3d168b1a03af71c06fcd1218a3b99af0228686896248074767a207b32bdc6e7d16a8826ba1b11680b4371648f956576
6
+ metadata.gz: ca8454b96ad3064c16018f09198f8450f9a15e6525c1df6e63b7a0e3dd3254f66f2bee56e69e8c7088087962911480513f3608c759f955489b2e602dc2251890
7
+ data.tar.gz: 49c2198645f22b9ac26ea78aa36e1073a27807dca8364ad076250dccfc6b307055775894962d70d6400d7c8ec6b3dfa02cb31c84c922c60d8c18cbbf5ee55171
@@ -1,14 +1,18 @@
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:
6
9
 
7
10
  jobs:
8
11
  test-macos:
9
12
  name: Test on Ruby ${{ matrix.ruby }} macOS
10
13
  runs-on: macos-latest
11
14
  strategy:
15
+ fail-fast: false
12
16
  matrix:
13
17
  ruby: [ '2.6', '2.5', '2.4' ]
14
18
  steps:
@@ -20,7 +24,7 @@ jobs:
20
24
  architecture: 'x64'
21
25
  - name: Update gems
22
26
  run: |
23
- sudo gem install bundler -v "~> 2" --force
27
+ sudo gem install bundler --force
24
28
  bundle install --jobs 4 --retry 3
25
29
  - name: Run specs
26
30
  run: |
@@ -1,14 +1,18 @@
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:
6
9
 
7
10
  jobs:
8
11
  test-linux:
9
12
  name: Test on Ruby ${{ matrix.ruby }} Ubuntu
10
13
  runs-on: ubuntu-latest
11
14
  strategy:
15
+ fail-fast: false
12
16
  matrix:
13
17
  ruby: [ '2.6', '2.5', '2.4' ]
14
18
  steps:
@@ -18,9 +22,11 @@ jobs:
18
22
  with:
19
23
  ruby-version: ${{ matrix.ruby }}
20
24
  architecture: 'x64'
25
+ - name: Install LibreOffice
26
+ run: sudo apt-get -y --no-install-recommends install libreoffice
21
27
  - name: Update gems
22
28
  run: |
23
- gem install bundler -v "~> 2"
29
+ gem install bundler
24
30
  bundle install --jobs 4 --retry 3
25
31
  - name: Run specs
26
32
  run: |
@@ -1,14 +1,18 @@
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:
6
9
 
7
10
  jobs:
8
11
  test-windows:
9
12
  name: Test on Ruby ${{ matrix.ruby }} Windows
10
13
  runs-on: windows-latest
11
14
  strategy:
15
+ fail-fast: false
12
16
  matrix:
13
17
  ruby: [ '2.6', '2.5', '2.4' ]
14
18
  steps:
@@ -18,12 +22,15 @@ jobs:
18
22
  with:
19
23
  ruby-version: ${{ matrix.ruby }}
20
24
  architecture: 'x64'
25
+ - name: Install LibreOffice
26
+ run: |
27
+ choco install libreoffice-still
28
+ echo "::add-path::C:\Program Files\LibreOffice\program"
21
29
  - name: Update gems
22
30
  shell: pwsh
23
31
  run: |
24
- gem install bundler -v "~> 2"
32
+ gem install bundler
25
33
  bundle config --local path vendor/bundle
26
- bundle update
27
34
  bundle install --jobs 4 --retry 3
28
35
  - name: Run specs
29
36
  run: |
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source "https://rubygems.org"
2
-
2
+
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in reverse_asciidoctor.gemspec
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ reverse_adoc (0.2.8)
5
+ mathml2asciimath
6
+ mimemagic
7
+ nokogiri (>= 1.10.4)
8
+ word-to-markdown
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.7.0)
14
+ public_suffix (>= 2.0.2, < 5.0)
15
+ byebug (11.1.1)
16
+ cliver (0.3.2)
17
+ codeclimate-test-reporter (1.0.7)
18
+ simplecov
19
+ css_parser (1.7.1)
20
+ addressable
21
+ descriptive_statistics (2.5.1)
22
+ diff-lcs (1.3)
23
+ docile (1.3.2)
24
+ ffi (1.13.1)
25
+ htmlentities (4.3.4)
26
+ mathml2asciimath (0.0.10)
27
+ htmlentities (~> 4.3.4)
28
+ nokogiri (>= 1.10.4)
29
+ mimemagic (0.3.5)
30
+ mini_portile2 (2.4.0)
31
+ nokogiri (1.10.9)
32
+ mini_portile2 (~> 2.4.0)
33
+ nokogiri-styles (0.1.2)
34
+ nokogiri
35
+ premailer (1.11.1)
36
+ addressable
37
+ css_parser (>= 1.6.0)
38
+ htmlentities (>= 4.0.0)
39
+ public_suffix (4.0.5)
40
+ rake (13.0.1)
41
+ redcarpet (3.5.0)
42
+ reverse_markdown (1.4.0)
43
+ nokogiri
44
+ rspec (3.9.0)
45
+ rspec-core (~> 3.9.0)
46
+ rspec-expectations (~> 3.9.0)
47
+ rspec-mocks (~> 3.9.0)
48
+ rspec-core (3.9.1)
49
+ rspec-support (~> 3.9.1)
50
+ rspec-expectations (3.9.0)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.9.0)
53
+ rspec-mocks (3.9.1)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.9.0)
56
+ rspec-support (3.9.2)
57
+ simplecov (0.18.5)
58
+ docile (~> 1.1)
59
+ simplecov-html (~> 0.11)
60
+ simplecov-html (0.12.1)
61
+ sys-proctable (1.2.5)
62
+ ffi
63
+ word-to-markdown (1.1.8)
64
+ cliver (~> 0.3)
65
+ descriptive_statistics (~> 2.5)
66
+ nokogiri-styles (~> 0.1)
67
+ premailer (~> 1.8)
68
+ reverse_markdown (~> 1.0)
69
+ sys-proctable (~> 1.0)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ byebug
76
+ codeclimate-test-reporter
77
+ rake
78
+ redcarpet
79
+ reverse_adoc!
80
+ rspec
81
+ simplecov
82
+
83
+ BUNDLED WITH
84
+ 2.0.2
@@ -44,10 +44,21 @@ $ reverse_adoc file.html > file.adoc
44
44
  $ cat file.html | reverse_adoc > file.adoc
45
45
  ----
46
46
 
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
+
47
57
  [source,console]
48
58
  ----
49
59
  $ reverse_adoc -h
50
60
  Usage: reverse_adoc [options] <file>
61
+ -f, --input_format Supply input format to choose converter(html or smrl_description)
51
62
  -m, --mathml2asciimath Convert MathML to AsciiMath
52
63
  -o, --output=FILENAME Output file to write to
53
64
  -e, --external-images Export images if data URI
@@ -4,7 +4,7 @@
4
4
  require 'rubygems'
5
5
  require 'bundler/setup'
6
6
 
7
- require 'reverse_adoc'
7
+ require 'reverse_asciidoctor'
8
8
  require 'optparse'
9
9
  require 'fileutils'
10
10
 
@@ -23,6 +23,10 @@ OptionParser.new do |opts|
23
23
  ReverseAsciidoctor.config.external_images = true
24
24
  end
25
25
 
26
+ opts.on('-f', '--input_format [html, smrl_description]', 'Unknown input format (default: html)') do |v|
27
+ ReverseAsciidoctor.config.input_format = v
28
+ end
29
+
26
30
  opts.on('-u', '--unknown_tags [pass_through, drop, bypass, raise]', 'Unknown tag handling (default: pass_through)') do |v|
27
31
  ReverseAsciidoctor.config.unknown_tags = v
28
32
  end
data/bin/w2a CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  require 'rubygems'
4
5
  require 'bundler/setup'
5
6
 
@@ -50,10 +51,9 @@ if ReverseAsciidoctor.config.external_images && ReverseAsciidoctor.config.destin
50
51
  end
51
52
 
52
53
  ReverseAsciidoctor.config.sourcedir = Dir.mktmpdir
53
- # puts "ReverseAsciidoctor.config.sourcedir #{ReverseAsciidoctor.config.sourcedir}"
54
54
 
55
55
  doc = WordToMarkdown.new(filename, ReverseAsciidoctor.config.sourcedir)
56
- File.open("test.html", "w:UTF-8") { |f| f.write doc.document.html }
56
+ #File.open("test.html", "w:UTF-8") { |f| f.write doc.document.html }
57
57
  adoc_content = ReverseAsciidoctor.convert(
58
58
  ReverseAsciidoctor.cleaner.preprocess_word_html(doc.document.html),
59
59
  WordToMarkdown::REVERSE_MARKDOWN_OPTIONS
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'digest'
2
4
  require 'nokogiri'
3
5
  require 'reverse_asciidoctor/version'
@@ -6,55 +8,14 @@ require 'reverse_asciidoctor/cleaner'
6
8
  require 'reverse_asciidoctor/config'
7
9
  require 'reverse_asciidoctor/converters'
8
10
  require 'reverse_asciidoctor/converters/base'
9
- require 'reverse_asciidoctor/converters/a'
10
- require 'reverse_asciidoctor/converters/aside'
11
- require 'reverse_asciidoctor/converters/audio'
12
- require 'reverse_asciidoctor/converters/blockquote'
13
- require 'reverse_asciidoctor/converters/br'
14
- require 'reverse_asciidoctor/converters/bypass'
15
- require 'reverse_asciidoctor/converters/code'
16
- require 'reverse_asciidoctor/converters/div'
17
- require 'reverse_asciidoctor/converters/drop'
18
- require 'reverse_asciidoctor/converters/em'
19
- require 'reverse_asciidoctor/converters/figure'
20
- require 'reverse_asciidoctor/converters/h'
21
- require 'reverse_asciidoctor/converters/head'
22
- require 'reverse_asciidoctor/converters/hr'
23
- require 'reverse_asciidoctor/converters/ignore'
24
- require 'reverse_asciidoctor/converters/img'
25
- require 'reverse_asciidoctor/converters/mark'
26
- require 'reverse_asciidoctor/converters/li'
27
- require 'reverse_asciidoctor/converters/ol'
28
- require 'reverse_asciidoctor/converters/p'
29
- require 'reverse_asciidoctor/converters/pass_through'
30
- require 'reverse_asciidoctor/converters/pre'
31
- require 'reverse_asciidoctor/converters/q'
32
- require 'reverse_asciidoctor/converters/strong'
33
- require 'reverse_asciidoctor/converters/sup'
34
- require 'reverse_asciidoctor/converters/sub'
35
- require 'reverse_asciidoctor/converters/table'
36
- require 'reverse_asciidoctor/converters/td'
37
- require 'reverse_asciidoctor/converters/th'
38
- require 'reverse_asciidoctor/converters/text'
39
- require 'reverse_asciidoctor/converters/tr'
40
- require 'reverse_asciidoctor/converters/video'
41
- require 'reverse_asciidoctor/converters/math'
42
11
 
43
12
  module ReverseAsciidoctor
44
-
45
13
  def self.convert(input, options = {})
46
- root = case input
47
- when String then Nokogiri::HTML(input).root
48
- when Nokogiri::XML::Document then input.root
49
- when Nokogiri::XML::Node then input
50
- end
51
-
52
- root or return ''
53
-
54
- config.with(options) do
55
- result = ReverseAsciidoctor::Converters.lookup(root.name).convert(root)
56
- cleaner.tidy(result)
57
- end
14
+ type = config.input_format
15
+ name = "#{type}_converter"
16
+ require "reverse_asciidoctor/#{type}_converter"
17
+ constant = name.split('_').map(&:capitalize).join.to_s
18
+ ReverseAsciidoctor.const_get(constant).convert(input, options)
58
19
  end
59
20
 
60
21
  def self.config
@@ -66,5 +27,4 @@ module ReverseAsciidoctor
66
27
  def self.cleaner
67
28
  @cleaner ||= Cleaner.new
68
29
  end
69
-
70
30
  end
@@ -3,10 +3,11 @@ require 'tmpdir'
3
3
  module ReverseAsciidoctor
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
 
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ReverseAsciidoctor
4
+ module Converters
5
+ class Example < Base
6
+ def convert(node, state = {})
7
+ <<~TEMPLATE
8
+ [example]
9
+ ====
10
+ #{treat_children(node, state)}
11
+ ====
12
+ TEMPLATE
13
+ end
14
+ end
15
+ register :example, Example.new
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ReverseAsciidoctor
4
+ module Converters
5
+ class ExpressRef < Base
6
+ def convert(node, _state = {})
7
+ "express_ref:[#{node['linkend']}]"
8
+ end
9
+ end
10
+ register :express_ref, ExpressRef.new
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ReverseAsciidoctor
4
+ module Converters
5
+ class ExtDescription < Base
6
+ def convert(node, state = {})
7
+ <<~TEMPLATE
8
+ (*"#{node['linkend']}"
9
+ #{treat_children(node, state)}
10
+ *)
11
+ TEMPLATE
12
+ end
13
+ end
14
+ register :ext_description, ExtDescription.new
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ReverseAsciidoctor
4
+ module Converters
5
+ class ExtDescriptions < Base
6
+ def convert(node, state = {})
7
+ treat_children(node, state)
8
+ end
9
+ end
10
+ register :ext_descriptions, ExtDescriptions.new
11
+ end
12
+ end
@@ -26,7 +26,7 @@ module ReverseAsciidoctor
26
26
  images_dir = dest_dir + 'images'
27
27
  FileUtils.mkdir_p(images_dir)
28
28
 
29
- ext, image_src_path = determine_image_src_path(imgdata, src)
29
+ ext, image_src_path = determine_image_src_path(src, imgdata)
30
30
  image_dest_path = images_dir + "#{image_number}.#{ext}"
31
31
 
32
32
  # puts "image_dest_path: #{image_dest_path.to_s}"
@@ -38,7 +38,7 @@ module ReverseAsciidoctor
38
38
  image_dest_path.relative_path_from(dest_dir)
39
39
  end
40
40
 
41
- def determine_image_src_path(imgdata, src)
41
+ def determine_image_src_path(src, imgdata)
42
42
  return copy_temp_file(imgdata) if imgdata
43
43
 
44
44
  ext = File.extname(src).strip.downcase[1..-1]
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ReverseAsciidoctor
4
+ module Converters
5
+ class Note < Base
6
+ def convert(node, state = {})
7
+ <<~TEMPLATE
8
+ [NOTE]
9
+ --
10
+ #{treat_children(node, state)}
11
+ --
12
+ TEMPLATE
13
+ end
14
+ end
15
+ register :note, Note.new
16
+ end
17
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'reverse_asciidoctor/converters/a'
4
+ require 'reverse_asciidoctor/converters/aside'
5
+ require 'reverse_asciidoctor/converters/audio'
6
+ require 'reverse_asciidoctor/converters/blockquote'
7
+ require 'reverse_asciidoctor/converters/br'
8
+ require 'reverse_asciidoctor/converters/bypass'
9
+ require 'reverse_asciidoctor/converters/code'
10
+ require 'reverse_asciidoctor/converters/div'
11
+ require 'reverse_asciidoctor/converters/drop'
12
+ require 'reverse_asciidoctor/converters/em'
13
+ require 'reverse_asciidoctor/converters/figure'
14
+ require 'reverse_asciidoctor/converters/h'
15
+ require 'reverse_asciidoctor/converters/head'
16
+ require 'reverse_asciidoctor/converters/hr'
17
+ require 'reverse_asciidoctor/converters/ignore'
18
+ require 'reverse_asciidoctor/converters/img'
19
+ require 'reverse_asciidoctor/converters/mark'
20
+ require 'reverse_asciidoctor/converters/li'
21
+ require 'reverse_asciidoctor/converters/ol'
22
+ require 'reverse_asciidoctor/converters/p'
23
+ require 'reverse_asciidoctor/converters/pass_through'
24
+ require 'reverse_asciidoctor/converters/pre'
25
+ require 'reverse_asciidoctor/converters/q'
26
+ require 'reverse_asciidoctor/converters/strong'
27
+ require 'reverse_asciidoctor/converters/sup'
28
+ require 'reverse_asciidoctor/converters/sub'
29
+ require 'reverse_asciidoctor/converters/table'
30
+ require 'reverse_asciidoctor/converters/td'
31
+ require 'reverse_asciidoctor/converters/th'
32
+ require 'reverse_asciidoctor/converters/text'
33
+ require 'reverse_asciidoctor/converters/tr'
34
+ require 'reverse_asciidoctor/converters/video'
35
+ require 'reverse_asciidoctor/converters/math'
36
+
37
+ module ReverseAsciidoctor
38
+ class HtmlConverter
39
+ def self.convert(input, options = {})
40
+ root = if input.is_a?(String)
41
+ then Nokogiri::HTML(input).root
42
+ elsif input.is_a?(Nokogiri::XML::Document)
43
+ then input.root
44
+ elsif input.is_a?(Nokogiri::XML::Node)
45
+ then input
46
+ end
47
+
48
+ root || (return '')
49
+
50
+ ReverseAsciidoctor.config.with(options) do
51
+ result = ReverseAsciidoctor::Converters.lookup(root.name).convert(root)
52
+ ReverseAsciidoctor.cleaner.tidy(result)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'reverse_asciidoctor/converters/a'
4
+ require 'reverse_asciidoctor/converters/blockquote'
5
+ require 'reverse_asciidoctor/converters/bypass'
6
+ require 'reverse_asciidoctor/converters/br'
7
+ require 'reverse_asciidoctor/converters/code'
8
+ require 'reverse_asciidoctor/converters/drop'
9
+ require 'reverse_asciidoctor/converters/em'
10
+ require 'reverse_asciidoctor/converters/example'
11
+ require 'reverse_asciidoctor/converters/ext_descriptions'
12
+ require 'reverse_asciidoctor/converters/ext_description'
13
+ require 'reverse_asciidoctor/converters/express_ref'
14
+ require 'reverse_asciidoctor/converters/head'
15
+ require 'reverse_asciidoctor/converters/hr'
16
+ require 'reverse_asciidoctor/converters/ignore'
17
+ require 'reverse_asciidoctor/converters/note'
18
+ require 'reverse_asciidoctor/converters/p'
19
+ require 'reverse_asciidoctor/converters/pass_through'
20
+ require 'reverse_asciidoctor/converters/q'
21
+ require 'reverse_asciidoctor/converters/strong'
22
+ require 'reverse_asciidoctor/converters/sup'
23
+ require 'reverse_asciidoctor/converters/sub'
24
+ require 'reverse_asciidoctor/converters/text'
25
+
26
+ module ReverseAsciidoctor
27
+ class SmrlDescriptionConverter
28
+ def self.convert(input, options = {})
29
+ root = if input.is_a?(String)
30
+ then Nokogiri::XML(input).root
31
+ elsif input.is_a?(Nokogiri::XML::Document)
32
+ then input.root
33
+ elsif input.is_a?(Nokogiri::XML::Node)
34
+ then input
35
+ end
36
+
37
+ root || (return '')
38
+
39
+ ReverseAsciidoctor.config.with(options) do
40
+ result = ReverseAsciidoctor::Converters.lookup(root.name).convert(root)
41
+ ReverseAsciidoctor.cleaner.tidy(result)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module ReverseAsciidoctor
2
- VERSION = '0.2.7'
2
+ VERSION = '0.2.8'
3
3
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'bin/revrse_adoc' do
6
+ subject(:convert) do
7
+ ShellUtils.execute!("./bin/reverse_adoc -e -o test1 #{input_file_path}")
8
+ end
9
+ unless Gem.win_platform?
10
+ context 'when external images present' do
11
+ let(:input_file_path) { 'spec/assets/external_images.html' }
12
+ let(:images_folder) { 'images' }
13
+
14
+ after do
15
+ FileUtils.rm_rf(images_folder) if File.directory?(images_folder)
16
+ end
17
+
18
+ it 'Does not raise error' do
19
+ expect { convert }.to_not raise_error
20
+ end
21
+
22
+ it 'exatracts images from source html' do
23
+ expect { convert }
24
+ .to(change do
25
+ Dir["#{images_folder}/*gif"]
26
+ .map { |entry| File.basename(entry) }
27
+ .sort
28
+ end.from([]).to(['001.gif']))
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'bin/w2a' do
6
+ subject(:convert) do
7
+ ShellUtils.execute!("./bin/w2a -e -o test1 #{input_file_path}")
8
+ end
9
+ # TODO: fix github actions integration with libreoffice, currently it hangs
10
+ # when trying to use soffice binary
11
+ unless Gem.win_platform? ||
12
+ (Gem::Platform.local.os == 'darwin' && !ENV['GITHUB_ACTION'].nil?)
13
+ context 'when external images present' do
14
+ let(:input_file_path) { 'spec/assets/external_images.docx' }
15
+ let(:images_folder) { 'images' }
16
+
17
+ after do
18
+ FileUtils.rm_rf(images_folder) if File.directory?(images_folder)
19
+ end
20
+
21
+ it 'Does not raise error' do
22
+ expect { convert }.to_not raise_error
23
+ end
24
+
25
+ it 'exatracts images from source html' do
26
+ expect { convert }
27
+ .to(change do
28
+ Dir["#{images_folder}/*gif"]
29
+ .map { |entry| File.basename(entry) }
30
+ .sort
31
+ end.from([]).to(['001.gif', '002.gif']))
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'reverse_asciidoctor/converters/example'
5
+
6
+ describe ReverseAsciidoctor::Converters::Example do
7
+ let(:converter) { described_class.new }
8
+ let(:output) do
9
+ <<~TEXT
10
+ [example]
11
+ ====
12
+ foo
13
+
14
+ ====
15
+ TEXT
16
+ end
17
+
18
+ it 'converts example` children' do
19
+ input = node_for('<example><li>foo</li></example>')
20
+ expect(converter.convert(input)).to eq(output)
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'reverse_asciidoctor/converters/express_ref'
5
+
6
+ describe ReverseAsciidoctor::Converters::ExpressRef do
7
+ let(:converter) { described_class.new }
8
+ let(:schema) { 'schema' }
9
+
10
+ it 'converts supplied tag by format' do
11
+ input = node_for("<express_ref linkend='#{schema}' />")
12
+ expect(converter.convert(input)).to eq("express_ref:[#{schema}]")
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'reverse_asciidoctor/converters/ext_description'
5
+
6
+ describe ReverseAsciidoctor::Converters::ExtDescription do
7
+ let(:converter) { described_class.new }
8
+ let(:schema) { 'schema' }
9
+
10
+ it 'takes ext_description linkend attribute' do
11
+ input = node_for("<ext_description linkend='#{schema}'></ext_description>")
12
+ expect(converter.convert(input)).to include(%{(*"#{schema}"})
13
+ end
14
+
15
+ it 'converts html children' do
16
+ input = node_for(
17
+ "<ext_description linkend='#{schema}'><li>foo</li></ext_description>")
18
+ expect(converter.convert(input)).to include(" foo\n")
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'reverse_asciidoctor/converters/ext_descriptions'
5
+
6
+ describe ReverseAsciidoctor::Converters::ExtDescriptions do
7
+ let(:converter) { described_class.new }
8
+
9
+ it 'converts ext_descriptions children' do
10
+ input = node_for('<ext_descriptions><li>foo</li></ext_descriptions>')
11
+ expect(converter.convert(input)).to eq " foo\n"
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'reverse_asciidoctor/converters/note'
5
+
6
+ describe ReverseAsciidoctor::Converters::Note do
7
+ let(:converter) { described_class.new }
8
+ let(:output) do
9
+ <<~TEXT
10
+ [NOTE]
11
+ --
12
+ foo
13
+
14
+ --
15
+ TEXT
16
+ end
17
+
18
+ it 'converts note` children' do
19
+ input = node_for('<note><li>foo</li></note>')
20
+ expect(converter.convert(input)).to eq(output)
21
+ end
22
+ end
@@ -4,19 +4,19 @@ describe ReverseAsciidoctor do
4
4
  let(:input) { File.read('spec/assets/minimum.html') }
5
5
  let(:document) { Nokogiri::HTML(input) }
6
6
 
7
- it "parses nokogiri documents" do
7
+ it 'parses nokogiri documents' do
8
8
  expect { ReverseAsciidoctor.convert(document) }.not_to raise_error
9
9
  end
10
10
 
11
- it "parses nokogiri elements" do
11
+ it 'parses nokogiri elements' do
12
12
  expect { ReverseAsciidoctor.convert(document.root) }.not_to raise_error
13
13
  end
14
14
 
15
- it "parses string input" do
15
+ it 'parses string input' do
16
16
  expect { ReverseAsciidoctor.convert(input) }.not_to raise_error
17
17
  end
18
18
 
19
- it "behaves in a sane way when root element is nil" do
19
+ it 'behaves in a sane way when root element is nil' do
20
20
  expect(ReverseAsciidoctor.convert(nil)).to eq ''
21
21
  end
22
22
 
@@ -28,10 +28,63 @@ describe ReverseAsciidoctor do
28
28
 
29
29
  it 'can be used as a block configurator as well' do
30
30
  ReverseAsciidoctor.config do |config|
31
- expect(config.tag_border).to eq " "
31
+ expect(config.tag_border).to eq ' '
32
32
  config.tag_border = true
33
33
  end
34
34
  expect(ReverseAsciidoctor.config.tag_border).to eq true
35
35
  end
36
36
  end
37
+
38
+ shared_examples 'converting source with external images included' do |result|
39
+ let(:temp_dir) do
40
+ Pathname.new(ReverseAsciidoctor.config.destination).dirname
41
+ end
42
+ let(:images_folder) { File.join(temp_dir, 'images') }
43
+
44
+ before do
45
+ ReverseAsciidoctor.config.destination = File.join(Dir.mktmpdir,
46
+ 'output.html')
47
+ ReverseAsciidoctor.config.sourcedir = Dir.mktmpdir
48
+ ReverseAsciidoctor.config.external_images = true
49
+ end
50
+
51
+ after do
52
+ FileUtils.rm_rf(temp_dir)
53
+ end
54
+
55
+ it 'Creates local files from external URI' do
56
+ expect { convert }
57
+ .to(change do
58
+ Dir["#{images_folder}/*gif"]
59
+ .map { |entry| File.basename(entry) }
60
+ .sort
61
+ end.from([]).to(result))
62
+ end
63
+ end
64
+
65
+ # TODO: fix github actions integration with libreoffice, currently it hangs
66
+ # when trying to use soffice binary
67
+ unless Gem::Platform.local.os == 'darwin' && !ENV['GITHUB_ACTION'].nil?
68
+ context 'when docx file input' do
69
+ subject(:convert) do
70
+ ReverseAsciidoctor.convert(
71
+ ReverseAsciidoctor.cleaner.preprocess_word_html(input.document.html),
72
+ WordToMarkdown::REVERSE_MARKDOWN_OPTIONS
73
+ )
74
+ end
75
+ let(:input) do
76
+ WordToMarkdown.new('spec/assets/external_images.docx',
77
+ ReverseAsciidoctor.config.sourcedir)
78
+ end
79
+ it_behaves_like 'converting source with external images included',
80
+ ['001.gif', '002.gif']
81
+ end
82
+ end
83
+
84
+ context 'when html file input' do
85
+ subject(:convert) { ReverseAsciidoctor.convert(input) }
86
+ let(:input) { File.read('spec/assets/external_images.html') }
87
+ it_behaves_like 'converting source with external images included',
88
+ ['001.gif']
89
+ end
37
90
  end
@@ -9,6 +9,11 @@ end
9
9
  SimpleCov.start 'gem'
10
10
 
11
11
  require 'reverse_asciidoctor'
12
+ require 'reverse_asciidoctor/html_converter'
13
+ require 'word-to-markdown'
14
+
15
+ Dir[File.join('spec', 'support', '**', '*.rb')]
16
+ .each { |f| require File.join('.', f) }
12
17
 
13
18
  RSpec.configure do |config|
14
19
  config.after(:each) do
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+
5
+ module ShellUtils
6
+ class ShellExcutionError < StandardError; end
7
+ module_function
8
+
9
+ def execute!(cmd)
10
+ stdout, stderr, status = Open3.capture3(cmd)
11
+ raise(ShellExcutionError, stderr) unless status.success?
12
+
13
+ stdout
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reverse_adoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-12 00:00:00.000000000 Z
11
+ date: 2020-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -151,6 +151,7 @@ files:
151
151
  - ".hound.yml"
152
152
  - ".rubocop.yml"
153
153
  - Gemfile
154
+ - Gemfile.lock
154
155
  - LICENSE.txt
155
156
  - README.adoc
156
157
  - Rakefile
@@ -171,6 +172,10 @@ files:
171
172
  - lib/reverse_asciidoctor/converters/div.rb
172
173
  - lib/reverse_asciidoctor/converters/drop.rb
173
174
  - lib/reverse_asciidoctor/converters/em.rb
175
+ - lib/reverse_asciidoctor/converters/example.rb
176
+ - lib/reverse_asciidoctor/converters/express_ref.rb
177
+ - lib/reverse_asciidoctor/converters/ext_description.rb
178
+ - lib/reverse_asciidoctor/converters/ext_descriptions.rb
174
179
  - lib/reverse_asciidoctor/converters/figure.rb
175
180
  - lib/reverse_asciidoctor/converters/h.rb
176
181
  - lib/reverse_asciidoctor/converters/head.rb
@@ -180,6 +185,7 @@ files:
180
185
  - lib/reverse_asciidoctor/converters/li.rb
181
186
  - lib/reverse_asciidoctor/converters/mark.rb
182
187
  - lib/reverse_asciidoctor/converters/math.rb
188
+ - lib/reverse_asciidoctor/converters/note.rb
183
189
  - lib/reverse_asciidoctor/converters/ol.rb
184
190
  - lib/reverse_asciidoctor/converters/p.rb
185
191
  - lib/reverse_asciidoctor/converters/pass_through.rb
@@ -195,12 +201,16 @@ files:
195
201
  - lib/reverse_asciidoctor/converters/tr.rb
196
202
  - lib/reverse_asciidoctor/converters/video.rb
197
203
  - lib/reverse_asciidoctor/errors.rb
204
+ - lib/reverse_asciidoctor/html_converter.rb
205
+ - lib/reverse_asciidoctor/smrl_description_converter.rb
198
206
  - lib/reverse_asciidoctor/version.rb
199
207
  - reverse_adoc.gemspec
200
208
  - spec/assets/anchors.html
201
209
  - spec/assets/basic.html
202
210
  - spec/assets/code.html
203
211
  - spec/assets/escapables.html
212
+ - spec/assets/external_images.docx
213
+ - spec/assets/external_images.html
204
214
  - spec/assets/from_the_wild.html
205
215
  - spec/assets/full_example.html
206
216
  - spec/assets/html_fragment.html
@@ -209,9 +219,9 @@ files:
209
219
  - spec/assets/paragraphs.html
210
220
  - spec/assets/quotation.html
211
221
  - spec/assets/tables.html
212
- - spec/assets/test.docx
213
- - spec/assets/test.html
214
222
  - spec/assets/unknown_tags.html
223
+ - spec/bin/reverse_adoc_spec.rb
224
+ - spec/bin/w2a_spec.rb
215
225
  - spec/components/anchors_spec.rb
216
226
  - spec/components/basic_spec.rb
217
227
  - spec/components/code_spec.rb
@@ -231,10 +241,15 @@ files:
231
241
  - spec/lib/reverse_asciidoctor/converters/br_spec.rb
232
242
  - spec/lib/reverse_asciidoctor/converters/code_spec.rb
233
243
  - spec/lib/reverse_asciidoctor/converters/div_spec.rb
244
+ - spec/lib/reverse_asciidoctor/converters/example_spec.rb
245
+ - spec/lib/reverse_asciidoctor/converters/express_ref_spec.rb
246
+ - spec/lib/reverse_asciidoctor/converters/ext_description_spec.rb
247
+ - spec/lib/reverse_asciidoctor/converters/ext_descriptions_spec.rb
234
248
  - spec/lib/reverse_asciidoctor/converters/figure_spec.rb
235
249
  - spec/lib/reverse_asciidoctor/converters/img_spec.rb
236
250
  - spec/lib/reverse_asciidoctor/converters/li_spec.rb
237
251
  - spec/lib/reverse_asciidoctor/converters/mark_spec.rb
252
+ - spec/lib/reverse_asciidoctor/converters/note_spec.rb
238
253
  - spec/lib/reverse_asciidoctor/converters/p_spec.rb
239
254
  - spec/lib/reverse_asciidoctor/converters/pre_spec.rb
240
255
  - spec/lib/reverse_asciidoctor/converters/q_spec.rb
@@ -244,6 +259,7 @@ files:
244
259
  - spec/lib/reverse_asciidoctor/converters_spec.rb
245
260
  - spec/lib/reverse_asciidoctor_spec.rb
246
261
  - spec/spec_helper.rb
262
+ - spec/support/shell_helpers.rb
247
263
  homepage: http://github.com/metanorma/reverse_adoc
248
264
  licenses:
249
265
  - BSD-2-Clause
@@ -263,8 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
279
  - !ruby/object:Gem::Version
264
280
  version: '0'
265
281
  requirements: []
266
- rubyforge_project:
267
- rubygems_version: 2.7.6
282
+ rubygems_version: 3.0.6
268
283
  signing_key:
269
284
  specification_version: 4
270
285
  summary: Generate AsciiDoc from HTML and Microsoft Word via CLI or library.
@@ -273,6 +288,8 @@ test_files:
273
288
  - spec/assets/basic.html
274
289
  - spec/assets/code.html
275
290
  - spec/assets/escapables.html
291
+ - spec/assets/external_images.docx
292
+ - spec/assets/external_images.html
276
293
  - spec/assets/from_the_wild.html
277
294
  - spec/assets/full_example.html
278
295
  - spec/assets/html_fragment.html
@@ -281,9 +298,9 @@ test_files:
281
298
  - spec/assets/paragraphs.html
282
299
  - spec/assets/quotation.html
283
300
  - spec/assets/tables.html
284
- - spec/assets/test.docx
285
- - spec/assets/test.html
286
301
  - spec/assets/unknown_tags.html
302
+ - spec/bin/reverse_adoc_spec.rb
303
+ - spec/bin/w2a_spec.rb
287
304
  - spec/components/anchors_spec.rb
288
305
  - spec/components/basic_spec.rb
289
306
  - spec/components/code_spec.rb
@@ -303,10 +320,15 @@ test_files:
303
320
  - spec/lib/reverse_asciidoctor/converters/br_spec.rb
304
321
  - spec/lib/reverse_asciidoctor/converters/code_spec.rb
305
322
  - spec/lib/reverse_asciidoctor/converters/div_spec.rb
323
+ - spec/lib/reverse_asciidoctor/converters/example_spec.rb
324
+ - spec/lib/reverse_asciidoctor/converters/express_ref_spec.rb
325
+ - spec/lib/reverse_asciidoctor/converters/ext_description_spec.rb
326
+ - spec/lib/reverse_asciidoctor/converters/ext_descriptions_spec.rb
306
327
  - spec/lib/reverse_asciidoctor/converters/figure_spec.rb
307
328
  - spec/lib/reverse_asciidoctor/converters/img_spec.rb
308
329
  - spec/lib/reverse_asciidoctor/converters/li_spec.rb
309
330
  - spec/lib/reverse_asciidoctor/converters/mark_spec.rb
331
+ - spec/lib/reverse_asciidoctor/converters/note_spec.rb
310
332
  - spec/lib/reverse_asciidoctor/converters/p_spec.rb
311
333
  - spec/lib/reverse_asciidoctor/converters/pre_spec.rb
312
334
  - spec/lib/reverse_asciidoctor/converters/q_spec.rb
@@ -316,3 +338,4 @@ test_files:
316
338
  - spec/lib/reverse_asciidoctor/converters_spec.rb
317
339
  - spec/lib/reverse_asciidoctor_spec.rb
318
340
  - spec/spec_helper.rb
341
+ - spec/support/shell_helpers.rb