coradoc 1.0.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 +7 -4
- 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 +16 -3
- data/lib/coradoc/element/list/definition.rb +3 -1
- data/lib/coradoc/element/list_item.rb +15 -5
- data/lib/coradoc/element/paragraph.rb +8 -5
- data/lib/coradoc/element/revision.rb +1 -1
- data/lib/coradoc/element/section.rb +11 -3
- data/lib/coradoc/element/table.rb +6 -1
- 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 +2 -2
- 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 +19 -6
- 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 +17 -10
- 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 +36 -11
- 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 +62 -30
- data/lib/coradoc/{reverse_adoc → input/html}/postprocessor.rb +13 -9
- 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 +10 -0
- data/lib/coradoc/version.rb +1 -1
- data/lib/coradoc.rb +8 -4
- data/lib/reverse_adoc.rb +6 -6
- data/utils/parser_analyzer.rb +66 -0
- data/utils/round_trip.rb +37 -0
- metadata +113 -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 -53
- 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
|
-
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
|
@@ -30,12 +30,20 @@ module Coradoc::ReverseAdoc
|
|
30
30
|
html_tree_change_tag_name_by_css(".pitemdata", "h3")
|
31
31
|
html_tree_change_tag_name_by_css(".sitemdata", "h4")
|
32
32
|
html_tree_change_tag_name_by_css('td[bgcolor="#D0CECE"]', "th")
|
33
|
+
html_tree_change_tag_name_by_css('td[bgcolor="#d0cece"]', "th")
|
34
|
+
html_tree_change_tag_name_by_css('.framedata, .frame_container_box', 'aside')
|
35
|
+
html_tree_change_tag_name_by_css('.frame2data', 'pre')
|
36
|
+
# Assumption that all code snippets in those documents are XML...
|
37
|
+
html_tree_change_properties_by_css(".frame2data", class: "brush:xml;")
|
33
38
|
|
34
39
|
# Remove some CSS ids that are not important to us
|
35
40
|
html_tree_change_properties_by_css("#__nuxt", id: nil)
|
36
41
|
html_tree_change_properties_by_css("#__layout", id: nil)
|
37
42
|
html_tree_change_properties_by_css("#app", id: nil)
|
38
43
|
|
44
|
+
# Handle lists of document 02
|
45
|
+
html_tree_replace_with_children_by_css(".list_num-wrap")
|
46
|
+
|
39
47
|
# Convert table/img caption to become a caption
|
40
48
|
html_tree.css(".imagedata").each do |e|
|
41
49
|
table = e.parent.next&.children&.first
|
@@ -75,66 +83,82 @@ module Coradoc::ReverseAdoc
|
|
75
83
|
end
|
76
84
|
end
|
77
85
|
|
78
|
-
|
79
|
-
text
|
80
|
-
|
81
|
-
|
82
|
-
text = text.strip.gsub(/^/, "*** ")
|
83
|
-
"\n\n//-PT3D\n#{text}\n//-ENDPT3D\n\n"
|
84
|
-
end
|
85
|
-
|
86
|
-
html_tree_add_hook_pre_by_css ".text4data" do |node,|
|
87
|
-
text = html_tree_process_to_adoc(node).strip
|
88
|
-
next "" if text.empty? || text == "\u3000"
|
86
|
+
(3..4).each do |i|
|
87
|
+
html_tree_add_hook_pre_by_css ".text#{i}data" do |node,|
|
88
|
+
text = html_tree_process_to_adoc(node).strip
|
89
|
+
next "" if text.empty? || text == "\u3000"
|
89
90
|
|
90
|
-
|
91
|
-
|
91
|
+
text = text.strip.gsub(/^/, "#{'*' * i} ")
|
92
|
+
"\n\n//-PT#{i}D\n#{text}\n//-ENDPT#{i}D\n\n"
|
93
|
+
end
|
92
94
|
end
|
93
95
|
|
94
|
-
|
95
|
-
text
|
96
|
+
(2..3).each do |i|
|
97
|
+
html_tree_add_hook_pre_by_css ".text#{i}data_point ul" do |node,|
|
98
|
+
text = html_tree_process_to_adoc(node.children.first.children).strip
|
96
99
|
|
97
|
-
|
100
|
+
"#{'*' * i} #{text}\n"
|
101
|
+
end
|
98
102
|
end
|
99
103
|
|
100
|
-
|
101
|
-
|
104
|
+
(1..20).each do |i|
|
105
|
+
html_tree_add_hook_pre_by_css ".numtextdata_num .list_num#{i}" do |node,|
|
106
|
+
text = html_tree_process_to_adoc(node).strip
|
102
107
|
|
103
|
-
|
108
|
+
"[start=#{i}]\n. #{text}\n"
|
109
|
+
end
|
104
110
|
end
|
105
111
|
|
106
112
|
# html_tree_preview
|
107
113
|
end
|
108
114
|
|
115
|
+
IM = /[A-Z0-9]{1,3}/
|
116
|
+
|
109
117
|
def handle_headers(node, coradoc, state)
|
110
|
-
|
111
|
-
|
118
|
+
content = coradoc.content.map(&:content).join
|
119
|
+
|
120
|
+
if %w[toc0 toc_0].any? { |i| coradoc.id&.start_with?(i) }
|
112
121
|
# Special content
|
113
122
|
case content.strip
|
114
123
|
when "はじめに" # Introduction
|
115
124
|
coradoc.style = "abstract" # The older version document has ".preface"
|
125
|
+
coradoc.level_int = 1
|
116
126
|
when "改定の概要" # Revision overview
|
117
127
|
coradoc.style = "abstract" # The older version document has ".preface"
|
128
|
+
coradoc.level_int = 1
|
118
129
|
when "参考文献" # Bibliography
|
119
130
|
coradoc.style = "bibliography"
|
131
|
+
coradoc.level_int = 1
|
120
132
|
when "改訂履歴" # Document history
|
121
133
|
coradoc.style = "appendix"
|
134
|
+
coradoc.level_int = 1
|
135
|
+
when "0 概要" # Overview
|
136
|
+
coradoc.style = "abstract" # I'm not sure this is correct
|
137
|
+
coradoc.level_int = 1
|
138
|
+
when "索引" # Index
|
139
|
+
coradoc.style = "index" # I'm not sure this is correct
|
140
|
+
coradoc.level_int = 1
|
122
141
|
else
|
123
|
-
warn "Unknown section #{
|
142
|
+
warn "Unknown section #{content.inspect}"
|
124
143
|
end
|
144
|
+
end
|
125
145
|
|
126
|
-
|
127
|
-
|
146
|
+
if node.name == "h1"
|
147
|
+
if content.start_with?("Annex")
|
148
|
+
coradoc.style = "appendix"
|
149
|
+
coradoc.content.first.content.sub!(/\AAnnex [A-Z]/, "")
|
150
|
+
end
|
128
151
|
end
|
129
152
|
|
130
153
|
# Remove numbers
|
131
|
-
coradoc.content.first.content.sub!(/\A[
|
154
|
+
coradoc.content.first.content.sub!(/\A(#{IM}\.)*#{IM}[[:space:]]/, "")
|
132
155
|
|
133
156
|
coradoc
|
134
157
|
end
|
135
158
|
|
136
159
|
def handle_headers_h4(node, coradoc, state)
|
137
|
-
|
160
|
+
title = Coradoc.strip_unicode(coradoc.content.first.content)
|
161
|
+
case title
|
138
162
|
when /\A\(\d+\)(.*)/
|
139
163
|
coradoc.level_int = 4
|
140
164
|
coradoc.content.first.content = $1.strip
|
@@ -143,8 +167,16 @@ module Coradoc::ReverseAdoc
|
|
143
167
|
coradoc.level_int = 5
|
144
168
|
coradoc.content.first.content = $1.strip
|
145
169
|
coradoc
|
170
|
+
when /\A#{IM}\.#{IM}\.#{IM}\.#{IM}(.*)/
|
171
|
+
coradoc.level_int = 4
|
172
|
+
coradoc.content.first.content = $1.strip
|
146
173
|
else
|
147
|
-
|
174
|
+
if title.empty?
|
175
|
+
# Strip instances of faulty empty paragraphs
|
176
|
+
nil
|
177
|
+
else
|
178
|
+
["// FIXME\n", coradoc]
|
179
|
+
end
|
148
180
|
end
|
149
181
|
end
|
150
182
|
|
@@ -171,4 +203,4 @@ module Coradoc::ReverseAdoc
|
|
171
203
|
end
|
172
204
|
end
|
173
205
|
|
174
|
-
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
|
|
@@ -82,13 +82,18 @@ module Coradoc::ReverseAdoc
|
|
82
82
|
previous_sections = {}
|
83
83
|
|
84
84
|
determine_section_id = ->(elem) do
|
85
|
-
|
86
|
-
|
85
|
+
if elem.title.style == "appendix"
|
86
|
+
level = "A"
|
87
|
+
else
|
88
|
+
level = 1
|
89
|
+
end
|
90
|
+
|
91
|
+
section = previous_sections[elem]
|
87
92
|
while section
|
88
|
-
level
|
93
|
+
level = level.succ if elem.title.style == section.title.style
|
89
94
|
section = previous_sections[section]
|
90
95
|
end
|
91
|
-
level
|
96
|
+
level.is_a?(Integer) ? "%02d" % level : level
|
92
97
|
end
|
93
98
|
|
94
99
|
determine_style = ->(elem) do
|
@@ -106,7 +111,7 @@ module Coradoc::ReverseAdoc
|
|
106
111
|
# we can compute numbers
|
107
112
|
previous_sections[elem] = parent_sections[title.level_int]
|
108
113
|
parent_sections[title.level_int] = elem
|
109
|
-
parent_sections[(title.level_int+1)..nil] = nil
|
114
|
+
parent_sections[(title.level_int + 1)..nil] = nil
|
110
115
|
|
111
116
|
elem
|
112
117
|
else
|
@@ -114,8 +119,7 @@ module Coradoc::ReverseAdoc
|
|
114
119
|
# include tag.
|
115
120
|
section_file = "sections/"
|
116
121
|
section_file += parent_sections[1..title.level_int].map do |parent|
|
117
|
-
|
118
|
-
"%s%02d" % [style, determine_section_id.(parent)]
|
122
|
+
determine_style.(parent) + determine_section_id.(parent)
|
119
123
|
end.join("/")
|
120
124
|
section_file += ".adoc"
|
121
125
|
|
@@ -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
|
@@ -1,13 +1,43 @@
|
|
1
|
+
require_relative "admonition"
|
2
|
+
require_relative "attribute_list"
|
3
|
+
require_relative "bibliography"
|
4
|
+
require_relative "block"
|
5
|
+
require_relative "citation"
|
6
|
+
require_relative "content"
|
7
|
+
require_relative "document_attributes"
|
8
|
+
require_relative "header"
|
9
|
+
require_relative "inline"
|
10
|
+
require_relative "list"
|
11
|
+
require_relative "paragraph"
|
12
|
+
require_relative "section"
|
13
|
+
require_relative "table"
|
14
|
+
require_relative "term"
|
15
|
+
|
1
16
|
module Coradoc
|
2
17
|
module Parser
|
3
18
|
module Asciidoc
|
4
19
|
module Base
|
20
|
+
include Coradoc::Parser::Asciidoc::Admonition
|
21
|
+
include Coradoc::Parser::Asciidoc::AttributeList
|
22
|
+
include Coradoc::Parser::Asciidoc::Bibliography
|
23
|
+
include Coradoc::Parser::Asciidoc::Block
|
24
|
+
include Coradoc::Parser::Asciidoc::Citation
|
25
|
+
include Coradoc::Parser::Asciidoc::Content
|
26
|
+
include Coradoc::Parser::Asciidoc::DocumentAttributes
|
27
|
+
include Coradoc::Parser::Asciidoc::Header
|
28
|
+
include Coradoc::Parser::Asciidoc::Inline
|
29
|
+
include Coradoc::Parser::Asciidoc::List
|
30
|
+
include Coradoc::Parser::Asciidoc::Paragraph
|
31
|
+
include Coradoc::Parser::Asciidoc::Section
|
32
|
+
include Coradoc::Parser::Asciidoc::Table
|
33
|
+
include Coradoc::Parser::Asciidoc::Term
|
34
|
+
|
5
35
|
def space?
|
6
36
|
space.maybe
|
7
37
|
end
|
8
38
|
|
9
39
|
def space
|
10
|
-
|
40
|
+
str(' ').repeat(1)
|
11
41
|
end
|
12
42
|
|
13
43
|
def text
|
@@ -15,7 +45,7 @@ module Coradoc
|
|
15
45
|
end
|
16
46
|
|
17
47
|
def line_ending
|
18
|
-
|
48
|
+
str("\n")
|
19
49
|
end
|
20
50
|
|
21
51
|
def endline
|
@@ -23,11 +53,15 @@ module Coradoc
|
|
23
53
|
end
|
24
54
|
|
25
55
|
def newline
|
26
|
-
|
56
|
+
(str("\n") | str("\r\n")).repeat(1)
|
57
|
+
end
|
58
|
+
|
59
|
+
def newline_single
|
60
|
+
(str("\n") | str("\r\n"))
|
27
61
|
end
|
28
62
|
|
29
63
|
def keyword
|
30
|
-
(match(
|
64
|
+
(match('[a-zA-Z0-9_\-.,]') | str(".")).repeat(1)
|
31
65
|
end
|
32
66
|
|
33
67
|
def empty_line
|
@@ -62,22 +96,76 @@ module Coradoc
|
|
62
96
|
word >> str("@") >> word >> str(".") >> word
|
63
97
|
end
|
64
98
|
|
65
|
-
def attribute_name
|
66
|
-
match("[a-zA-Z0-9_-]").repeat(1)
|
67
|
-
end
|
68
|
-
|
69
|
-
def attribute_value
|
70
|
-
text | str("")
|
71
|
-
end
|
72
|
-
|
73
99
|
def special_character
|
74
|
-
match("^[
|
100
|
+
match("^[*:=-]") | str("[#") | str("[[")
|
75
101
|
end
|
76
102
|
|
77
103
|
def date
|
78
104
|
digit.repeat(2, 4) >> str("-") >>
|
79
105
|
digit.repeat(1, 2) >> str("-") >> digit.repeat(1, 2)
|
80
106
|
end
|
107
|
+
|
108
|
+
def attr_name
|
109
|
+
match("[^\t\s]").repeat(1)
|
110
|
+
end
|
111
|
+
|
112
|
+
def file_path
|
113
|
+
match('[^\[]').repeat(1)
|
114
|
+
end
|
115
|
+
|
116
|
+
def include_directive
|
117
|
+
(str("include::") >>
|
118
|
+
file_path.as(:path) >>
|
119
|
+
attribute_list >>
|
120
|
+
(newline | str("")).as(:line_break)
|
121
|
+
).as(:include)
|
122
|
+
end
|
123
|
+
|
124
|
+
def inline_image
|
125
|
+
(str("image::") >>
|
126
|
+
file_path.as(:path) >>
|
127
|
+
attribute_list >>
|
128
|
+
(line_ending)
|
129
|
+
).as(:inline_image)
|
130
|
+
end
|
131
|
+
|
132
|
+
def block_image
|
133
|
+
(block_id.maybe >>
|
134
|
+
block_title.maybe >>
|
135
|
+
(attribute_list >> newline).maybe >>
|
136
|
+
match('^i') >> str("mage::") >>
|
137
|
+
file_path.as(:path) >>
|
138
|
+
attribute_list(:attribute_list_macro) >>
|
139
|
+
newline.as(:line_break)
|
140
|
+
).as(:block_image)
|
141
|
+
end
|
142
|
+
|
143
|
+
def comment_line
|
144
|
+
tag.absent? >>
|
145
|
+
(str('//') >> str("/").absent? >>
|
146
|
+
space? >>
|
147
|
+
text.as(:comment_text)
|
148
|
+
).as(:comment_line)
|
149
|
+
end
|
150
|
+
|
151
|
+
def tag
|
152
|
+
(str('//') >> str('/').absent? >>
|
153
|
+
space? >>
|
154
|
+
(str('tag') | str('end')).as(:prefix) >>
|
155
|
+
str('::') >> str(':').absent? >>
|
156
|
+
match('[^\[]').repeat(1).as(:name) >>
|
157
|
+
attribute_list >>
|
158
|
+
line_ending.maybe.as(:line_break)
|
159
|
+
).as(:tag)
|
160
|
+
end
|
161
|
+
|
162
|
+
def comment_block
|
163
|
+
( str('////') >> line_ending >>
|
164
|
+
((line_ending >> str('////')).absent? >> any
|
165
|
+
).repeat.as(:comment_text) >>
|
166
|
+
line_ending >> str('////')
|
167
|
+
).as(:comment_block)
|
168
|
+
end
|
81
169
|
end
|
82
170
|
end
|
83
171
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Parser
|
3
|
+
module Asciidoc
|
4
|
+
module Bibliography
|
5
|
+
|
6
|
+
def bibliography
|
7
|
+
(section_id.maybe >>
|
8
|
+
str("[bibliography]\n") >>
|
9
|
+
str("== ") >> match("[^\n]").repeat(1).as(:title) >> str("\n") >>
|
10
|
+
bib_entry.repeat(1).as(:entries)
|
11
|
+
).as(:bibliography)
|
12
|
+
end
|
13
|
+
|
14
|
+
def bib_entry
|
15
|
+
(match("^*") >> str(' [[[') >>
|
16
|
+
match('[^,\[\]\n]').repeat(1).as(:anchor_name) >>
|
17
|
+
( str(",") >>
|
18
|
+
match('[^\]\n]').repeat(1).as(:document_id)
|
19
|
+
).maybe >>
|
20
|
+
str("]]]") >>
|
21
|
+
(text_line.repeat(0,1) >>
|
22
|
+
text_line.repeat(0)
|
23
|
+
).as(:ref_text).maybe >>
|
24
|
+
line_ending.repeat(1).as(:line_break).maybe
|
25
|
+
).as(:bibliography_entry)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|