coradoc 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +35 -0
- data/{.docker/readme.md → README.Docker.adoc} +21 -25
- data/README.adoc +121 -0
- data/coradoc.gemspec +4 -0
- data/docker-compose.yml +14 -0
- data/exe/coradoc +5 -0
- data/exe/reverse_adoc +24 -34
- data/exe/w2a +16 -28
- data/lib/coradoc/cli.rb +105 -0
- data/lib/coradoc/converter.rb +145 -0
- data/lib/coradoc/document.rb +13 -0
- data/lib/coradoc/element/admonition.rb +5 -0
- data/lib/coradoc/element/attribute_list.rb +1 -1
- data/lib/coradoc/element/author.rb +4 -4
- data/lib/coradoc/element/bibliography.rb +24 -0
- data/lib/coradoc/element/bibliography_entry.rb +24 -0
- data/lib/coradoc/element/block/core.rb +6 -4
- data/lib/coradoc/element/block/example.rb +1 -0
- data/lib/coradoc/element/block/pass.rb +21 -0
- data/lib/coradoc/element/block/quote.rb +1 -1
- data/lib/coradoc/element/block/reviewer_comment.rb +19 -0
- data/lib/coradoc/element/block/side.rb +4 -2
- data/lib/coradoc/element/block/sourcecode.rb +1 -0
- data/lib/coradoc/element/block.rb +2 -0
- data/lib/coradoc/element/comment_block.rb +22 -0
- data/lib/coradoc/element/comment_line.rb +18 -0
- data/lib/coradoc/element/document_attributes.rb +8 -1
- data/lib/coradoc/element/header.rb +1 -1
- data/lib/coradoc/element/image/block_image.rb +8 -0
- data/lib/coradoc/element/image/core.rb +6 -5
- data/lib/coradoc/element/include.rb +18 -0
- data/lib/coradoc/element/inline/citation.rb +24 -0
- data/lib/coradoc/element/inline/cross_reference.rb +29 -8
- data/lib/coradoc/element/inline.rb +1 -0
- data/lib/coradoc/element/list/core.rb +10 -2
- data/lib/coradoc/element/list_item.rb +7 -5
- data/lib/coradoc/element/paragraph.rb +8 -5
- data/lib/coradoc/element/revision.rb +1 -1
- data/lib/coradoc/element/section.rb +6 -4
- data/lib/coradoc/element/table.rb +2 -2
- data/lib/coradoc/element/tag.rb +19 -0
- data/lib/coradoc/element/term.rb +21 -0
- data/lib/coradoc/element/text_element.rb +9 -1
- data/lib/coradoc/element/title.rb +1 -1
- data/lib/coradoc/generator.rb +2 -0
- data/lib/coradoc/input/adoc.rb +28 -0
- data/lib/coradoc/input/docx.rb +35 -0
- data/lib/coradoc/{reverse_adoc → input/html}/README.adoc +9 -9
- data/lib/coradoc/{reverse_adoc → input/html}/cleaner.rb +18 -4
- data/lib/coradoc/input/html/config.rb +75 -0
- data/lib/coradoc/{reverse_adoc → input/html}/converters/a.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/aside.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/audio.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/base.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/blockquote.rb +2 -2
- data/lib/coradoc/{reverse_adoc → input/html}/converters/br.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/bypass.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/code.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/div.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/dl.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/drop.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/em.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/figure.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/h.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/head.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/hr.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/ignore.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/img.rb +7 -7
- data/lib/coradoc/{reverse_adoc → input/html}/converters/li.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/mark.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/markup.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/math.rb +3 -3
- data/lib/coradoc/{reverse_adoc → input/html}/converters/ol.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/p.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/pass_through.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/pre.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/q.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/strong.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/sub.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/sup.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/table.rb +4 -4
- data/lib/coradoc/{reverse_adoc → input/html}/converters/td.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/text.rb +2 -2
- data/lib/coradoc/{reverse_adoc → input/html}/converters/th.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/tr.rb +1 -1
- data/lib/coradoc/{reverse_adoc → input/html}/converters/video.rb +1 -1
- data/lib/coradoc/input/html/converters.rb +57 -0
- data/lib/coradoc/input/html/errors.rb +12 -0
- data/lib/coradoc/{reverse_adoc → input/html}/html_converter.rb +37 -22
- data/lib/coradoc/{reverse_adoc → input/html}/plugin.rb +6 -6
- data/lib/coradoc/{reverse_adoc → input/html}/plugins/plateau.rb +3 -3
- data/lib/coradoc/{reverse_adoc → input/html}/postprocessor.rb +3 -3
- data/lib/coradoc/input/html.rb +59 -0
- data/lib/coradoc/input.rb +12 -0
- data/lib/coradoc/output/adoc.rb +17 -0
- data/lib/coradoc/output/coradoc_tree_debug.rb +19 -0
- data/lib/coradoc/output.rb +11 -0
- data/lib/coradoc/parser/asciidoc/admonition.rb +24 -0
- data/lib/coradoc/parser/asciidoc/attribute_list.rb +67 -0
- data/lib/coradoc/parser/asciidoc/base.rb +101 -13
- data/lib/coradoc/parser/asciidoc/bibliography.rb +30 -0
- data/lib/coradoc/parser/asciidoc/block.rb +82 -0
- data/lib/coradoc/parser/asciidoc/citation.rb +48 -0
- data/lib/coradoc/parser/asciidoc/content.rb +15 -120
- data/lib/coradoc/parser/asciidoc/document_attributes.rb +12 -5
- data/lib/coradoc/parser/asciidoc/header.rb +1 -4
- data/lib/coradoc/parser/asciidoc/inline.rb +72 -0
- data/lib/coradoc/parser/asciidoc/list.rb +81 -0
- data/lib/coradoc/parser/asciidoc/paragraph.rb +33 -0
- data/lib/coradoc/parser/asciidoc/section.rb +36 -31
- data/lib/coradoc/parser/asciidoc/table.rb +32 -0
- data/lib/coradoc/parser/asciidoc/term.rb +23 -0
- data/lib/coradoc/parser/base.rb +39 -4
- data/lib/coradoc/transformer.rb +353 -82
- data/lib/coradoc/util.rb +1 -1
- data/lib/coradoc/version.rb +1 -1
- data/lib/coradoc.rb +8 -5
- data/lib/reverse_adoc.rb +6 -6
- data/utils/parser_analyzer.rb +66 -0
- data/utils/round_trip.rb +37 -0
- metadata +112 -54
- data/.docker/Makefile +0 -35
- data/.docker/docker-compose.yml +0 -14
- data/Makefile +0 -1
- data/README.md +0 -73
- data/docker-compose.yml +0 -1
- data/lib/coradoc/reverse_adoc/config.rb +0 -73
- data/lib/coradoc/reverse_adoc/converters.rb +0 -55
- data/lib/coradoc/reverse_adoc/errors.rb +0 -10
- data/lib/coradoc/reverse_adoc.rb +0 -30
- /data/{.docker/Dockerfile → Dockerfile} +0 -0
- /data/lib/coradoc/{reverse_adoc → input/html}/LICENSE.txt +0 -0
@@ -1,10 +1,10 @@
|
|
1
|
-
# Unless run with Coradoc::
|
1
|
+
# Unless run with Coradoc::Input::HTML.config.mathml2asciimath,
|
2
2
|
# this is cheating: we're injecting MathML into Asciidoctor, but
|
3
3
|
# Asciidoctor only understands AsciiMath or LaTeX
|
4
4
|
|
5
5
|
require "mathml2asciimath"
|
6
6
|
|
7
|
-
module Coradoc::
|
7
|
+
module Coradoc::Input::HTML
|
8
8
|
module Converters
|
9
9
|
class Math < Base
|
10
10
|
# FIXIT
|
@@ -14,7 +14,7 @@ module Coradoc::ReverseAdoc
|
|
14
14
|
|
15
15
|
def convert(node, _state = {})
|
16
16
|
stem = node.to_s.gsub(/\n/, " ")
|
17
|
-
stem = MathML2AsciiMath.m2a(stem) if Coradoc::
|
17
|
+
stem = MathML2AsciiMath.m2a(stem) if Coradoc::Input::HTML.config.mathml2asciimath
|
18
18
|
unless stem.nil?
|
19
19
|
stem = stem.gsub(/\[/, "\\[").gsub(/\]/, "\\]").gsub(
|
20
20
|
/\(\(([^\)]+)\)\)/, "(\\1)"
|
@@ -1,12 +1,12 @@
|
|
1
|
-
module Coradoc::
|
1
|
+
module Coradoc::Input::HTML
|
2
2
|
module Converters
|
3
3
|
class Table < Base
|
4
4
|
def to_coradoc(node, state = {})
|
5
5
|
id = node["id"]
|
6
6
|
title = extract_title(node)
|
7
|
-
|
7
|
+
attributes = style(node)
|
8
8
|
content = treat_children_coradoc(node, state)
|
9
|
-
Coradoc::Element::Table.new(title, content, { id: id,
|
9
|
+
Coradoc::Element::Table.new(title, content, { id: id, attributes: attributes })
|
10
10
|
end
|
11
11
|
|
12
12
|
def extract_title(node)
|
@@ -238,7 +238,7 @@ module Coradoc::ReverseAdoc
|
|
238
238
|
end
|
239
239
|
end
|
240
240
|
|
241
|
-
document_width = Coradoc::
|
241
|
+
document_width = Coradoc::Input::HTML.config.doc_width.to_r
|
242
242
|
|
243
243
|
column_sizes += [nil] * (cpr.first - column_sizes.length)
|
244
244
|
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module Coradoc::
|
1
|
+
module Coradoc::Input::HTML
|
2
2
|
module Converters
|
3
3
|
class Text < Base
|
4
4
|
def to_coradoc(node, state = {})
|
5
5
|
return treat_empty(node, state) if node.text.strip.empty?
|
6
6
|
|
7
|
-
Coradoc::Element::TextElement.new(node.text)
|
7
|
+
Coradoc::Element::TextElement.new(node.text, html_cleanup: true)
|
8
8
|
end
|
9
9
|
|
10
10
|
private
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Input::HTML
|
3
|
+
module Converters
|
4
|
+
def self.register(tag_name, converter)
|
5
|
+
@@converters ||= {}
|
6
|
+
@@converters[tag_name.to_sym] = converter
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.unregister(tag_name)
|
10
|
+
@@converters.delete(tag_name.to_sym)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.lookup(tag_name)
|
14
|
+
converter = @@converters[tag_name.to_sym] || default_converter(tag_name)
|
15
|
+
converter = converter.new if converter.respond_to? :new
|
16
|
+
converter
|
17
|
+
end
|
18
|
+
|
19
|
+
# Note: process won't run plugin hooks
|
20
|
+
def self.process(node, state)
|
21
|
+
node = node.to_a if node.is_a? Nokogiri::XML::NodeSet
|
22
|
+
return node.map { |i| process(i, state) }.join if node.is_a? Array
|
23
|
+
|
24
|
+
lookup(node.name).convert(node, state)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.process_coradoc(node, state)
|
28
|
+
node = node.to_a if node.is_a? Nokogiri::XML::NodeSet
|
29
|
+
return node.map { |i| process_coradoc(i, state) } if node.is_a? Array
|
30
|
+
|
31
|
+
plugins = state[:plugin_instances] || {}
|
32
|
+
process = proc { lookup(node.name).to_coradoc(node, state) }
|
33
|
+
plugins.each do |i|
|
34
|
+
prev_process = process
|
35
|
+
process = proc { i.html_tree_run_hooks(node, state, &prev_process) }
|
36
|
+
end
|
37
|
+
process.(node, state)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.default_converter(tag_name)
|
41
|
+
case Coradoc::Input::HTML.config.unknown_tags.to_sym
|
42
|
+
when :pass_through
|
43
|
+
Coradoc::Input::HTML::Converters::PassThrough.new
|
44
|
+
when :drop
|
45
|
+
Coradoc::Input::HTML::Converters::Drop.new
|
46
|
+
when :bypass
|
47
|
+
Coradoc::Input::HTML::Converters::Bypass.new
|
48
|
+
when :raise
|
49
|
+
raise UnknownTagError, "unknown tag: #{tag_name}"
|
50
|
+
else
|
51
|
+
raise InvalidConfigurationError,
|
52
|
+
"unknown value #{Coradoc::Input::HTML.config.unknown_tags.inspect} for Coradoc::Input::HTML.config.unknown_tags"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -37,12 +37,11 @@ require_relative "converters/video"
|
|
37
37
|
require_relative "converters/math"
|
38
38
|
|
39
39
|
module Coradoc
|
40
|
-
module
|
40
|
+
module Input::HTML
|
41
41
|
class HtmlConverter
|
42
42
|
def self.to_coradoc(input, options = {})
|
43
|
-
|
44
|
-
|
45
|
-
plugin_instances ||= Coradoc::ReverseAdoc.config.plugins.map(&:new)
|
43
|
+
Input::HTML.config.with(options) do
|
44
|
+
plugin_instances = prepare_plugin_instances(options)
|
46
45
|
|
47
46
|
root = track_time "Loading input HTML document" do
|
48
47
|
case input
|
@@ -85,52 +84,68 @@ module Coradoc
|
|
85
84
|
end
|
86
85
|
end
|
87
86
|
|
87
|
+
options[:plugin_instances] = plugin_instances unless options.frozen?
|
88
|
+
|
88
89
|
coradoc
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
92
93
|
def self.convert(input, options = {})
|
93
|
-
|
94
|
-
plugin_instances =
|
95
|
-
|
96
|
-
options = options.merge(plugin_instances: plugin_instances)
|
94
|
+
Input::HTML.config.with(options) do
|
95
|
+
plugin_instances = prepare_plugin_instances(options)
|
97
96
|
|
98
97
|
coradoc = to_coradoc(input, options)
|
99
98
|
|
100
99
|
if coradoc.is_a?(Hash)
|
101
100
|
coradoc.to_h do |file, tree|
|
102
101
|
track_time "Converting file #{file || 'main'}" do
|
103
|
-
[file,
|
102
|
+
[file,
|
103
|
+
convert_single_coradoc_to_adoc(file, tree, options)]
|
104
104
|
end
|
105
105
|
end
|
106
106
|
else
|
107
|
-
convert_single_coradoc_to_adoc(nil, coradoc,
|
107
|
+
convert_single_coradoc_to_adoc(nil, coradoc, options)
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
def self.convert_single_coradoc_to_adoc(_file, coradoc,
|
112
|
+
def self.convert_single_coradoc_to_adoc(_file, coradoc, options)
|
113
|
+
plugin_instances = prepare_plugin_instances(options)
|
114
|
+
|
113
115
|
result = track_time "Converting Coradoc tree into Asciidoc" do
|
114
116
|
Coradoc::Generator.gen_adoc(coradoc)
|
115
117
|
end
|
116
|
-
result
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
118
|
+
cleanup_result(result, options)
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.cleanup_result(result, options)
|
122
|
+
Input::HTML.config.with(options) do
|
123
|
+
plugin_instances = prepare_plugin_instances(options)
|
124
|
+
|
125
|
+
result = track_time "Cleaning up the result" do
|
126
|
+
Input::HTML.cleaner.tidy(result)
|
127
|
+
end
|
128
|
+
plugin_instances.each do |plugin|
|
129
|
+
if plugin.respond_to?(:postprocess_asciidoc_string)
|
130
|
+
plugin.asciidoc_string = result
|
131
|
+
track_time "Postprocessing AsciiDoc string with #{plugin.name} plugin" do
|
132
|
+
plugin.postprocess_asciidoc_string
|
133
|
+
end
|
134
|
+
result = plugin.asciidoc_string
|
124
135
|
end
|
125
|
-
result = plugin.asciidoc_string
|
126
136
|
end
|
137
|
+
|
138
|
+
result
|
127
139
|
end
|
128
|
-
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.prepare_plugin_instances(options)
|
143
|
+
options[:plugin_instances] || Coradoc::Input::HTML.config.plugins.map(&:new)
|
129
144
|
end
|
130
145
|
|
131
146
|
@track_time_indentation = 0
|
132
147
|
def self.track_time(task)
|
133
|
-
if
|
148
|
+
if Input::HTML.config.track_time
|
134
149
|
warn " " * @track_time_indentation +
|
135
150
|
"* #{task} is starting..."
|
136
151
|
@track_time_indentation += 1
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module Coradoc::
|
1
|
+
module Coradoc::Input::HTML
|
2
2
|
class Plugin
|
3
3
|
#### Plugin system general
|
4
4
|
|
5
5
|
# Allow building plugins with a shorthand syntax:
|
6
|
-
# plugin = Coradoc::
|
6
|
+
# plugin = Coradoc::Input::HTML::Plugin.new do
|
7
7
|
# def name = "Test"
|
8
8
|
# end
|
9
9
|
|
@@ -53,12 +53,12 @@ module Coradoc::ReverseAdoc
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
def html_tree_process_to_coradoc(tree, state={})
|
57
|
-
Coradoc::
|
56
|
+
def html_tree_process_to_coradoc(tree, state = {})
|
57
|
+
Coradoc::Input::HTML::Converters.process_coradoc(tree, state)
|
58
58
|
end
|
59
59
|
|
60
|
-
def html_tree_process_to_adoc(tree, state={})
|
61
|
-
Coradoc::
|
60
|
+
def html_tree_process_to_adoc(tree, state = {})
|
61
|
+
Coradoc::Input::HTML::Converters.process(tree, state)
|
62
62
|
end
|
63
63
|
|
64
64
|
def html_tree_preview
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module Coradoc::
|
1
|
+
module Coradoc::Input::HTML
|
2
2
|
class Plugin
|
3
3
|
# This plugin enhances documents from the PLATEAU project
|
4
4
|
# to extract more data.
|
5
5
|
#
|
6
6
|
# Usage:
|
7
|
-
# reverse_adoc -rcoradoc/
|
7
|
+
# reverse_adoc -rcoradoc/input/html/plugins/plateau
|
8
8
|
# --external-images -u raise --output _out/index.adoc index.html
|
9
9
|
class Plateau < Plugin
|
10
10
|
def name
|
@@ -203,4 +203,4 @@ module Coradoc::ReverseAdoc
|
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
206
|
-
Coradoc::
|
206
|
+
Coradoc::Input::HTML.config.plugins << Coradoc::Input::HTML::Plugin::Plateau
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Coradoc::
|
1
|
+
module Coradoc::Input::HTML
|
2
2
|
# Postprocessor's aim is to convert a Coradoc tree from
|
3
3
|
# a mess that has been created from HTML into a tree that
|
4
4
|
# is compatible with what we would get out of Coradoc, if
|
@@ -73,7 +73,7 @@ module Coradoc::ReverseAdoc
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def split_sections
|
76
|
-
max_level = Coradoc::
|
76
|
+
max_level = Coradoc::Input::HTML.config.split_sections
|
77
77
|
|
78
78
|
return unless max_level
|
79
79
|
|
@@ -111,7 +111,7 @@ module Coradoc::ReverseAdoc
|
|
111
111
|
# we can compute numbers
|
112
112
|
previous_sections[elem] = parent_sections[title.level_int]
|
113
113
|
parent_sections[title.level_int] = elem
|
114
|
-
parent_sections[(title.level_int+1)..nil] = nil
|
114
|
+
parent_sections[(title.level_int + 1)..nil] = nil
|
115
115
|
|
116
116
|
elem
|
117
117
|
else
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "digest"
|
4
|
+
require "nokogiri"
|
5
|
+
require "coradoc/input"
|
6
|
+
require_relative "html/errors"
|
7
|
+
require_relative "html/cleaner"
|
8
|
+
require_relative "html/config"
|
9
|
+
require_relative "html/converters"
|
10
|
+
require_relative "html/converters/base"
|
11
|
+
require_relative "html/html_converter"
|
12
|
+
require_relative "html/plugin"
|
13
|
+
require_relative "html/postprocessor"
|
14
|
+
|
15
|
+
module Coradoc
|
16
|
+
module Input::HTML
|
17
|
+
def self.convert(input, options = {})
|
18
|
+
Coradoc::Input::HTML::HtmlConverter.convert(input, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.to_coradoc(input, options = {})
|
22
|
+
Input::HTML::HtmlConverter.to_coradoc(input, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.config
|
26
|
+
@config ||= Config.new
|
27
|
+
yield @config if block_given?
|
28
|
+
@config
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.cleaner
|
32
|
+
@cleaner ||= Cleaner.new
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.processor_id
|
36
|
+
:html
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.processor_match?(filename)
|
40
|
+
%w[.html .htm].any? { |i| filename.downcase.end_with?(i) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.processor_execute(input, options = {})
|
44
|
+
to_coradoc(input, options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.processor_postprocess(data, options)
|
48
|
+
if options[:output_processor] == :adoc
|
49
|
+
data.transform_values do |v|
|
50
|
+
Input::HTML::HtmlConverter.cleanup_result(v, options)
|
51
|
+
end
|
52
|
+
else
|
53
|
+
data
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
Coradoc::Input.define(self)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Output::Adoc
|
3
|
+
def self.processor_id
|
4
|
+
:adoc
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.processor_match?(filename)
|
8
|
+
%w[.adoc].any? { |i| filename.downcase.end_with?(i) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.processor_execute(input, _options = {})
|
12
|
+
input.transform_values { |i| Coradoc::Generator.gen_adoc(i) }
|
13
|
+
end
|
14
|
+
|
15
|
+
Coradoc::Output.define(self)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Output::CoradocTreeDebug
|
3
|
+
def self.processor_id
|
4
|
+
:coradoc_tree_debug
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.processor_match?(filename)
|
8
|
+
false
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.processor_execute(input, _options = {})
|
12
|
+
out = StringIO.new
|
13
|
+
PP.pp(input, out)
|
14
|
+
{ nil => out.string }
|
15
|
+
end
|
16
|
+
|
17
|
+
Coradoc::Output.define(self)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Parser
|
3
|
+
module Asciidoc
|
4
|
+
module Admonition
|
5
|
+
def admonition_type
|
6
|
+
str('NOTE') | str('TIP') | str('EDITOR') |
|
7
|
+
str('IMPORTANT') | str('WARNING') | str('CAUTION') |
|
8
|
+
str('TODO')
|
9
|
+
# requires atypical syntax for access?
|
10
|
+
# | str('DANGER')
|
11
|
+
# | str('SAFETY PRECAUTION')
|
12
|
+
end
|
13
|
+
def admonition_line
|
14
|
+
admonition_type.as(:admonition_type) >> str(': ') >>
|
15
|
+
(
|
16
|
+
(text.as(:text) >>
|
17
|
+
line_ending.as(:line_break)
|
18
|
+
).repeat(1)
|
19
|
+
).as(:content)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Parser
|
3
|
+
module Asciidoc
|
4
|
+
module AttributeList
|
5
|
+
|
6
|
+
def named_attribute_name
|
7
|
+
attribute_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def named_attribute_value
|
11
|
+
match('[^\],]').repeat(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
def named_attribute
|
15
|
+
(match('[a-zA-Z0-9_-]').repeat(1).as(:named_key) >>
|
16
|
+
str(' ').maybe >> str("=") >> str(' ').maybe >>
|
17
|
+
match['a-zA-Z0-9_\- \"'].repeat(1).as(:named_value) >>
|
18
|
+
str(' ').maybe
|
19
|
+
).as(:named)
|
20
|
+
end
|
21
|
+
|
22
|
+
def positional_attribute
|
23
|
+
(match['a-zA-Z0-9_\-%'].repeat(1) >>
|
24
|
+
str("=").absent?
|
25
|
+
).as(:positional)
|
26
|
+
end
|
27
|
+
|
28
|
+
def named_many
|
29
|
+
(named_attribute.repeat(1,1) >>
|
30
|
+
(str(",") >> space.maybe >> named_attribute).repeat(0))
|
31
|
+
end
|
32
|
+
|
33
|
+
def positional_one_named_many
|
34
|
+
(positional_attribute.repeat(1,1) >>
|
35
|
+
(str(",") >> space.maybe >> named_attribute).repeat(1))
|
36
|
+
end
|
37
|
+
|
38
|
+
def positional_many_named_many
|
39
|
+
(positional_attribute.repeat(1,1) >>
|
40
|
+
(str(",") >> space.maybe >> positional_attribute).repeat(1) >>
|
41
|
+
(str(",") >> space.maybe>> named_attribute).repeat(1))
|
42
|
+
end
|
43
|
+
|
44
|
+
def positional_many
|
45
|
+
(positional_attribute.repeat(1,1) >>
|
46
|
+
(str(",") >> space.maybe >> positional_attribute).repeat(0))
|
47
|
+
end
|
48
|
+
|
49
|
+
def positional_zero_or_one
|
50
|
+
positional_attribute.repeat(0,1)
|
51
|
+
end
|
52
|
+
|
53
|
+
def attribute_list(name = :attribute_list)
|
54
|
+
str('[') >> str("[").absent? >>
|
55
|
+
( named_many |
|
56
|
+
positional_one_named_many |
|
57
|
+
positional_many_named_many |
|
58
|
+
positional_many |
|
59
|
+
positional_zero_or_one
|
60
|
+
).as(:attribute_array).as(name) >>
|
61
|
+
str("]")
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|