coradoc 1.1.0 → 1.1.2
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 +7 -7
- 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 +8 -6
- 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/reverse_adoc.rb +16 -28
- 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 -53
- 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/{.docker/Dockerfile → Dockerfile} +0 -0
- /data/lib/coradoc/{reverse_adoc → input/html}/LICENSE.txt +0 -0
@@ -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
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Parser
|
3
|
+
module Asciidoc
|
4
|
+
module Block
|
5
|
+
|
6
|
+
def block
|
7
|
+
sidebar_block |
|
8
|
+
example_block |
|
9
|
+
source_block |
|
10
|
+
quote_block |
|
11
|
+
pass_block
|
12
|
+
end
|
13
|
+
|
14
|
+
def source_block
|
15
|
+
block_style("-", 2)
|
16
|
+
end
|
17
|
+
|
18
|
+
def pass_block
|
19
|
+
block_style("+", 4, :pass)
|
20
|
+
end
|
21
|
+
|
22
|
+
def source_block
|
23
|
+
block_style("-", 2)
|
24
|
+
end
|
25
|
+
|
26
|
+
def quote_block
|
27
|
+
block_style("_")
|
28
|
+
end
|
29
|
+
|
30
|
+
def block_content(n_deep = 2)
|
31
|
+
c = block_image |
|
32
|
+
list |
|
33
|
+
text_line |
|
34
|
+
empty_line.as(:line_break)
|
35
|
+
c = c | block_content(n_deep - 1) if (n_deep > 0)
|
36
|
+
c.repeat(1)
|
37
|
+
end
|
38
|
+
|
39
|
+
def sidebar_block
|
40
|
+
block_style("*")
|
41
|
+
end
|
42
|
+
|
43
|
+
def example_block
|
44
|
+
block_style("=")
|
45
|
+
end
|
46
|
+
|
47
|
+
def block_title
|
48
|
+
match('^\\.') >> space.absent? >> text.as(:title) >> newline
|
49
|
+
end
|
50
|
+
|
51
|
+
def block_type(type)
|
52
|
+
(match('^\[') >> str("[").absent? >>
|
53
|
+
str(type).as(:type) >>
|
54
|
+
str("]")) |
|
55
|
+
(match('^\[') >> keyword.as(:type) >> str("]")) >> newline
|
56
|
+
end
|
57
|
+
|
58
|
+
def block_id
|
59
|
+
(match('^\[') >> str("[") >> str('[').absent? >> keyword.as(:id) >> str("]]") |
|
60
|
+
str("[#") >> keyword.as(:id) >> str("]")) >> newline
|
61
|
+
end
|
62
|
+
|
63
|
+
def block_style(delimiter = "*", repeater = 4, type = nil)
|
64
|
+
block_id.maybe >>
|
65
|
+
block_title.maybe >>
|
66
|
+
newline.maybe >>
|
67
|
+
(attribute_list >> newline ).maybe >>
|
68
|
+
block_id.maybe >>
|
69
|
+
(attribute_list >> newline ).maybe >>
|
70
|
+
str(delimiter).repeat(repeater).as(:delimiter) >> newline >>
|
71
|
+
if type == :pass
|
72
|
+
(text_line | empty_line.as(:line_break)).repeat(1).as(:lines)
|
73
|
+
else
|
74
|
+
block_content.as(:lines)
|
75
|
+
end >>
|
76
|
+
str(delimiter).repeat(repeater) >> newline
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Parser
|
3
|
+
module Asciidoc
|
4
|
+
module Citation
|
5
|
+
def xref_anchor
|
6
|
+
match('[^,>]').repeat(1).as(:href_arg).repeat(1,1)
|
7
|
+
end
|
8
|
+
|
9
|
+
def xref_str
|
10
|
+
match('[^,>]').repeat(1).as(:text)
|
11
|
+
end
|
12
|
+
|
13
|
+
def xref_arg
|
14
|
+
(str('section') | str('paragraph') | str('clause') | str('annex') | str('table')).as(:key) >>
|
15
|
+
match('[ =]').as(:delimiter) >>
|
16
|
+
match('[^,>=]').repeat(1).as(:value)
|
17
|
+
end
|
18
|
+
|
19
|
+
def cross_reference
|
20
|
+
str('<<') >> xref_anchor >>
|
21
|
+
( (str(',') >> xref_arg).repeat(1) |
|
22
|
+
(str(',') >> xref_str).repeat(1)
|
23
|
+
).maybe >>
|
24
|
+
str('>>')
|
25
|
+
end
|
26
|
+
|
27
|
+
def citation_xref
|
28
|
+
cross_reference.as(:cross_reference) >> newline |
|
29
|
+
cross_reference.as(:cross_reference) >>
|
30
|
+
(text_line.repeat(1)
|
31
|
+
).as(:comment).maybe
|
32
|
+
end
|
33
|
+
|
34
|
+
def citation_noxref
|
35
|
+
(text_line.repeat(1)
|
36
|
+
).as(:comment)
|
37
|
+
end
|
38
|
+
|
39
|
+
def citation
|
40
|
+
match('^[\[]') >> str(".source]\n") >>
|
41
|
+
( citation_xref |
|
42
|
+
citation_noxref
|
43
|
+
).as(:citation)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -2,66 +2,6 @@ module Coradoc
|
|
2
2
|
module Parser
|
3
3
|
module Asciidoc
|
4
4
|
module Content
|
5
|
-
include Coradoc::Parser::Asciidoc::Base
|
6
|
-
|
7
|
-
def paragraph
|
8
|
-
paragraph_meta.as(:meta).maybe >>
|
9
|
-
text_line.repeat(1).as(:lines)
|
10
|
-
end
|
11
|
-
|
12
|
-
def glossaries
|
13
|
-
glossary.repeat(1)
|
14
|
-
end
|
15
|
-
|
16
|
-
# List
|
17
|
-
def list
|
18
|
-
unordered_list.as(:unordered) |
|
19
|
-
definition_list.as(:definition) | ordered_list.as(:ordered)
|
20
|
-
end
|
21
|
-
|
22
|
-
def contents
|
23
|
-
(
|
24
|
-
block.as(:block) |
|
25
|
-
list.as(:list) |
|
26
|
-
table.as(:table) |
|
27
|
-
highlight.as(:highlight) |
|
28
|
-
glossaries.as(:glossaries) |
|
29
|
-
paragraph.as(:paragraph) | empty_line
|
30
|
-
).repeat(1)
|
31
|
-
end
|
32
|
-
|
33
|
-
def block
|
34
|
-
sidebar_block | example_block | source_block | quote_block
|
35
|
-
end
|
36
|
-
|
37
|
-
def source_block
|
38
|
-
block_style("-", 2)
|
39
|
-
end
|
40
|
-
|
41
|
-
def quote_block
|
42
|
-
block_style("_")
|
43
|
-
end
|
44
|
-
|
45
|
-
def sidebar_block
|
46
|
-
block_style("*")
|
47
|
-
end
|
48
|
-
|
49
|
-
def example_block
|
50
|
-
block_style("=")
|
51
|
-
end
|
52
|
-
|
53
|
-
def block_style(delimiter = "*", repeater = 4)
|
54
|
-
block_title.maybe >>
|
55
|
-
newline.maybe >>
|
56
|
-
block_type.maybe >>
|
57
|
-
str(delimiter).repeat(repeater).as(:delimiter) >> newline >>
|
58
|
-
text_line.repeat(1).as(:lines) >>
|
59
|
-
str(delimiter).repeat(repeater) >> newline
|
60
|
-
end
|
61
|
-
|
62
|
-
def block_type
|
63
|
-
str("[") >> keyword.as(:type) >> str("]") >> newline
|
64
|
-
end
|
65
5
|
|
66
6
|
def highlight
|
67
7
|
text_id >> newline >>
|
@@ -76,27 +16,6 @@ module Coradoc
|
|
76
16
|
str("#") >> words.as(:text) >> str("#")
|
77
17
|
end
|
78
18
|
|
79
|
-
# Table
|
80
|
-
def table
|
81
|
-
block_title >>
|
82
|
-
str("|===") >> line_ending >>
|
83
|
-
table_row.repeat(1).as(:rows) >>
|
84
|
-
str("|===") >> line_ending
|
85
|
-
end
|
86
|
-
|
87
|
-
def table_row
|
88
|
-
(literal_space? >> str("|") >> (cell_content | empty_cell_content))
|
89
|
-
.repeat(1).as(:cols) >> line_ending
|
90
|
-
end
|
91
|
-
|
92
|
-
def empty_cell_content
|
93
|
-
str("|").absent? >> literal_space.as(:text)
|
94
|
-
end
|
95
|
-
|
96
|
-
def cell_content
|
97
|
-
str("|").absent? >> literal_space? >> rich_texts.as(:text)
|
98
|
-
end
|
99
|
-
|
100
19
|
def literal_space
|
101
20
|
(match[" "] | match[' \t']).repeat(1)
|
102
21
|
end
|
@@ -106,63 +25,39 @@ module Coradoc
|
|
106
25
|
literal_space.maybe
|
107
26
|
end
|
108
27
|
|
109
|
-
def block_title
|
110
|
-
str(".") >> text.as(:title) >> line_ending
|
111
|
-
end
|
112
|
-
|
113
28
|
# Text
|
114
|
-
def text_line
|
115
|
-
|
116
|
-
text.as(:text)
|
29
|
+
def text_line(many_breaks = false)
|
30
|
+
tl = (asciidoc_char_with_id.absent? | text_id) >> literal_space? >>
|
31
|
+
text.as(:text)
|
32
|
+
if many_breaks
|
33
|
+
tl >> line_ending.repeat(1).as(:line_break)
|
34
|
+
else
|
35
|
+
tl >> line_ending.as(:line_break)
|
36
|
+
end
|
117
37
|
end
|
118
38
|
|
119
39
|
def asciidoc_char
|
120
|
-
match(
|
40
|
+
match('^[*_:=\-+]')
|
121
41
|
end
|
122
42
|
|
123
43
|
def asciidoc_char_with_id
|
124
|
-
asciidoc_char | str(
|
44
|
+
asciidoc_char | str('[#') | str('[[')
|
125
45
|
end
|
126
46
|
|
127
47
|
def text_id
|
128
|
-
str("[[") >> keyword.as(:id) >> str("]]") |
|
48
|
+
str("[[") >> str('[').absent? >> keyword.as(:id) >> str("]]") |
|
129
49
|
str("[#") >> keyword.as(:id) >> str("]")
|
130
50
|
end
|
131
51
|
|
132
|
-
def paragraph_meta
|
133
|
-
str("[") >>
|
134
|
-
keyword.as(:key) >> str("=") >>
|
135
|
-
word.as(:value) >> str("]") >> newline
|
136
|
-
end
|
137
|
-
|
138
52
|
def glossary
|
139
|
-
keyword.as(:key) >> str("::") >>
|
140
|
-
text.as(:value) >> line_ending.as(:
|
53
|
+
keyword.as(:key) >> str("::") >> (str(" ") | newline) >>
|
54
|
+
text.as(:value) >> line_ending.as(:line_break)
|
141
55
|
end
|
142
56
|
|
143
|
-
def
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
def unordered_list
|
148
|
-
(ulist_item >> newline.maybe).repeat(1)
|
149
|
-
end
|
150
|
-
|
151
|
-
def definition_list
|
152
|
-
dlist_item.repeat(1)
|
153
|
-
end
|
154
|
-
|
155
|
-
def olist_item
|
156
|
-
match("\.") >> space >> text_line
|
157
|
-
end
|
158
|
-
|
159
|
-
def ulist_item
|
160
|
-
match("\\*") >> space >> text_line
|
57
|
+
def glossaries
|
58
|
+
glossary.repeat(1)
|
161
59
|
end
|
162
60
|
|
163
|
-
def dlist_item
|
164
|
-
str("term") >> space >> digits >> str("::") >> space >> text_line
|
165
|
-
end
|
166
61
|
end
|
167
62
|
end
|
168
63
|
end
|
@@ -2,16 +2,23 @@ module Coradoc
|
|
2
2
|
module Parser
|
3
3
|
module Asciidoc
|
4
4
|
module DocumentAttributes
|
5
|
-
include Coradoc::Parser::Asciidoc::Base
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def attribute_name
|
7
|
+
match("[a-zA-Z0-9_-]").repeat(1)
|
8
|
+
end
|
9
|
+
|
10
|
+
def attribute_value
|
11
|
+
text | str("") >> str("\n").absent?
|
10
12
|
end
|
11
13
|
|
12
14
|
def document_attributes
|
15
|
+
(document_attribute.repeat(1)
|
16
|
+
).as(:document_attributes)
|
17
|
+
end
|
18
|
+
|
19
|
+
def document_attribute
|
13
20
|
str(":") >> attribute_name.as(:key) >> str(":") >>
|
14
|
-
space? >> attribute_value.as(:value) >> line_ending
|
21
|
+
space? >> (attribute_value | str("")).as(:value) >> line_ending
|
15
22
|
end
|
16
23
|
end
|
17
24
|
end
|
@@ -1,10 +1,7 @@
|
|
1
|
-
require_relative "base"
|
2
|
-
|
3
1
|
module Coradoc
|
4
2
|
module Parser
|
5
3
|
module Asciidoc
|
6
4
|
module Header
|
7
|
-
include Coradoc::Parser::Asciidoc::Base
|
8
5
|
|
9
6
|
def header
|
10
7
|
header_title >>
|
@@ -13,7 +10,7 @@ module Coradoc
|
|
13
10
|
end
|
14
11
|
|
15
12
|
def header_title
|
16
|
-
match("
|
13
|
+
match("^=") >> str('=').absent? >> space? >> text.as(:title) >> newline
|
17
14
|
end
|
18
15
|
|
19
16
|
def author
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Parser
|
3
|
+
module Asciidoc
|
4
|
+
module Inline
|
5
|
+
|
6
|
+
def bold_constrained
|
7
|
+
(str('*') >>
|
8
|
+
match("[^*]").repeat(1).as(:text).repeat(1,1) >>
|
9
|
+
str('*') >> str('*').absent?
|
10
|
+
).as(:bold_constrained)
|
11
|
+
end
|
12
|
+
|
13
|
+
def bold_unconstrained
|
14
|
+
(str('**') >>
|
15
|
+
match("[^*\n]").repeat(1).as(:text).repeat(1,1) >>
|
16
|
+
str('**')
|
17
|
+
).as(:bold_unconstrained)
|
18
|
+
end
|
19
|
+
|
20
|
+
def highlight_constrained
|
21
|
+
(str('#') >>
|
22
|
+
match('[^#]').repeat(1).as(:text).repeat(1,1) >>
|
23
|
+
str('#') >> str('#').absent?
|
24
|
+
).as(:highlight_constrained)
|
25
|
+
end
|
26
|
+
|
27
|
+
def highlight_unconstrained
|
28
|
+
(str('##') >>
|
29
|
+
match('[^#]').repeat(1).as(:text).repeat(1,1) >>
|
30
|
+
str('##')
|
31
|
+
).as(:highlight_unconstrained)
|
32
|
+
end
|
33
|
+
|
34
|
+
def italic_constrained
|
35
|
+
(str('_') >>
|
36
|
+
match('[^_]').repeat(1).as(:text).repeat(1,1) >>
|
37
|
+
str('_') >> str('_').absent?
|
38
|
+
).as(:italic_constrained)
|
39
|
+
end
|
40
|
+
|
41
|
+
def italic_unconstrained
|
42
|
+
(str('__') >>
|
43
|
+
match('[^_]').repeat(1).as(:text).repeat(1,1) >>
|
44
|
+
str('__')
|
45
|
+
).as(:italic_unconstrained)
|
46
|
+
end
|
47
|
+
|
48
|
+
def text_unformatted
|
49
|
+
(admonition_line.absent? >>
|
50
|
+
(cross_reference.absent? |
|
51
|
+
bold_unconstrained.absent? |
|
52
|
+
bold_constrained.absent? |
|
53
|
+
highlight_unconstrained.absent? |
|
54
|
+
highlight_constrained.absent? |
|
55
|
+
italic_unconstrained.absent? |
|
56
|
+
italic_constrained.absent?) >>
|
57
|
+
match('[^\n]').repeat(1)
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
def text_formatted
|
62
|
+
((cross_reference |
|
63
|
+
bold_unconstrained | bold_constrained |
|
64
|
+
highlight_unconstrained | highlight_constrained |
|
65
|
+
italic_unconstrained | italic_constrained )|
|
66
|
+
text_unformatted).repeat(1)
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|