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
data/lib/coradoc/transformer.rb
CHANGED
@@ -27,147 +27,413 @@ module Coradoc
|
|
27
27
|
Element::Revision.new(number, date: date, remark: remark)
|
28
28
|
end
|
29
29
|
|
30
|
+
# Comments
|
31
|
+
rule(comment_line: {comment_text: simple(:comment_text)}) {
|
32
|
+
Element::Comment::Line.new(comment_text)
|
33
|
+
}
|
34
|
+
|
35
|
+
rule(comment_block: {comment_text: simple(:comment_text)}) {
|
36
|
+
Element::Comment::Block.new(comment_text)
|
37
|
+
}
|
38
|
+
|
39
|
+
rule(tag: subtree(:tag)) {
|
40
|
+
opts = {}
|
41
|
+
opts[:prefix] = tag[:prefix]
|
42
|
+
opts[:attribute_list] = tag[:attribute_list]
|
43
|
+
opts[:line_break] = tag[:line_break]
|
44
|
+
Element::Tag.new(tag[:name], opts)
|
45
|
+
}
|
46
|
+
|
47
|
+
# AttributeList
|
48
|
+
class NamedAttribute < Struct.new(:key, :value); end
|
49
|
+
|
50
|
+
rule(:named => {named_key: simple(:key),
|
51
|
+
named_value: simple(:value)} ) {
|
52
|
+
NamedAttribute.new(key.to_s, value.to_s)
|
53
|
+
}
|
54
|
+
|
55
|
+
rule(positional: simple(:positional)){
|
56
|
+
positional.to_s
|
57
|
+
}
|
58
|
+
|
59
|
+
rule(attribute_array: nil){
|
60
|
+
Element::AttributeList.new
|
61
|
+
}
|
62
|
+
|
63
|
+
rule(attribute_array: sequence(:attributes)){
|
64
|
+
attr_list = Element::AttributeList.new
|
65
|
+
attributes.each do |a|
|
66
|
+
if a.is_a?(String)
|
67
|
+
attr_list.add_positional(a)
|
68
|
+
elsif a.is_a?(NamedAttribute)
|
69
|
+
attr_list.add_named(a[:key], a[:value])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
attr_list
|
73
|
+
}
|
74
|
+
|
75
|
+
# Include
|
76
|
+
rule(include: {
|
77
|
+
path: simple(:path),
|
78
|
+
attribute_list: simple(:attribute_list),
|
79
|
+
line_break: simple(:line_break)}
|
80
|
+
) {
|
81
|
+
Element::Include.new(
|
82
|
+
path.to_s,
|
83
|
+
attributes: attribute_list,
|
84
|
+
line_break: line_break)
|
85
|
+
}
|
86
|
+
|
87
|
+
|
30
88
|
# Text Element
|
31
|
-
rule(text: simple(:text)) {
|
89
|
+
rule(text: simple(:text)) {
|
90
|
+
Element::TextElement.new(text.to_s)
|
91
|
+
}
|
92
|
+
|
93
|
+
rule(text: simple(:text), line_break: simple(:line_break)) {
|
94
|
+
Element::TextElement.new(text.to_s, line_break: line_break)
|
95
|
+
}
|
96
|
+
|
32
97
|
rule(id: simple(:id), text: simple(:text)) do
|
33
|
-
Element::TextElement.new(text, id: id)
|
98
|
+
Element::TextElement.new(text.to_s, id: id.to_s)
|
99
|
+
end
|
100
|
+
|
101
|
+
rule(text: sequence(:text)) {
|
102
|
+
Element::TextElement.new(text)
|
103
|
+
}
|
104
|
+
|
105
|
+
rule(
|
106
|
+
text: simple(:text),
|
107
|
+
line_break: simple(:line_break)
|
108
|
+
) do
|
109
|
+
Element::TextElement.new(
|
110
|
+
text.to_s,
|
111
|
+
line_break: line_break)
|
112
|
+
end
|
113
|
+
|
114
|
+
rule(
|
115
|
+
id: simple(:id),
|
116
|
+
text: simple(:text),
|
117
|
+
line_break: simple(:line_break)
|
118
|
+
) do
|
119
|
+
Element::TextElement.new(
|
120
|
+
text.to_s,
|
121
|
+
id: id,
|
122
|
+
line_break: line_break)
|
34
123
|
end
|
35
124
|
|
36
|
-
rule(
|
37
|
-
|
125
|
+
rule(
|
126
|
+
id: simple(:id),
|
127
|
+
text: sequence(:text),
|
128
|
+
line_break: simple(:line_break)
|
129
|
+
) do
|
130
|
+
Element::TextElement.new(
|
131
|
+
text,
|
132
|
+
id: id,
|
133
|
+
line_break: line_break)
|
38
134
|
end
|
39
135
|
|
40
|
-
rule(
|
41
|
-
|
136
|
+
rule(text: sequence(:text),
|
137
|
+
line_break: simple(:line_break)
|
138
|
+
) do
|
139
|
+
Element::TextElement.new(
|
140
|
+
text,
|
141
|
+
line_break: line_break)
|
42
142
|
end
|
43
143
|
|
144
|
+
rule(href: simple(:href)){
|
145
|
+
Element::Inline::CrossReference.new(
|
146
|
+
href.to_s
|
147
|
+
)
|
148
|
+
}
|
149
|
+
|
150
|
+
rule(href: simple(:href),
|
151
|
+
name: simple(:name)
|
152
|
+
){
|
153
|
+
Element::Inline::CrossReference.new(
|
154
|
+
href.to_s,
|
155
|
+
name.to_s
|
156
|
+
)
|
157
|
+
}
|
158
|
+
|
159
|
+
rule(bold_constrained: {
|
160
|
+
content: simple(:text)
|
161
|
+
}){
|
162
|
+
Element::Inline::Bold.new(text, unconstrained: false)
|
163
|
+
}
|
164
|
+
|
165
|
+
rule(bold_unconstrained: {content: simple(:text)}) {
|
166
|
+
Element::Inline::Bold.new(text, unconstrained: true)
|
167
|
+
}
|
168
|
+
|
169
|
+
rule(highlight_constrained: {content: simple(:text)}) {
|
170
|
+
Element::Inline::Highlight.new(text, unconstrained: false)
|
171
|
+
}
|
172
|
+
rule(highlight_unconstrained: {content: simple(:text)}) {
|
173
|
+
Element::Inline::Highlight.new(text, unconstrained: true)
|
174
|
+
}
|
175
|
+
|
176
|
+
rule(italic_constrained: {content: simple(:text)}) {
|
177
|
+
Element::Inline::Italic.new(text, unconstrained: false)
|
178
|
+
}
|
179
|
+
rule(italic_unconstrained: {content: simple(:text)}) {
|
180
|
+
Element::Inline::Italic.new(text, unconstrained: true)
|
181
|
+
}
|
182
|
+
|
183
|
+
|
44
184
|
# Paragraph
|
45
|
-
rule(paragraph:
|
46
|
-
|
47
|
-
|
48
|
-
|
185
|
+
rule(paragraph: subtree(:paragraph)) do
|
186
|
+
Element::Paragraph.new(
|
187
|
+
paragraph[:lines],
|
188
|
+
id: paragraph[:id],
|
189
|
+
attributes: paragraph[:attribute_list],
|
190
|
+
title: paragraph[:title]
|
191
|
+
)
|
49
192
|
end
|
50
193
|
|
194
|
+
|
195
|
+
|
51
196
|
# Title Element
|
52
197
|
rule(
|
53
198
|
level: simple(:level),
|
54
199
|
text: simple(:text),
|
55
|
-
|
200
|
+
line_break: simple(:line_break),
|
56
201
|
) do
|
57
|
-
Element::Title.new(text, level, line_break: line_break)
|
202
|
+
Element::Title.new(text, level.size - 1, line_break: line_break)
|
58
203
|
end
|
59
204
|
|
60
205
|
rule(
|
61
206
|
name: simple(:name),
|
62
207
|
level: simple(:level),
|
63
208
|
text: simple(:text),
|
64
|
-
|
209
|
+
line_break: simple(:line_break),
|
65
210
|
) do
|
66
|
-
Element::Title.new(text, level, line_break: line_break, id: name)
|
211
|
+
Element::Title.new(text, level.size - 1, line_break: line_break, id: name)
|
67
212
|
end
|
68
213
|
|
69
214
|
# Section
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
sections:
|
77
|
-
|
78
|
-
Element::Section.new(title, id: id, sections: sections)
|
215
|
+
rule(section: subtree(:section)) do
|
216
|
+
id = section[:id] || nil
|
217
|
+
title = section[:title] || nil
|
218
|
+
attribute_list = section[:attribute_list] || nil
|
219
|
+
contents = section[:contents] || []
|
220
|
+
sections = section[:sections]
|
221
|
+
opts = {id:,attribute_list:,contents:,sections: }
|
222
|
+
Element::Section.new(title, opts)
|
79
223
|
end
|
80
224
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
contents: sequence(:contents),
|
85
|
-
sections: simple(:sections),
|
86
|
-
) do
|
87
|
-
Element::Section.new(title, id: id, contents: contents,
|
88
|
-
sections: sections)
|
225
|
+
|
226
|
+
rule(example: sequence(:example)) do
|
227
|
+
Element::Core.new("", type: "example", lines: example)
|
89
228
|
end
|
90
229
|
|
230
|
+
rule(bibliography_entry: subtree(:bib_entry) ){
|
231
|
+
Element::BibliographyEntry.new(bib_entry)
|
232
|
+
}
|
233
|
+
|
91
234
|
rule(
|
92
235
|
id: simple(:id),
|
93
236
|
title: simple(:title),
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
237
|
+
entries: sequence(:entries)
|
238
|
+
){
|
239
|
+
Element::Bibliography.new(
|
240
|
+
id: id,
|
241
|
+
title: title,
|
242
|
+
entries: entries
|
243
|
+
)
|
244
|
+
}
|
245
|
+
|
246
|
+
rule(
|
247
|
+
key: simple(:key),
|
248
|
+
delimiter: simple(:delimiter),
|
249
|
+
value: simple(:value)
|
250
|
+
){
|
251
|
+
Element::Inline::CrossReferenceArg.new(key, delimiter, value)
|
252
|
+
}
|
253
|
+
|
254
|
+
rule(href_arg: simple(:href_arg)){
|
255
|
+
href_arg.to_s
|
256
|
+
}
|
257
|
+
|
258
|
+
rule(citation: subtree(:citation)){
|
259
|
+
xref = citation[:cross_reference]
|
260
|
+
xref = Element::Inline::CrossReference.new(xref[0], xref[1..-1]) if xref
|
261
|
+
comment = citation[:comment]
|
262
|
+
opts = {}
|
263
|
+
opts[:cross_reference] = xref if xref
|
264
|
+
opts[:comment] = comment if comment
|
265
|
+
Element::Inline::Citation.new(opts)
|
266
|
+
}
|
267
|
+
|
268
|
+
rule(term_type: simple(:term_type),
|
269
|
+
term: simple(:term),
|
270
|
+
line_break: simple(:line_break)){
|
271
|
+
Coradoc::Element::Term.new(term, type: term_type, line_break: line_break, lang: :en)
|
272
|
+
}
|
273
|
+
|
274
|
+
rule(term_type: simple(:term_type),
|
275
|
+
term2: simple(:term2),
|
276
|
+
line_break: simple(:line_break)){
|
277
|
+
Coradoc::Element::Term.new(term2, type: term_type, line_break: line_break, lang: :fr)
|
278
|
+
}
|
279
|
+
|
280
|
+
|
281
|
+
rule(block: subtree(:block)
|
282
|
+
) {
|
283
|
+
|
284
|
+
id = block[:id]
|
285
|
+
title = block[:title]
|
286
|
+
attribute_list = block[:attribute_list]
|
287
|
+
delimiter = block[:delimiter].to_s
|
288
|
+
delimiter_c = delimiter[0]
|
289
|
+
lines = block[:lines]
|
290
|
+
ordering = block.keys.select{|k|
|
291
|
+
[:id, :title, :attribute_list, :attribute_list2].include?(k)}
|
292
|
+
|
293
|
+
opts = {id: id,
|
294
|
+
title: title,
|
295
|
+
delimiter_len: delimiter.size,
|
296
|
+
lines: lines,
|
297
|
+
ordering: ordering}
|
298
|
+
opts[:attributes] = attribute_list if attribute_list
|
299
|
+
if delimiter_c == "*"
|
300
|
+
if attribute_list
|
301
|
+
if (attribute_list.positional == [] &&
|
302
|
+
attribute_list.named.keys[0] == "reviewer")
|
303
|
+
Element::Block::ReviewerComment.new(
|
304
|
+
opts
|
305
|
+
)
|
306
|
+
elsif (attribute_list.positional[0] == "sidebar" &&
|
307
|
+
attribute_list.named == {})
|
308
|
+
Element::Block::Side.new(
|
309
|
+
opts
|
310
|
+
)
|
311
|
+
end
|
312
|
+
else
|
313
|
+
end
|
314
|
+
elsif delimiter_c == "="
|
315
|
+
Element::Block::Example.new(title, opts)
|
316
|
+
elsif delimiter_c == "+"
|
317
|
+
Element::Block::Pass.new(opts)
|
318
|
+
elsif delimiter_c == "-"
|
319
|
+
if (attribute_list.positional[0] == "quote")
|
320
|
+
Element::Block::Quote.new(title, opts)
|
321
|
+
end
|
322
|
+
elsif delimiter_c == "_"
|
323
|
+
Element::Block::Quote.new(title, opts)
|
324
|
+
end
|
325
|
+
}
|
326
|
+
|
327
|
+
# Admonition
|
328
|
+
rule(admonition_type: simple(:admonition_type),
|
329
|
+
content: sequence(:content),
|
330
|
+
) do
|
331
|
+
Element::Admonition.new(content, admonition_type.to_s)
|
99
332
|
end
|
100
333
|
|
101
|
-
rule(
|
102
|
-
|
334
|
+
rule(block_image: subtree(:block_image)) do
|
335
|
+
id = block_image[:id]
|
336
|
+
title = block_image[:title]
|
337
|
+
path = block_image[:path]
|
338
|
+
opts = {
|
339
|
+
attributes: block_image[:attribute_list_macro],
|
340
|
+
line_break: block_image[:line_break]
|
341
|
+
}
|
342
|
+
Element::Image::BlockImage.new(title, id, path, opts)
|
103
343
|
end
|
104
344
|
|
105
|
-
|
106
|
-
|
107
|
-
# end
|
108
|
-
#
|
109
|
-
# rule(title: simple(:title), blocks: sequence(:blocks)) do
|
110
|
-
# Element::Section.new(title, blocks: blocks)
|
111
|
-
# end
|
112
|
-
#
|
113
|
-
# # Admonition
|
114
|
-
# rule(admonition: simple(:admonition)) { admonition }
|
115
|
-
# rule(type: simple(:type), text: simple(:text), break: simple(:line_break)) do
|
116
|
-
# Element::Admonition.new(text, type.to_s, line_break: line_break)
|
117
|
-
# end
|
118
|
-
#
|
119
|
-
# # Block
|
120
|
-
# rule(title: simple(:title), lines: sequence(:lines)) do
|
121
|
-
# Element::Block.new(title, lines: lines)
|
122
|
-
# end
|
123
|
-
#
|
124
|
-
# rule(
|
125
|
-
# title: simple(:title),
|
126
|
-
# delimiter: simple(:delimiter),
|
127
|
-
# lines: sequence(:lines)) do
|
128
|
-
# Element::Block.new(title, lines: lines, delimiter: delimiter)
|
129
|
-
# end
|
130
|
-
#
|
131
|
-
# rule(
|
132
|
-
# type: simple(:type),
|
133
|
-
# title: simple(:title),
|
134
|
-
# delimiter: simple(:delimiter),
|
135
|
-
# lines: sequence(:lines)) do
|
136
|
-
# Element::Block.new(title, lines: lines, delimiter: delimiter, type: type)
|
137
|
-
# end
|
138
|
-
#
|
139
|
-
# rule(attributes: simple(:attributes), lines: sequence(:lines)) do
|
140
|
-
# Element::Block.new(nil, lines: lines, attributes: attributes)
|
141
|
-
# end
|
142
|
-
#
|
345
|
+
|
346
|
+
|
143
347
|
# Attribute
|
144
348
|
rule(key: simple(:key), value: simple(:value)) do
|
145
349
|
Element::Attribute.new(key, value)
|
146
350
|
end
|
147
351
|
|
148
352
|
rule(key: simple(:key), value: simple(:value),
|
149
|
-
|
353
|
+
line_break: simple(:line_break)) do
|
150
354
|
Element::Attribute.new(key, value, line_break: line_break)
|
151
355
|
end
|
152
356
|
|
153
|
-
rule(line_break: simple(:line_break)) {
|
357
|
+
rule(line_break: simple(:line_break)) {
|
358
|
+
Element::LineBreak.new(line_break)
|
359
|
+
}
|
154
360
|
|
155
361
|
rule(document_attributes: sequence(:document_attributes)) do
|
156
362
|
Element::DocumentAttributes.new(document_attributes)
|
157
363
|
end
|
158
364
|
|
159
365
|
# Table
|
160
|
-
|
161
|
-
rule(cols: sequence(:cols)) {
|
162
|
-
|
163
|
-
Element::Table.new(
|
366
|
+
|
367
|
+
rule(cols: sequence(:cols)) {
|
368
|
+
cells = cols.map{|c| Element::Table::Cell.new(content: c)}
|
369
|
+
Element::Table::Row.new(cells)
|
370
|
+
}
|
371
|
+
|
372
|
+
rule(table: subtree(:table)) do
|
373
|
+
title = table[:title] || nil
|
374
|
+
rows = table[:rows] || []
|
375
|
+
opts = {
|
376
|
+
id: table[:id] || nil,
|
377
|
+
attributes: table[:attribute_list] || nil
|
378
|
+
}
|
379
|
+
Element::Table.new(title, rows, opts)
|
164
380
|
end
|
165
381
|
|
382
|
+
rule(list_item: simple(:list_item),
|
383
|
+
marker: simple(:marker),
|
384
|
+
text: simple(:text),
|
385
|
+
line_break: simple(:line_break)) do
|
386
|
+
Element::ListItem.new(
|
387
|
+
text,
|
388
|
+
marker: marker.to_s,
|
389
|
+
line_break: line_break
|
390
|
+
)
|
391
|
+
end
|
392
|
+
|
393
|
+
rule(list_item: simple(:list_item),
|
394
|
+
marker: simple(:marker),
|
395
|
+
id: simple(:id),
|
396
|
+
text: simple(:text),
|
397
|
+
line_break: simple(:line_break)) do
|
398
|
+
Element::ListItem.new(
|
399
|
+
text,
|
400
|
+
id: id,
|
401
|
+
marker: marker.to_s,
|
402
|
+
line_break: line_break
|
403
|
+
)
|
404
|
+
end
|
405
|
+
|
406
|
+
|
166
407
|
# List
|
167
408
|
rule(list: simple(:list)) { list }
|
168
409
|
rule(unordered: sequence(:list_items)) do
|
169
410
|
Element::List::Unordered.new(list_items)
|
170
411
|
end
|
412
|
+
rule(attribute_list: simple(:attribute_list),
|
413
|
+
unordered: sequence(:list_items)
|
414
|
+
) do
|
415
|
+
Element::List::Unordered.new(list_items, attrs: attribute_list)
|
416
|
+
end
|
417
|
+
|
418
|
+
rule(ordered: sequence(:list_items)) do
|
419
|
+
Element::List::Ordered.new(list_items)
|
420
|
+
end
|
421
|
+
|
422
|
+
rule(attribute_list: simple(:attribute_list),
|
423
|
+
ordered: sequence(:list_items)
|
424
|
+
) do
|
425
|
+
Element::List::Ordered.new(list_items, attrs: attribute_list)
|
426
|
+
end
|
427
|
+
|
428
|
+
|
429
|
+
rule(terms: simple(:terms), definition: simple(:definition)) do
|
430
|
+
Element::ListItemDefinition.new(terms, contents)
|
431
|
+
end
|
432
|
+
|
433
|
+
rule(definition_list: sequence(:definition_list)) do
|
434
|
+
Element::List::Definition.new(list_items)
|
435
|
+
end
|
436
|
+
|
171
437
|
|
172
438
|
# Highlight
|
173
439
|
rule(highlight: simple(:text)) { Element::Highlight.new(text) }
|
@@ -184,6 +450,11 @@ module Coradoc
|
|
184
450
|
Document.from_ast(elements)
|
185
451
|
end
|
186
452
|
|
453
|
+
|
454
|
+
# rule(unparsed: simple(:text)) do
|
455
|
+
# text.to_s
|
456
|
+
# end
|
457
|
+
|
187
458
|
def self.transform(syntax_tree)
|
188
459
|
new.apply(syntax_tree)
|
189
460
|
end
|
data/lib/coradoc/util.rb
CHANGED
data/lib/coradoc/version.rb
CHANGED
data/lib/coradoc.rb
CHANGED
@@ -3,11 +3,14 @@
|
|
3
3
|
require "pathname"
|
4
4
|
|
5
5
|
require "parslet"
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
require "coradoc/version"
|
7
|
+
require "coradoc/util"
|
8
|
+
require "coradoc/parser"
|
9
|
+
require "coradoc/transformer"
|
10
|
+
require "coradoc/generator"
|
11
|
+
require "coradoc/converter"
|
12
|
+
require "coradoc/input"
|
13
|
+
require "coradoc/output"
|
11
14
|
|
12
15
|
module Coradoc
|
13
16
|
class Error < StandardError; end
|
data/lib/reverse_adoc.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
warn <<~
|
1
|
+
warn <<~WARN
|
2
2
|
Deprecated: reverse_adoc has been merged into coradoc gem.
|
3
3
|
| Please update your references from:
|
4
4
|
| require 'reverse_adoc'
|
5
5
|
| To:
|
6
|
-
| require 'coradoc/
|
6
|
+
| require 'coradoc/input/html'
|
7
7
|
|
|
8
8
|
| You are referencing an old require here:
|
9
9
|
| #{caller.join("\n| ")}
|
@@ -12,9 +12,9 @@ warn <<~END
|
|
12
12
|
| reverse_adoc 2.0.0 will be kept with 'coradoc' as the only dependency.
|
13
13
|
|
|
14
14
|
| Please also ensure that you replace all references to ReverseAdoc in your code
|
15
|
-
| with Coradoc::
|
16
|
-
|
15
|
+
| with Coradoc::Input::HTML.
|
16
|
+
WARN
|
17
17
|
|
18
|
-
require "coradoc/
|
18
|
+
require "coradoc/input/html"
|
19
19
|
|
20
|
-
ReverseAdoc = Coradoc::
|
20
|
+
ReverseAdoc = Coradoc::Input::HTML
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "rubocop"
|
2
|
+
|
3
|
+
def ast_from(string)
|
4
|
+
RuboCop::ProcessedSource.new(string, RUBY_VERSION.to_f).ast
|
5
|
+
end
|
6
|
+
|
7
|
+
def is_def?(arr)
|
8
|
+
if Array === arr
|
9
|
+
if arr[0] == :def
|
10
|
+
$defs << arr
|
11
|
+
else
|
12
|
+
arr.each do |e|
|
13
|
+
is_def?(e)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
path = "lib/coradoc/parser/asciidoc/"
|
20
|
+
class_files = Dir.entries(path).select{|x| File.file?(path+x)}
|
21
|
+
|
22
|
+
$all_defs = {}
|
23
|
+
|
24
|
+
class_files.each do |cf|
|
25
|
+
a = ast_from(File.open(path+cf).read)
|
26
|
+
next if a.nil?
|
27
|
+
sexp = a.to_sexp_array
|
28
|
+
$defs = []
|
29
|
+
is_def?(sexp)
|
30
|
+
$all_defs[cf] = $defs
|
31
|
+
end;
|
32
|
+
|
33
|
+
relevant_names = $all_defs.map{|fn, defs| defs.map{|d| d[1]}}.flatten;
|
34
|
+
|
35
|
+
require 'graphviz'
|
36
|
+
|
37
|
+
g = GraphViz.new( :G, :type => :digraph );
|
38
|
+
|
39
|
+
g[:fontsize] = 8
|
40
|
+
g[:rankdir] = "LR"
|
41
|
+
g[:overlap] = false
|
42
|
+
g[:splines] = false
|
43
|
+
|
44
|
+
nodes = {}
|
45
|
+
|
46
|
+
$all_defs.each do |file_name, defs|
|
47
|
+
|
48
|
+
defs.each do |ast_def|
|
49
|
+
calls = ast_def[2..-1].flatten & relevant_names
|
50
|
+
node_name = ast_def[1]
|
51
|
+
nodes[node_name] = g.add_nodes( "#{node_name}\n#{file_name}" )
|
52
|
+
end
|
53
|
+
end;
|
54
|
+
|
55
|
+
$all_defs.each do |file_name, defs|
|
56
|
+
defs.each do |ast_def|
|
57
|
+
calls = ast_def[2..-1].flatten & relevant_names
|
58
|
+
node_name = ast_def[1]
|
59
|
+
calls.each do |cl|
|
60
|
+
w = g.add_edges(nodes[node_name], nodes[cl])
|
61
|
+
w[:weight] = 1.5
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end;
|
65
|
+
|
66
|
+
g.output( :png => "utils/parser_graph.png_#{Time.now.to_i}" );
|
data/utils/round_trip.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
$LOAD_PATH.unshift("../coradoc/lib")
|
2
|
+
|
3
|
+
require "coradoc"
|
4
|
+
require "coradoc/input/html"
|
5
|
+
|
6
|
+
|
7
|
+
rice_path = "../mn-samples-iso/sources/international-standard/rice-2023/"
|
8
|
+
|
9
|
+
if !Dir.exist?(rice_path)
|
10
|
+
puts "pleas set path to rice-2023"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
adoc_files = Dir.glob("#{rice_path}**/*adoc")
|
15
|
+
|
16
|
+
adoc_files.each do |file_path|
|
17
|
+
puts file_path
|
18
|
+
file_path_rt = "#{file_path}.roundtrip"
|
19
|
+
file_path_diff = "#{file_path}.roundtrip.diff"
|
20
|
+
FileUtils.rm(file_path_rt) if File.exist?(file_path_rt)
|
21
|
+
FileUtils.rm(file_path_diff) if File.exist?(file_path_diff)
|
22
|
+
# begin
|
23
|
+
adoc_file = File.open(file_path).read
|
24
|
+
next if adoc_file.size == 0
|
25
|
+
puts "parsing..."
|
26
|
+
ast = Coradoc::Parser::Base.new.parse(adoc_file)
|
27
|
+
puts "transforming..."
|
28
|
+
doc = Coradoc::Transformer.transform(ast[:document])
|
29
|
+
puts "generating..."
|
30
|
+
generated_adoc = Coradoc::Generator.gen_adoc(doc)
|
31
|
+
cleaned_adoc = Coradoc::Input::HTML.cleaner.tidy(generated_adoc)
|
32
|
+
File.open("#{file_path}.roundtrip","w"){|f| f.write(cleaned_adoc)}
|
33
|
+
`diff -B #{file_path} #{file_path}.roundtrip > #{file_path}.roundtrip.diff`
|
34
|
+
# rescue
|
35
|
+
# puts "unsuccessful..."
|
36
|
+
# end
|
37
|
+
end
|