reverse_adoc 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/README.adoc +4 -294
- data/Rakefile +2 -13
- data/reverse_adoc.gemspec +2 -20
- metadata +5 -246
- data/.editorconfig +0 -15
- data/.github/workflows/rake.yml +0 -15
- data/.gitignore +0 -10
- data/.hound.yml +0 -5
- data/.rubocop.yml +0 -10
- data/LICENSE.txt +0 -25
- data/exe/reverse_adoc +0 -70
- data/exe/w2a +0 -72
- data/lib/reverse_adoc/cleaner.rb +0 -113
- data/lib/reverse_adoc/config.rb +0 -54
- data/lib/reverse_adoc/converters/a.rb +0 -42
- data/lib/reverse_adoc/converters/aside.rb +0 -16
- data/lib/reverse_adoc/converters/audio.rb +0 -29
- data/lib/reverse_adoc/converters/base.rb +0 -100
- data/lib/reverse_adoc/converters/blockquote.rb +0 -27
- data/lib/reverse_adoc/converters/br.rb +0 -15
- data/lib/reverse_adoc/converters/bypass.rb +0 -81
- data/lib/reverse_adoc/converters/code.rb +0 -56
- data/lib/reverse_adoc/converters/div.rb +0 -18
- data/lib/reverse_adoc/converters/drop.rb +0 -22
- data/lib/reverse_adoc/converters/em.rb +0 -55
- data/lib/reverse_adoc/converters/figure.rb +0 -25
- data/lib/reverse_adoc/converters/h.rb +0 -42
- data/lib/reverse_adoc/converters/head.rb +0 -23
- data/lib/reverse_adoc/converters/hr.rb +0 -15
- data/lib/reverse_adoc/converters/ignore.rb +0 -16
- data/lib/reverse_adoc/converters/img.rb +0 -93
- data/lib/reverse_adoc/converters/li.rb +0 -17
- data/lib/reverse_adoc/converters/mark.rb +0 -21
- data/lib/reverse_adoc/converters/math.rb +0 -31
- data/lib/reverse_adoc/converters/ol.rb +0 -64
- data/lib/reverse_adoc/converters/p.rb +0 -23
- data/lib/reverse_adoc/converters/pass_through.rb +0 -13
- data/lib/reverse_adoc/converters/pre.rb +0 -55
- data/lib/reverse_adoc/converters/q.rb +0 -16
- data/lib/reverse_adoc/converters/strong.rb +0 -52
- data/lib/reverse_adoc/converters/sub.rb +0 -16
- data/lib/reverse_adoc/converters/sup.rb +0 -16
- data/lib/reverse_adoc/converters/table.rb +0 -69
- data/lib/reverse_adoc/converters/td.rb +0 -83
- data/lib/reverse_adoc/converters/text.rb +0 -65
- data/lib/reverse_adoc/converters/th.rb +0 -14
- data/lib/reverse_adoc/converters/tr.rb +0 -22
- data/lib/reverse_adoc/converters/video.rb +0 -29
- data/lib/reverse_adoc/converters.rb +0 -32
- data/lib/reverse_adoc/errors.rb +0 -10
- data/lib/reverse_adoc/html_converter.rb +0 -61
- data/lib/reverse_adoc/version.rb +0 -3
- data/lib/reverse_adoc.rb +0 -27
- data/spec/assets/anchors.html +0 -30
- data/spec/assets/basic.html +0 -61
- data/spec/assets/code.html +0 -22
- data/spec/assets/escapables.html +0 -17
- data/spec/assets/external_images.docx +0 -0
- data/spec/assets/external_images.html +0 -35
- data/spec/assets/from_the_wild.html +0 -23
- data/spec/assets/full_example.html +0 -49
- data/spec/assets/html_fragment.html +0 -3
- data/spec/assets/lists.html +0 -137
- data/spec/assets/minimum.html +0 -4
- data/spec/assets/paragraphs.html +0 -24
- data/spec/assets/quotation.html +0 -12
- data/spec/assets/tables.html +0 -99
- data/spec/assets/unknown_tags.html +0 -9
- data/spec/bin/reverse_adoc_spec.rb +0 -33
- data/spec/bin/w2a_spec.rb +0 -35
- data/spec/components/anchors_spec.rb +0 -32
- data/spec/components/basic_spec.rb +0 -63
- data/spec/components/code_spec.rb +0 -25
- data/spec/components/escapables_spec.rb +0 -30
- data/spec/components/from_the_wild_spec.rb +0 -15
- data/spec/components/html_fragment_spec.rb +0 -9
- data/spec/components/lists_spec.rb +0 -90
- data/spec/components/paragraphs_spec.rb +0 -14
- data/spec/components/quotation_spec.rb +0 -12
- data/spec/components/tables_spec.rb +0 -42
- data/spec/components/unknown_tags_spec.rb +0 -41
- data/spec/lib/reverse_adoc/cleaner_spec.rb +0 -180
- data/spec/lib/reverse_adoc/config_spec.rb +0 -25
- data/spec/lib/reverse_adoc/converters/aside_spec.rb +0 -11
- data/spec/lib/reverse_adoc/converters/audio_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters/blockquote_spec.rb +0 -23
- data/spec/lib/reverse_adoc/converters/br_spec.rb +0 -9
- data/spec/lib/reverse_adoc/converters/code_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters/div_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters/figure_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/img_spec.rb +0 -25
- data/spec/lib/reverse_adoc/converters/li_spec.rb +0 -11
- data/spec/lib/reverse_adoc/converters/mark_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/p_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/pre_spec.rb +0 -43
- data/spec/lib/reverse_adoc/converters/q_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/strong_spec.rb +0 -21
- data/spec/lib/reverse_adoc/converters/text_spec.rb +0 -67
- data/spec/lib/reverse_adoc/converters/video_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters_spec.rb +0 -22
- data/spec/lib/reverse_adoc.rb +0 -90
- data/spec/spec_helper.rb +0 -25
- data/spec/support/shell_helpers.rb +0 -15
data/.gitignore
DELETED
data/.hound.yml
DELETED
data/.rubocop.yml
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
-
# See https://github.com/metanorma/cimas
|
3
|
-
inherit_from:
|
4
|
-
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
5
|
-
|
6
|
-
# local repo-specific modifications
|
7
|
-
# ...
|
8
|
-
|
9
|
-
AllCops:
|
10
|
-
TargetRubyVersion: 2.5
|
data/LICENSE.txt
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
BSD 2-Clause License
|
2
|
-
|
3
|
-
Copyright (c) 2018, Ribose
|
4
|
-
All rights reserved.
|
5
|
-
|
6
|
-
Redistribution and use in source and binary forms, with or without
|
7
|
-
modification, are permitted provided that the following conditions are met:
|
8
|
-
|
9
|
-
* Redistributions of source code must retain the above copyright notice, this
|
10
|
-
list of conditions and the following disclaimer.
|
11
|
-
|
12
|
-
* Redistributions in binary form must reproduce the above copyright notice,
|
13
|
-
this list of conditions and the following disclaimer in the documentation
|
14
|
-
and/or other materials provided with the distribution.
|
15
|
-
|
16
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
20
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/exe/reverse_adoc
DELETED
@@ -1,70 +0,0 @@
|
|
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]",
|
27
|
-
"Unknown tag handling (default: pass_through)") do |v|
|
28
|
-
ReverseAdoc.config.unknown_tags = v
|
29
|
-
end
|
30
|
-
|
31
|
-
opts.on("-v", "--version", "Version information") do |_v|
|
32
|
-
puts "reverse_adoc: v#{ReverseAdoc::VERSION}"
|
33
|
-
exit
|
34
|
-
end
|
35
|
-
|
36
|
-
opts.on("-h", "--help", "Prints this help") do
|
37
|
-
puts opts
|
38
|
-
exit
|
39
|
-
end
|
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/exe/w2a
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bundler/setup"
|
6
|
-
|
7
|
-
require "word-to-markdown"
|
8
|
-
require "optparse"
|
9
|
-
require "reverse_adoc"
|
10
|
-
|
11
|
-
ARGV.push("-h") if ARGV.empty?
|
12
|
-
|
13
|
-
OptionParser.new do |opts|
|
14
|
-
opts.banner = "Usage: w2a [options] <file>"
|
15
|
-
opts.on("-m", "--mathml2asciimath", "Convert MathML to AsciiMath") do |_v|
|
16
|
-
ReverseAdoc.config.mathml2asciimath = true
|
17
|
-
end
|
18
|
-
|
19
|
-
opts.on("-oFILENAME", "--output=FILENAME", "Output file to write to") do |v|
|
20
|
-
ReverseAdoc.config.destination = File.expand_path(v)
|
21
|
-
# puts "output goes to #{ReverseAdoc.config.destination}"
|
22
|
-
end
|
23
|
-
|
24
|
-
opts.on("-e", "--external-images", "Export images if data URI") do |_v|
|
25
|
-
ReverseAdoc.config.external_images = true
|
26
|
-
end
|
27
|
-
|
28
|
-
opts.on("-v", "--version", "Version information") do |_v|
|
29
|
-
puts "reverse_adoc: v#{ReverseAdoc::VERSION}"
|
30
|
-
puts "[dependency] WordToMarkdown: v#{WordToMarkdown::VERSION}"
|
31
|
-
if Gem.win_platform?
|
32
|
-
puts "[dependency] LibreOffice: version not available on Windows"
|
33
|
-
else
|
34
|
-
puts "[dependency] LibreOffice: v#{WordToMarkdown.soffice.version}"
|
35
|
-
end
|
36
|
-
exit
|
37
|
-
end
|
38
|
-
|
39
|
-
opts.on("-h", "--help", "Prints this help") do
|
40
|
-
puts opts
|
41
|
-
exit
|
42
|
-
end
|
43
|
-
end.parse!
|
44
|
-
|
45
|
-
filename = ARGV.pop
|
46
|
-
raise "Please provide an input file to process. Exiting." unless filename
|
47
|
-
|
48
|
-
if ReverseAdoc.config.external_images && ReverseAdoc.config.destination.nil?
|
49
|
-
raise "The -e | --external-images feature must be used with -o | --output. Exiting."
|
50
|
-
end
|
51
|
-
|
52
|
-
ReverseAdoc.config.sourcedir = Dir.mktmpdir
|
53
|
-
|
54
|
-
doc = WordToMarkdown.new(filename, ReverseAdoc.config.sourcedir)
|
55
|
-
# File.open("test.html", "w:UTF-8") { |f| f.write doc.document.html }
|
56
|
-
adoc_content = ReverseAdoc.convert(
|
57
|
-
ReverseAdoc.cleaner.preprocess_word_html(doc.document.html),
|
58
|
-
WordToMarkdown::REVERSE_MARKDOWN_OPTIONS,
|
59
|
-
)
|
60
|
-
# puts scrub_whitespace(doc.document.html)
|
61
|
-
|
62
|
-
# Print to STDOUT
|
63
|
-
unless ReverseAdoc.config.destination
|
64
|
-
puts adoc_content
|
65
|
-
exit
|
66
|
-
end
|
67
|
-
|
68
|
-
# Write output to ReverseAdoc.config.destination
|
69
|
-
FileUtils.mkdir_p(File.dirname(ReverseAdoc.config.destination))
|
70
|
-
File.open(ReverseAdoc.config.destination, "w") do |file|
|
71
|
-
file.write(adoc_content)
|
72
|
-
end
|
data/lib/reverse_adoc/cleaner.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
class Cleaner
|
3
|
-
def tidy(string)
|
4
|
-
result = remove_inner_whitespaces(string)
|
5
|
-
result = remove_newlines(result)
|
6
|
-
result = remove_leading_newlines(result)
|
7
|
-
result = clean_tag_borders(result)
|
8
|
-
clean_punctuation_characters(result)
|
9
|
-
end
|
10
|
-
|
11
|
-
def remove_newlines(string)
|
12
|
-
string.gsub(/\n{3,}/, "\n\n")
|
13
|
-
end
|
14
|
-
|
15
|
-
def remove_leading_newlines(string)
|
16
|
-
string.gsub(/\A\n+/, "")
|
17
|
-
end
|
18
|
-
|
19
|
-
def remove_inner_whitespaces(string)
|
20
|
-
unless string.nil?
|
21
|
-
string.gsub!(/\n stem:\[/, "\nstem:[")
|
22
|
-
string.gsub!(/(stem:\[([^\]]|\\\])*\])\n(?=\S)/, "\\1 ")
|
23
|
-
string.gsub!(/(stem:\[([^\]]|\\\])*\])\s+(?=[\^-])/, "\\1")
|
24
|
-
end
|
25
|
-
string.each_line.inject("") do |memo, line|
|
26
|
-
memo + preserve_border_whitespaces(line) do
|
27
|
-
line.strip.gsub(/[ \t]{2,}/, " ")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# Find non-asterisk content that is enclosed by two or
|
33
|
-
# more asterisks. Ensure that only one whitespace occurs
|
34
|
-
# in the border area.
|
35
|
-
# Same for underscores and brackets.
|
36
|
-
def clean_tag_borders(string)
|
37
|
-
# result = string.gsub(/\s?\*{2,}.*?\*{2,}\s?/) do |match|
|
38
|
-
# preserve_border_whitespaces(match, default_border: ReverseAdoc.config.tag_border) do
|
39
|
-
# match.strip.sub("** ", "**").sub(" **", "**")
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
|
43
|
-
# result = string.gsub(/\s?_{2,}.*?_{2,}\s?/) do |match|
|
44
|
-
# preserve_border_whitespaces(match, default_border: ReverseAdoc.config.tag_border) do
|
45
|
-
# match.strip.sub("__ ", "__").sub(" __", "__")
|
46
|
-
# end
|
47
|
-
# end
|
48
|
-
|
49
|
-
result = string.gsub(/\s?~{2,}.*?~{2,}\s?/) do |match|
|
50
|
-
preserve_border_whitespaces(match,
|
51
|
-
default_border: ReverseAdoc.config.tag_border) do
|
52
|
-
match.strip.sub("~~ ", "~~").sub(" ~~", "~~")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
result.gsub(/\s?\[.*?\]\s?/) do |match|
|
57
|
-
preserve_border_whitespaces(match) do
|
58
|
-
match.strip.sub("[ ", "[").sub(" ]", "]")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def clean_punctuation_characters(string)
|
64
|
-
string.gsub(/(\*\*|~~|__)\s([.!?'"])/, "#{'\\1'.strip}\\2")
|
65
|
-
end
|
66
|
-
|
67
|
-
# preprocesses HTML, rather than postprocessing it
|
68
|
-
def preprocess_word_html(string)
|
69
|
-
clean_headings(scrub_whitespace(string.dup))
|
70
|
-
end
|
71
|
-
|
72
|
-
def scrub_whitespace(string)
|
73
|
-
string.gsub!(/ | |\u00a0/i, " ") # 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
|
79
|
-
string
|
80
|
-
end
|
81
|
-
|
82
|
-
# following added by me
|
83
|
-
def clean_headings(string)
|
84
|
-
string.gsub!(%r{<h([1-9])[^>]*></h\1>}, " ")
|
85
|
-
# I don't know why Libre Office is inserting them, but they need to go
|
86
|
-
string.gsub!(%r{<h([1-9])[^>]* style="vertical-align: super;[^>]*>(.+?)</h\1>},
|
87
|
-
"<sup>\\2</sup>")
|
88
|
-
# I absolutely don't know why Libre Office is rendering superscripts as h1
|
89
|
-
string
|
90
|
-
end
|
91
|
-
|
92
|
-
private
|
93
|
-
|
94
|
-
def preserve_border_whitespaces(string, options = {})
|
95
|
-
return string if /\A\s*\Z/.match?(string)
|
96
|
-
|
97
|
-
default_border = options.fetch(:default_border, "")
|
98
|
-
# If the string contains part of a link so the characters [,],(,)
|
99
|
-
# then don't add any extra spaces
|
100
|
-
default_border = "" if /[\[(\])]/.match?(string)
|
101
|
-
string_start = present_or_default(string[/\A\s*/], default_border)
|
102
|
-
string_end = present_or_default(string[/\s*\Z/], default_border)
|
103
|
-
result = yield
|
104
|
-
string_start + result + string_end
|
105
|
-
end
|
106
|
-
|
107
|
-
def present_or_default(string, default)
|
108
|
-
return default if string.nil? || string.empty?
|
109
|
-
|
110
|
-
string
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
data/lib/reverse_adoc/config.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require "tmpdir"
|
2
|
-
|
3
|
-
module ReverseAdoc
|
4
|
-
class Config
|
5
|
-
attr_accessor :unknown_tags, :tag_border, :mathml2asciimath, :external_images,
|
6
|
-
:destination, :sourcedir, :image_counter, :image_counter_pattern, :input_format
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@unknown_tags = :pass_through
|
10
|
-
@input_format = :html
|
11
|
-
@mathml2asciimath = false
|
12
|
-
@external_images = false
|
13
|
-
|
14
|
-
# Destination to save file and images
|
15
|
-
@destination = nil
|
16
|
-
|
17
|
-
# Source of HTML
|
18
|
-
# @sourcedir = nil
|
19
|
-
|
20
|
-
# Image counter, assuming there are max 999 images
|
21
|
-
@image_counter = 1
|
22
|
-
# pad with 0s
|
23
|
-
@image_counter_pattern = "%03d"
|
24
|
-
|
25
|
-
@em_delimiter = "_".freeze
|
26
|
-
@strong_delimiter = "*".freeze
|
27
|
-
@inline_options = {}
|
28
|
-
@tag_border = " ".freeze
|
29
|
-
end
|
30
|
-
|
31
|
-
def with(options = {})
|
32
|
-
@inline_options = options
|
33
|
-
result = yield
|
34
|
-
@inline_options = {}
|
35
|
-
result
|
36
|
-
end
|
37
|
-
|
38
|
-
def unknown_tags
|
39
|
-
@inline_options[:unknown_tags] || @unknown_tags
|
40
|
-
end
|
41
|
-
|
42
|
-
def mathml2asciimath
|
43
|
-
@inline_options[:mathml2asciimath] || @mathml2asciimath
|
44
|
-
end
|
45
|
-
|
46
|
-
def external_images
|
47
|
-
@inline_options[:external_images] || @external_images
|
48
|
-
end
|
49
|
-
|
50
|
-
def tag_border
|
51
|
-
@inline_options[:tag_border] || @tag_border
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require "coradoc"
|
2
|
-
|
3
|
-
module ReverseAdoc
|
4
|
-
module Converters
|
5
|
-
class A < Base
|
6
|
-
def to_coradoc(node, state = {})
|
7
|
-
name = treat_children(node, state)
|
8
|
-
|
9
|
-
href = node["href"]
|
10
|
-
title = extract_title(node)
|
11
|
-
id = node["id"] || node["name"]
|
12
|
-
|
13
|
-
id = id&.gsub(/\s/, "")&.gsub(/__+/, "_")
|
14
|
-
|
15
|
-
return "" if /^_Toc\d+$|^_GoBack$/.match?(id)
|
16
|
-
|
17
|
-
if !id.nil? && !id.empty?
|
18
|
-
return Coradoc::Element::Inline::Anchor.new(id)
|
19
|
-
end
|
20
|
-
|
21
|
-
if href.to_s.start_with?("#")
|
22
|
-
href = href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_")
|
23
|
-
return Coradoc::Element::Inline::CrossReference.new(href, name)
|
24
|
-
end
|
25
|
-
|
26
|
-
if href.to_s.empty?
|
27
|
-
return name
|
28
|
-
end
|
29
|
-
|
30
|
-
Coradoc::Element::Inline::Link.new(path: href,
|
31
|
-
name: name,
|
32
|
-
title: title)
|
33
|
-
end
|
34
|
-
|
35
|
-
def convert(node, state = {})
|
36
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
register :a, A.new
|
41
|
-
end
|
42
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Aside < Base
|
4
|
-
def to_coradoc(node, state = {})
|
5
|
-
content = treat_children(node, state)
|
6
|
-
Coradoc::Element::Block::Side.new(lines: content.lines)
|
7
|
-
end
|
8
|
-
|
9
|
-
def convert(node, state = {})
|
10
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
register :aside, Aside.new
|
15
|
-
end
|
16
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Audio < Base
|
4
|
-
def to_coradoc(node, _state = {})
|
5
|
-
src = node["src"]
|
6
|
-
id = node["id"]
|
7
|
-
title = extract_title(node)
|
8
|
-
attributes = Coradoc::Element::AttributeList.new
|
9
|
-
options = options(node)
|
10
|
-
attributes.add_named("options", options) if options.any?
|
11
|
-
Coradoc::Element::Audio.new(title, id: id, src: src,
|
12
|
-
attributes: attributes)
|
13
|
-
end
|
14
|
-
|
15
|
-
def convert(node, state = {})
|
16
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
17
|
-
end
|
18
|
-
|
19
|
-
def options(node)
|
20
|
-
autoplay = node["autoplay"]
|
21
|
-
loop_attr = node["loop"]
|
22
|
-
controls = node["controls"]
|
23
|
-
[autoplay, loop_attr, controls].compact
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
register :audio, Audio.new
|
28
|
-
end
|
29
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Base
|
4
|
-
def treat_children(node, state)
|
5
|
-
node.children.inject("") do |memo, child|
|
6
|
-
memo << treat(child, state)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def treat(node, state)
|
11
|
-
ReverseAdoc::Converters.lookup(node.name).convert(node, state)
|
12
|
-
end
|
13
|
-
|
14
|
-
def treat_children_coradoc(node, state)
|
15
|
-
node.children.inject([]) do |memo, child|
|
16
|
-
memo << treat_coradoc(child, state)
|
17
|
-
end.flatten.reject { |x| x == "" || x.nil? }
|
18
|
-
end
|
19
|
-
|
20
|
-
def treat_coradoc(node, state)
|
21
|
-
ReverseAdoc::Converters.lookup(node.name).to_coradoc(node, state)
|
22
|
-
end
|
23
|
-
|
24
|
-
def escape_keychars(string)
|
25
|
-
subs = { "*" => '\*', "_" => '\_' }
|
26
|
-
string
|
27
|
-
.gsub(/((?<=\s)[\*_]+)|[\*_]+(?=\s)/) do |n|
|
28
|
-
n.chars.map do |char|
|
29
|
-
subs[char]
|
30
|
-
end.join
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def extract_title(node)
|
35
|
-
title = escape_keychars(node["title"].to_s)
|
36
|
-
title.empty? ? "" : %[ #{title}]
|
37
|
-
end
|
38
|
-
|
39
|
-
def node_has_ancestor?(node, name)
|
40
|
-
case name
|
41
|
-
when String
|
42
|
-
node.ancestors.map(&:name).include?(name)
|
43
|
-
when Array
|
44
|
-
(node.ancestors.map(&:name) & name).any?
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def textnode_before_end_with?(node, str)
|
49
|
-
return nil if !str.is_a?(String) || str.empty?
|
50
|
-
|
51
|
-
node2 = node.at_xpath("preceding-sibling::node()[1]")
|
52
|
-
node2.respond_to?(:text) && node2.text.end_with?(str)
|
53
|
-
end
|
54
|
-
|
55
|
-
def unconstrained_before?(node)
|
56
|
-
before = node.at_xpath("preceding::node()[1]")
|
57
|
-
|
58
|
-
before &&
|
59
|
-
!before.text.strip.empty? &&
|
60
|
-
before.text[-1]&.match?(/\w/)
|
61
|
-
end
|
62
|
-
|
63
|
-
# TODO: This logic ought to be cleaned up.
|
64
|
-
def unconstrained_after?(node)
|
65
|
-
after = node.at_xpath("following::node()[1]")
|
66
|
-
|
67
|
-
after && !after.text.strip.empty? &&
|
68
|
-
after.text[0]&.match?(/\w|,|;|"|\.\?!/)
|
69
|
-
end
|
70
|
-
|
71
|
-
# def trailing_whitespace?(node)
|
72
|
-
|
73
|
-
# TODO: This logic ought to be cleaned up.
|
74
|
-
def constrained?(node)
|
75
|
-
before = node.at_xpath("preceding::node()[1]").to_s[-1]
|
76
|
-
before = if before
|
77
|
-
before&.match?(/\s/) ? true : false
|
78
|
-
else
|
79
|
-
true
|
80
|
-
end
|
81
|
-
|
82
|
-
if !before && (node.to_s[0] =~ /\s/)
|
83
|
-
before = true
|
84
|
-
end
|
85
|
-
|
86
|
-
after = node.at_xpath("following::node()[1]").to_s[0]
|
87
|
-
after = if after
|
88
|
-
after&.match?(/\s|,|;|"|\.\?!/) ? true : false
|
89
|
-
else
|
90
|
-
true
|
91
|
-
end
|
92
|
-
if !after && (node.to_s[-1] =~ /\s/)
|
93
|
-
after = true
|
94
|
-
end
|
95
|
-
|
96
|
-
before && after
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Blockquote < Base
|
4
|
-
def to_coradoc(node, state = {})
|
5
|
-
node["id"]
|
6
|
-
cite = node["cite"]
|
7
|
-
attributes = if cite.nil?
|
8
|
-
nil
|
9
|
-
else
|
10
|
-
Coradoc::Element::AttributeList.new(
|
11
|
-
"quote", cite
|
12
|
-
)
|
13
|
-
end
|
14
|
-
content = treat_children(node, state).strip
|
15
|
-
content = ReverseAdoc.cleaner.remove_newlines(content)
|
16
|
-
Coradoc::Element::Block::Quote.new(nil, lines: content,
|
17
|
-
attributes: attributes)
|
18
|
-
end
|
19
|
-
|
20
|
-
def convert(node, state = {})
|
21
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
register :blockquote, Blockquote.new
|
26
|
-
end
|
27
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Br < Base
|
4
|
-
def to_coradoc(_node, _state = {})
|
5
|
-
Coradoc::Element::Inline::HardLineBreak.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def convert(node, state = {})
|
9
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
register :br, Br.new
|
14
|
-
end
|
15
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
module ReverseAdoc
|
2
|
-
module Converters
|
3
|
-
class Bypass < Base
|
4
|
-
def to_coradoc(node, state = {})
|
5
|
-
treat_children_coradoc(node, state)
|
6
|
-
end
|
7
|
-
|
8
|
-
def convert(node, state = {})
|
9
|
-
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
register :document, Bypass.new
|
14
|
-
register :html, Bypass.new
|
15
|
-
register :body, Bypass.new
|
16
|
-
register :span, Bypass.new
|
17
|
-
register :thead, Bypass.new
|
18
|
-
register :tbody, Bypass.new
|
19
|
-
register :tfoot, Bypass.new
|
20
|
-
register :abbr, Bypass.new
|
21
|
-
register :acronym, Bypass.new
|
22
|
-
register :address, Bypass.new
|
23
|
-
register :applet, Bypass.new
|
24
|
-
register :map, Bypass.new
|
25
|
-
register :area, Bypass.new
|
26
|
-
register :bdi, Bypass.new
|
27
|
-
register :bdo, Bypass.new
|
28
|
-
register :big, Bypass.new
|
29
|
-
register :button, Bypass.new
|
30
|
-
register :canvas, Bypass.new
|
31
|
-
register :data, Bypass.new
|
32
|
-
register :datalist, Bypass.new
|
33
|
-
register :del, Bypass.new
|
34
|
-
register :ins, Bypass.new
|
35
|
-
register :dfn, Bypass.new
|
36
|
-
register :dialog, Bypass.new
|
37
|
-
register :embed, Bypass.new
|
38
|
-
register :fieldset, Bypass.new
|
39
|
-
register :font, Bypass.new
|
40
|
-
register :footer, Bypass.new
|
41
|
-
register :form, Bypass.new
|
42
|
-
register :frame, Bypass.new
|
43
|
-
register :frameset, Bypass.new
|
44
|
-
register :header, Bypass.new
|
45
|
-
register :iframe, Bypass.new
|
46
|
-
register :input, Bypass.new
|
47
|
-
register :label, Bypass.new
|
48
|
-
register :legend, Bypass.new
|
49
|
-
register :main, Bypass.new
|
50
|
-
register :menu, Bypass.new
|
51
|
-
register :menulist, Bypass.new
|
52
|
-
register :meter, Bypass.new
|
53
|
-
register :nav, Bypass.new
|
54
|
-
register :noframes, Bypass.new
|
55
|
-
register :noscript, Bypass.new
|
56
|
-
register :object, Bypass.new
|
57
|
-
register :optgroup, Bypass.new
|
58
|
-
register :option, Bypass.new
|
59
|
-
register :output, Bypass.new
|
60
|
-
register :param, Bypass.new
|
61
|
-
register :picture, Bypass.new
|
62
|
-
register :progress, Bypass.new
|
63
|
-
register :ruby, Bypass.new
|
64
|
-
register :rt, Bypass.new
|
65
|
-
register :rp, Bypass.new
|
66
|
-
register :s, Bypass.new
|
67
|
-
register :select, Bypass.new
|
68
|
-
register :small, Bypass.new
|
69
|
-
register :span, Bypass.new
|
70
|
-
register :strike, Bypass.new
|
71
|
-
register :details, Bypass.new
|
72
|
-
register :section, Bypass.new
|
73
|
-
register :summary, Bypass.new
|
74
|
-
register :svg, Bypass.new
|
75
|
-
register :template, Bypass.new
|
76
|
-
register :textarea, Bypass.new
|
77
|
-
register :track, Bypass.new
|
78
|
-
register :u, Bypass.new
|
79
|
-
register :wbr, Bypass.new
|
80
|
-
end
|
81
|
-
end
|