reverse_adoc 0.3.7 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +4 -3
- data/Gemfile +1 -1
- data/Rakefile +7 -7
- data/exe/reverse_adoc +11 -11
- data/exe/w2a +15 -16
- data/lib/reverse_adoc/cleaner.rb +18 -19
- data/lib/reverse_adoc/config.rb +7 -7
- data/lib/reverse_adoc/converters/a.rb +24 -24
- data/lib/reverse_adoc/converters/aside.rb +6 -4
- data/lib/reverse_adoc/converters/audio.rb +16 -21
- data/lib/reverse_adoc/converters/base.rb +79 -5
- data/lib/reverse_adoc/converters/blockquote.rb +16 -7
- data/lib/reverse_adoc/converters/br.rb +5 -1
- data/lib/reverse_adoc/converters/bypass.rb +38 -34
- data/lib/reverse_adoc/converters/code.rb +42 -1
- data/lib/reverse_adoc/converters/div.rb +7 -3
- data/lib/reverse_adoc/converters/drop.rb +6 -2
- data/lib/reverse_adoc/converters/em.rb +44 -7
- data/lib/reverse_adoc/converters/figure.rb +10 -6
- data/lib/reverse_adoc/converters/h.rb +19 -11
- data/lib/reverse_adoc/converters/head.rb +7 -2
- data/lib/reverse_adoc/converters/hr.rb +5 -1
- data/lib/reverse_adoc/converters/ignore.rb +6 -2
- data/lib/reverse_adoc/converters/img.rb +29 -19
- data/lib/reverse_adoc/converters/li.rb +6 -13
- data/lib/reverse_adoc/converters/mark.rb +11 -2
- data/lib/reverse_adoc/converters/math.rb +13 -2
- data/lib/reverse_adoc/converters/ol.rb +44 -26
- data/lib/reverse_adoc/converters/p.rb +13 -7
- data/lib/reverse_adoc/converters/pass_through.rb +5 -1
- data/lib/reverse_adoc/converters/pre.rb +23 -10
- data/lib/reverse_adoc/converters/q.rb +6 -2
- data/lib/reverse_adoc/converters/strong.rb +41 -6
- data/lib/reverse_adoc/converters/sub.rb +6 -2
- data/lib/reverse_adoc/converters/sup.rb +6 -2
- data/lib/reverse_adoc/converters/table.rb +28 -23
- data/lib/reverse_adoc/converters/td.rb +32 -16
- data/lib/reverse_adoc/converters/text.rb +16 -14
- data/lib/reverse_adoc/converters/th.rb +4 -6
- data/lib/reverse_adoc/converters/tr.rb +7 -7
- data/lib/reverse_adoc/converters/video.rb +16 -23
- data/lib/reverse_adoc/converters.rb +2 -3
- data/lib/reverse_adoc/html_converter.rb +48 -43
- data/lib/reverse_adoc/version.rb +1 -1
- data/lib/reverse_adoc.rb +9 -9
- data/reverse_adoc.gemspec +4 -1
- data/spec/assets/basic.html +3 -0
- data/spec/bin/reverse_adoc_spec.rb +9 -8
- data/spec/bin/w2a_spec.rb +12 -12
- data/spec/components/anchors_spec.rb +18 -12
- data/spec/components/basic_spec.rb +28 -14
- data/spec/components/code_spec.rb +2 -4
- data/spec/components/escapables_spec.rb +4 -6
- data/spec/components/from_the_wild_spec.rb +2 -4
- data/spec/components/html_fragment_spec.rb +2 -3
- data/spec/components/lists_spec.rb +12 -8
- data/spec/components/paragraphs_spec.rb +2 -3
- data/spec/components/quotation_spec.rb +5 -5
- data/spec/components/tables_spec.rb +22 -11
- data/spec/components/unknown_tags_spec.rb +13 -10
- data/spec/lib/reverse_adoc/cleaner_spec.rb +70 -71
- data/spec/lib/reverse_adoc/config_spec.rb +5 -6
- data/spec/lib/reverse_adoc/converters/aside_spec.rb +2 -3
- data/spec/lib/reverse_adoc/converters/audio_spec.rb +3 -5
- data/spec/lib/reverse_adoc/converters/blockquote_spec.rb +5 -6
- data/spec/lib/reverse_adoc/converters/br_spec.rb +2 -2
- data/spec/lib/reverse_adoc/converters/code_spec.rb +3 -5
- data/spec/lib/reverse_adoc/converters/div_spec.rb +3 -5
- data/spec/lib/reverse_adoc/converters/figure_spec.rb +2 -4
- data/spec/lib/reverse_adoc/converters/img_spec.rb +5 -7
- data/spec/lib/reverse_adoc/converters/li_spec.rb +2 -4
- data/spec/lib/reverse_adoc/converters/mark_spec.rb +4 -4
- data/spec/lib/reverse_adoc/converters/p_spec.rb +2 -3
- data/spec/lib/reverse_adoc/converters/pre_spec.rb +8 -9
- data/spec/lib/reverse_adoc/converters/q_spec.rb +3 -3
- data/spec/lib/reverse_adoc/converters/strong_spec.rb +9 -8
- data/spec/lib/reverse_adoc/converters/text_spec.rb +13 -14
- data/spec/lib/reverse_adoc/converters/video_spec.rb +7 -9
- data/spec/lib/reverse_adoc/converters_spec.rb +9 -6
- data/spec/lib/reverse_adoc.rb +25 -25
- data/spec/spec_helper.rb +11 -11
- data/spec/support/shell_helpers.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4e558e38964447487e85f7a227fcad42d82c516fef45ef258d60cf1958e5f3d
|
4
|
+
data.tar.gz: 4b415eb2b9c408e924f3ab165ee2646cd2968e66ccffb04efbfb8c0a8fd98f19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4777d930ae527079df3cce6fb2e40080b0cab672d0629fee63936abf8d41d9327f736a56d7e43d3bdaee1f1cc442af2abd18a7671e079689d9af3f11ebd3dc7a
|
7
|
+
data.tar.gz: 43ed88bf64982efeb5c5b45b8af397b02c18bad53749b0d204d1b061068d433fcf9442b6d01586270b7acb07fb3e426184e1378d814a05cadf9ef8b6b4290acb
|
@@ -7,11 +7,12 @@ on:
|
|
7
7
|
inputs:
|
8
8
|
next_version:
|
9
9
|
description: |
|
10
|
-
Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
|
10
|
+
Next release version. Possible values: x.y.z, major, minor, patch (or pre|rc|etc).
|
11
|
+
Also, you can pass 'skip' to skip 'git tag' and do 'gem push' for the current version
|
11
12
|
required: true
|
12
13
|
default: 'skip'
|
13
|
-
|
14
|
-
|
14
|
+
repository_dispatch:
|
15
|
+
types: [ do-release ]
|
15
16
|
|
16
17
|
jobs:
|
17
18
|
release:
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require "bundler/gem_tasks"
|
2
2
|
|
3
|
-
if File.exist?(
|
4
|
-
ENV["CODECLIMATE_REPO_TOKEN"] = File.read(
|
3
|
+
if File.exist?(".codeclimate")
|
4
|
+
ENV["CODECLIMATE_REPO_TOKEN"] = File.read(".codeclimate").strip
|
5
5
|
end
|
6
6
|
|
7
|
-
require
|
7
|
+
require "rspec/core/rake_task"
|
8
8
|
RSpec::Core::RakeTask.new(:spec)
|
9
|
-
task :
|
9
|
+
task default: :spec
|
10
10
|
|
11
|
-
desc
|
11
|
+
desc "Open an irb session preloaded with this library"
|
12
12
|
task :console do
|
13
|
-
sh
|
13
|
+
sh "irb -rubygems -I lib -r reverse_adoc.rb"
|
14
14
|
end
|
data/exe/reverse_adoc
CHANGED
@@ -1,33 +1,34 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# Usage: reverse_adoc [FILE]...
|
3
3
|
# Usage: cat FILE | reverse_adoc
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "rubygems"
|
5
|
+
require "bundler/setup"
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
7
|
+
require "reverse_adoc"
|
8
|
+
require "optparse"
|
9
|
+
require "fileutils"
|
10
10
|
|
11
11
|
OptionParser.new do |opts|
|
12
12
|
opts.banner = "Usage: reverse_adoc [options] <file>"
|
13
|
-
opts.on(
|
13
|
+
opts.on("-m", "--mathml2asciimath", "Convert MathML to AsciiMath") do |_v|
|
14
14
|
ReverseAdoc.config.mathml2asciimath = true
|
15
15
|
end
|
16
16
|
|
17
|
-
opts.on(
|
17
|
+
opts.on("-oFILENAME", "--output=FILENAME", "Output file to write to") do |v|
|
18
18
|
ReverseAdoc.config.destination = File.expand_path(v)
|
19
19
|
# puts "output goes to #{ReverseAdoc.config.destination}"
|
20
20
|
end
|
21
21
|
|
22
|
-
opts.on(
|
22
|
+
opts.on("-e", "--external-images", "Export images if data URI") do |_v|
|
23
23
|
ReverseAdoc.config.external_images = true
|
24
24
|
end
|
25
25
|
|
26
|
-
opts.on(
|
26
|
+
opts.on("-u", "--unknown_tags [pass_through, drop, bypass, raise]",
|
27
|
+
"Unknown tag handling (default: pass_through)") do |v|
|
27
28
|
ReverseAdoc.config.unknown_tags = v
|
28
29
|
end
|
29
30
|
|
30
|
-
opts.on(
|
31
|
+
opts.on("-v", "--version", "Version information") do |_v|
|
31
32
|
puts "reverse_adoc: v#{ReverseAdoc::VERSION}"
|
32
33
|
exit
|
33
34
|
end
|
@@ -36,7 +37,6 @@ OptionParser.new do |opts|
|
|
36
37
|
puts opts
|
37
38
|
exit
|
38
39
|
end
|
39
|
-
|
40
40
|
end.parse!
|
41
41
|
|
42
42
|
if filename = ARGV.pop
|
data/exe/w2a
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "rubygems"
|
5
|
+
require "bundler/setup"
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
7
|
+
require "word-to-markdown"
|
8
|
+
require "optparse"
|
9
|
+
require "reverse_adoc"
|
10
10
|
|
11
|
-
ARGV.push(
|
11
|
+
ARGV.push("-h") if ARGV.empty?
|
12
12
|
|
13
13
|
OptionParser.new do |opts|
|
14
14
|
opts.banner = "Usage: w2a [options] <file>"
|
15
|
-
opts.on(
|
15
|
+
opts.on("-m", "--mathml2asciimath", "Convert MathML to AsciiMath") do |_v|
|
16
16
|
ReverseAdoc.config.mathml2asciimath = true
|
17
17
|
end
|
18
18
|
|
19
|
-
opts.on(
|
19
|
+
opts.on("-oFILENAME", "--output=FILENAME", "Output file to write to") do |v|
|
20
20
|
ReverseAdoc.config.destination = File.expand_path(v)
|
21
21
|
# puts "output goes to #{ReverseAdoc.config.destination}"
|
22
22
|
end
|
23
23
|
|
24
|
-
opts.on(
|
24
|
+
opts.on("-e", "--external-images", "Export images if data URI") do |_v|
|
25
25
|
ReverseAdoc.config.external_images = true
|
26
26
|
end
|
27
27
|
|
28
|
-
opts.on(
|
28
|
+
opts.on("-v", "--version", "Version information") do |_v|
|
29
29
|
puts "reverse_adoc: v#{ReverseAdoc::VERSION}"
|
30
30
|
puts "[dependency] WordToMarkdown: v#{WordToMarkdown::VERSION}"
|
31
|
-
|
32
|
-
puts "[dependency] LibreOffice: v#{WordToMarkdown.soffice.version}"
|
33
|
-
else
|
31
|
+
if Gem.win_platform?
|
34
32
|
puts "[dependency] LibreOffice: version not available on Windows"
|
33
|
+
else
|
34
|
+
puts "[dependency] LibreOffice: v#{WordToMarkdown.soffice.version}"
|
35
35
|
end
|
36
36
|
exit
|
37
37
|
end
|
@@ -40,7 +40,6 @@ OptionParser.new do |opts|
|
|
40
40
|
puts opts
|
41
41
|
exit
|
42
42
|
end
|
43
|
-
|
44
43
|
end.parse!
|
45
44
|
|
46
45
|
filename = ARGV.pop
|
@@ -53,10 +52,10 @@ end
|
|
53
52
|
ReverseAdoc.config.sourcedir = Dir.mktmpdir
|
54
53
|
|
55
54
|
doc = WordToMarkdown.new(filename, ReverseAdoc.config.sourcedir)
|
56
|
-
#File.open("test.html", "w:UTF-8") { |f| f.write doc.document.html }
|
55
|
+
# File.open("test.html", "w:UTF-8") { |f| f.write doc.document.html }
|
57
56
|
adoc_content = ReverseAdoc.convert(
|
58
57
|
ReverseAdoc.cleaner.preprocess_word_html(doc.document.html),
|
59
|
-
WordToMarkdown::REVERSE_MARKDOWN_OPTIONS
|
58
|
+
WordToMarkdown::REVERSE_MARKDOWN_OPTIONS,
|
60
59
|
)
|
61
60
|
# puts scrub_whitespace(doc.document.html)
|
62
61
|
|
data/lib/reverse_adoc/cleaner.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
class Cleaner
|
3
3
|
def tidy(string)
|
4
|
-
result = remove_inner_whitespaces(string)
|
4
|
+
result = remove_inner_whitespaces(String.new(string))
|
5
5
|
result = remove_newlines(result)
|
6
6
|
result = remove_leading_newlines(result)
|
7
7
|
result = clean_tag_borders(result)
|
@@ -34,20 +34,21 @@ module ReverseAdoc
|
|
34
34
|
# in the border area.
|
35
35
|
# Same for underscores and brackets.
|
36
36
|
def clean_tag_borders(string)
|
37
|
-
result = string.gsub(/\s?\*{2,}.*?\*{2,}\s?/) do |match|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
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
42
|
|
43
|
-
result =
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
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
48
|
|
49
|
-
result =
|
50
|
-
preserve_border_whitespaces(match,
|
49
|
+
result = string.gsub(/\s?~{2,}.*?~{2,}\s?/) do |match|
|
50
|
+
preserve_border_whitespaces(match,
|
51
|
+
default_border: ReverseAdoc.config.tag_border) do
|
51
52
|
match.strip.sub("~~ ", "~~").sub(" ~~", "~~")
|
52
53
|
end
|
53
54
|
end
|
@@ -60,7 +61,7 @@ module ReverseAdoc
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def clean_punctuation_characters(string)
|
63
|
-
string.gsub(/(\*\*|~~|__)\s([.!?'"])/, "\\1
|
64
|
+
string.gsub(/(\*\*|~~|__)\s([.!?'"])/, "#{'\\1'.strip}\\2")
|
64
65
|
end
|
65
66
|
|
66
67
|
# preprocesses HTML, rather than postprocessing it
|
@@ -104,11 +105,9 @@ module ReverseAdoc
|
|
104
105
|
end
|
105
106
|
|
106
107
|
def present_or_default(string, default)
|
107
|
-
if string.nil? || string.empty?
|
108
|
-
|
109
|
-
|
110
|
-
string
|
111
|
-
end
|
108
|
+
return default if string.nil? || string.empty?
|
109
|
+
|
110
|
+
string
|
112
111
|
end
|
113
112
|
end
|
114
113
|
end
|
data/lib/reverse_adoc/config.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "tmpdir"
|
2
2
|
|
3
3
|
module ReverseAdoc
|
4
4
|
class Config
|
5
5
|
attr_accessor :unknown_tags, :tag_border, :mathml2asciimath, :external_images,
|
6
|
-
|
6
|
+
:destination, :sourcedir, :image_counter, :image_counter_pattern, :input_format
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@unknown_tags = :pass_through
|
@@ -18,14 +18,14 @@ module ReverseAdoc
|
|
18
18
|
# @sourcedir = nil
|
19
19
|
|
20
20
|
# Image counter, assuming there are max 999 images
|
21
|
-
@image_counter
|
21
|
+
@image_counter = 1
|
22
22
|
# pad with 0s
|
23
|
-
@image_counter_pattern =
|
23
|
+
@image_counter_pattern = "%03d"
|
24
24
|
|
25
|
-
@em_delimiter =
|
26
|
-
@strong_delimiter =
|
25
|
+
@em_delimiter = "_".freeze
|
26
|
+
@strong_delimiter = "*".freeze
|
27
27
|
@inline_options = {}
|
28
|
-
@tag_border =
|
28
|
+
@tag_border = " ".freeze
|
29
29
|
end
|
30
30
|
|
31
31
|
def with(options = {})
|
@@ -1,40 +1,40 @@
|
|
1
|
-
require "
|
1
|
+
require "coradoc"
|
2
2
|
|
3
3
|
module ReverseAdoc
|
4
4
|
module Converters
|
5
5
|
class A < Base
|
6
|
-
def
|
6
|
+
def to_coradoc(node, state = {})
|
7
7
|
name = treat_children(node, state)
|
8
|
-
|
8
|
+
|
9
|
+
href = node["href"]
|
9
10
|
title = extract_title(node)
|
10
|
-
id = node[
|
11
|
+
id = node["id"] || node["name"]
|
11
12
|
|
12
13
|
id = id&.gsub(/\s/, "")&.gsub(/__+/, "_")
|
13
14
|
|
14
|
-
if /^_Toc\d+$|^_GoBack$/.match
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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?("#")
|
19
22
|
href = href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_")
|
20
|
-
|
21
|
-
"<<#{href}>>"
|
22
|
-
else
|
23
|
-
"<<#{href},#{name}>>"
|
24
|
-
end
|
25
|
-
elsif href.to_s.empty?
|
26
|
-
name
|
27
|
-
else
|
28
|
-
name = title if name.empty?
|
29
|
-
href = "link:#{href}" unless href.to_s =~ URI::DEFAULT_PARSER.make_regexp
|
30
|
-
link = "#{href}[#{name}]"
|
31
|
-
link.prepend(' ')
|
32
|
-
link
|
23
|
+
return Coradoc::Element::Inline::CrossReference.new(href, name)
|
33
24
|
end
|
34
|
-
end
|
35
25
|
|
36
|
-
|
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
|
37
34
|
|
35
|
+
def convert(node, state = {})
|
36
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
37
|
+
end
|
38
38
|
end
|
39
39
|
|
40
40
|
register :a, A.new
|
@@ -1,11 +1,13 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
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
|
+
|
4
9
|
def convert(node, state = {})
|
5
|
-
|
6
|
-
anchor = id ? "[[#{id}]]\n" : ""
|
7
|
-
content = treat_children(node, state).strip
|
8
|
-
"\n\n****\n" << treat_children(node, state) << "\n****\n\n"
|
10
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
@@ -1,31 +1,26 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Audio < Base
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
controls = node['controls']
|
8
|
-
src = node['src']
|
9
|
-
id = node['id']
|
10
|
-
anchor = id ? "[[#{id}]]\n" : ""
|
4
|
+
def to_coradoc(node, _state = {})
|
5
|
+
src = node["src"]
|
6
|
+
id = node["id"]
|
11
7
|
title = extract_title(node)
|
12
|
-
|
13
|
-
|
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))
|
14
17
|
end
|
15
18
|
|
16
19
|
def options(node)
|
17
|
-
autoplay
|
18
|
-
loop_attr
|
19
|
-
controls
|
20
|
-
|
21
|
-
if autoplay || loop_attr || controls
|
22
|
-
out = []
|
23
|
-
out << "autoplay" if autoplay
|
24
|
-
out << "loop" if loop_attr
|
25
|
-
out << "controls" if controls
|
26
|
-
ret = %{options="#{out.join(',')}"}
|
27
|
-
end
|
28
|
-
ret
|
20
|
+
autoplay = node["autoplay"]
|
21
|
+
loop_attr = node["loop"]
|
22
|
+
controls = node["controls"]
|
23
|
+
[autoplay, loop_attr, controls].compact
|
29
24
|
end
|
30
25
|
end
|
31
26
|
|
@@ -2,7 +2,7 @@ module ReverseAdoc
|
|
2
2
|
module Converters
|
3
3
|
class Base
|
4
4
|
def treat_children(node, state)
|
5
|
-
node.children.inject(
|
5
|
+
node.children.inject("") do |memo, child|
|
6
6
|
memo << treat(child, state)
|
7
7
|
end
|
8
8
|
end
|
@@ -11,15 +11,89 @@ module ReverseAdoc
|
|
11
11
|
ReverseAdoc::Converters.lookup(node.name).convert(node, state)
|
12
12
|
end
|
13
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
|
+
|
14
24
|
def escape_keychars(string)
|
15
|
-
subs = {
|
25
|
+
subs = { "*" => '\*', "_" => '\_' }
|
16
26
|
string
|
17
|
-
.gsub(/((?<=\s)[\*_]+)|[\*_]+(?=\s)/)
|
27
|
+
.gsub(/((?<=\s)[\*_]+)|[\*_]+(?=\s)/) do |n|
|
28
|
+
n.chars.map do |char|
|
29
|
+
subs[char]
|
30
|
+
end.join
|
31
|
+
end
|
18
32
|
end
|
19
33
|
|
20
34
|
def extract_title(node)
|
21
|
-
title = escape_keychars(node[
|
22
|
-
title.empty? ?
|
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
|
23
97
|
end
|
24
98
|
end
|
25
99
|
end
|
@@ -1,15 +1,24 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Blockquote < Base
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
9
14
|
content = treat_children(node, state).strip
|
10
15
|
content = ReverseAdoc.cleaner.remove_newlines(content)
|
11
|
-
|
12
|
-
|
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))
|
13
22
|
end
|
14
23
|
end
|
15
24
|
|
@@ -1,8 +1,12 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Br < Base
|
4
|
+
def to_coradoc(_node, _state = {})
|
5
|
+
Coradoc::Element::Inline::HardLineBreak.new
|
6
|
+
end
|
7
|
+
|
4
8
|
def convert(node, state = {})
|
5
|
-
|
9
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
6
10
|
end
|
7
11
|
end
|
8
12
|
|