coradoc 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +35 -0
  3. data/{.docker/readme.md → README.Docker.adoc} +21 -25
  4. data/README.adoc +121 -0
  5. data/coradoc.gemspec +4 -0
  6. data/docker-compose.yml +14 -0
  7. data/exe/coradoc +5 -0
  8. data/exe/reverse_adoc +24 -34
  9. data/exe/w2a +16 -28
  10. data/lib/coradoc/cli.rb +105 -0
  11. data/lib/coradoc/converter.rb +145 -0
  12. data/lib/coradoc/document.rb +13 -0
  13. data/lib/coradoc/element/admonition.rb +5 -0
  14. data/lib/coradoc/element/attribute_list.rb +1 -1
  15. data/lib/coradoc/element/author.rb +4 -4
  16. data/lib/coradoc/element/bibliography.rb +24 -0
  17. data/lib/coradoc/element/bibliography_entry.rb +24 -0
  18. data/lib/coradoc/element/block/core.rb +6 -4
  19. data/lib/coradoc/element/block/example.rb +1 -0
  20. data/lib/coradoc/element/block/pass.rb +21 -0
  21. data/lib/coradoc/element/block/quote.rb +1 -1
  22. data/lib/coradoc/element/block/reviewer_comment.rb +19 -0
  23. data/lib/coradoc/element/block/side.rb +4 -2
  24. data/lib/coradoc/element/block/sourcecode.rb +1 -0
  25. data/lib/coradoc/element/block.rb +2 -0
  26. data/lib/coradoc/element/comment_block.rb +22 -0
  27. data/lib/coradoc/element/comment_line.rb +18 -0
  28. data/lib/coradoc/element/document_attributes.rb +8 -1
  29. data/lib/coradoc/element/header.rb +1 -1
  30. data/lib/coradoc/element/image/block_image.rb +8 -0
  31. data/lib/coradoc/element/image/core.rb +7 -4
  32. data/lib/coradoc/element/include.rb +18 -0
  33. data/lib/coradoc/element/inline/citation.rb +24 -0
  34. data/lib/coradoc/element/inline/cross_reference.rb +29 -8
  35. data/lib/coradoc/element/inline.rb +1 -0
  36. data/lib/coradoc/element/list/core.rb +16 -3
  37. data/lib/coradoc/element/list/definition.rb +3 -1
  38. data/lib/coradoc/element/list_item.rb +15 -5
  39. data/lib/coradoc/element/paragraph.rb +8 -5
  40. data/lib/coradoc/element/revision.rb +1 -1
  41. data/lib/coradoc/element/section.rb +11 -3
  42. data/lib/coradoc/element/table.rb +6 -1
  43. data/lib/coradoc/element/tag.rb +19 -0
  44. data/lib/coradoc/element/term.rb +21 -0
  45. data/lib/coradoc/element/text_element.rb +9 -1
  46. data/lib/coradoc/element/title.rb +2 -2
  47. data/lib/coradoc/generator.rb +2 -0
  48. data/lib/coradoc/input/adoc.rb +28 -0
  49. data/lib/coradoc/input/docx.rb +35 -0
  50. data/lib/coradoc/{reverse_adoc → input/html}/README.adoc +9 -9
  51. data/lib/coradoc/{reverse_adoc → input/html}/cleaner.rb +19 -6
  52. data/lib/coradoc/input/html/config.rb +75 -0
  53. data/lib/coradoc/{reverse_adoc → input/html}/converters/a.rb +1 -1
  54. data/lib/coradoc/{reverse_adoc → input/html}/converters/aside.rb +1 -1
  55. data/lib/coradoc/{reverse_adoc → input/html}/converters/audio.rb +1 -1
  56. data/lib/coradoc/{reverse_adoc → input/html}/converters/base.rb +1 -1
  57. data/lib/coradoc/{reverse_adoc → input/html}/converters/blockquote.rb +2 -2
  58. data/lib/coradoc/{reverse_adoc → input/html}/converters/br.rb +1 -1
  59. data/lib/coradoc/{reverse_adoc → input/html}/converters/bypass.rb +1 -1
  60. data/lib/coradoc/{reverse_adoc → input/html}/converters/code.rb +1 -1
  61. data/lib/coradoc/{reverse_adoc → input/html}/converters/div.rb +1 -1
  62. data/lib/coradoc/{reverse_adoc → input/html}/converters/dl.rb +1 -1
  63. data/lib/coradoc/{reverse_adoc → input/html}/converters/drop.rb +1 -1
  64. data/lib/coradoc/{reverse_adoc → input/html}/converters/em.rb +1 -1
  65. data/lib/coradoc/{reverse_adoc → input/html}/converters/figure.rb +1 -1
  66. data/lib/coradoc/{reverse_adoc → input/html}/converters/h.rb +1 -1
  67. data/lib/coradoc/{reverse_adoc → input/html}/converters/head.rb +1 -1
  68. data/lib/coradoc/{reverse_adoc → input/html}/converters/hr.rb +1 -1
  69. data/lib/coradoc/{reverse_adoc → input/html}/converters/ignore.rb +1 -1
  70. data/lib/coradoc/{reverse_adoc → input/html}/converters/img.rb +17 -10
  71. data/lib/coradoc/{reverse_adoc → input/html}/converters/li.rb +1 -1
  72. data/lib/coradoc/{reverse_adoc → input/html}/converters/mark.rb +1 -1
  73. data/lib/coradoc/{reverse_adoc → input/html}/converters/markup.rb +1 -1
  74. data/lib/coradoc/{reverse_adoc → input/html}/converters/math.rb +3 -3
  75. data/lib/coradoc/{reverse_adoc → input/html}/converters/ol.rb +1 -1
  76. data/lib/coradoc/{reverse_adoc → input/html}/converters/p.rb +1 -1
  77. data/lib/coradoc/{reverse_adoc → input/html}/converters/pass_through.rb +1 -1
  78. data/lib/coradoc/{reverse_adoc → input/html}/converters/pre.rb +1 -1
  79. data/lib/coradoc/{reverse_adoc → input/html}/converters/q.rb +1 -1
  80. data/lib/coradoc/{reverse_adoc → input/html}/converters/strong.rb +1 -1
  81. data/lib/coradoc/{reverse_adoc → input/html}/converters/sub.rb +1 -1
  82. data/lib/coradoc/{reverse_adoc → input/html}/converters/sup.rb +1 -1
  83. data/lib/coradoc/{reverse_adoc → input/html}/converters/table.rb +36 -11
  84. data/lib/coradoc/{reverse_adoc → input/html}/converters/td.rb +1 -1
  85. data/lib/coradoc/{reverse_adoc → input/html}/converters/text.rb +2 -2
  86. data/lib/coradoc/{reverse_adoc → input/html}/converters/th.rb +1 -1
  87. data/lib/coradoc/{reverse_adoc → input/html}/converters/tr.rb +1 -1
  88. data/lib/coradoc/{reverse_adoc → input/html}/converters/video.rb +1 -1
  89. data/lib/coradoc/input/html/converters.rb +57 -0
  90. data/lib/coradoc/input/html/errors.rb +12 -0
  91. data/lib/coradoc/{reverse_adoc → input/html}/html_converter.rb +37 -22
  92. data/lib/coradoc/{reverse_adoc → input/html}/plugin.rb +6 -6
  93. data/lib/coradoc/{reverse_adoc → input/html}/plugins/plateau.rb +62 -30
  94. data/lib/coradoc/{reverse_adoc → input/html}/postprocessor.rb +13 -9
  95. data/lib/coradoc/input/html.rb +59 -0
  96. data/lib/coradoc/input.rb +12 -0
  97. data/lib/coradoc/output/adoc.rb +17 -0
  98. data/lib/coradoc/output/coradoc_tree_debug.rb +19 -0
  99. data/lib/coradoc/output.rb +11 -0
  100. data/lib/coradoc/parser/asciidoc/admonition.rb +24 -0
  101. data/lib/coradoc/parser/asciidoc/attribute_list.rb +67 -0
  102. data/lib/coradoc/parser/asciidoc/base.rb +101 -13
  103. data/lib/coradoc/parser/asciidoc/bibliography.rb +30 -0
  104. data/lib/coradoc/parser/asciidoc/block.rb +82 -0
  105. data/lib/coradoc/parser/asciidoc/citation.rb +48 -0
  106. data/lib/coradoc/parser/asciidoc/content.rb +15 -120
  107. data/lib/coradoc/parser/asciidoc/document_attributes.rb +12 -5
  108. data/lib/coradoc/parser/asciidoc/header.rb +1 -4
  109. data/lib/coradoc/parser/asciidoc/inline.rb +72 -0
  110. data/lib/coradoc/parser/asciidoc/list.rb +81 -0
  111. data/lib/coradoc/parser/asciidoc/paragraph.rb +33 -0
  112. data/lib/coradoc/parser/asciidoc/section.rb +36 -31
  113. data/lib/coradoc/parser/asciidoc/table.rb +32 -0
  114. data/lib/coradoc/parser/asciidoc/term.rb +23 -0
  115. data/lib/coradoc/parser/base.rb +39 -4
  116. data/lib/coradoc/transformer.rb +353 -82
  117. data/lib/coradoc/util.rb +10 -0
  118. data/lib/coradoc/version.rb +1 -1
  119. data/lib/coradoc.rb +8 -4
  120. data/lib/reverse_adoc.rb +6 -6
  121. data/utils/parser_analyzer.rb +66 -0
  122. data/utils/round_trip.rb +37 -0
  123. metadata +113 -54
  124. data/.docker/Makefile +0 -35
  125. data/.docker/docker-compose.yml +0 -14
  126. data/Makefile +0 -1
  127. data/README.md +0 -73
  128. data/docker-compose.yml +0 -1
  129. data/lib/coradoc/reverse_adoc/config.rb +0 -73
  130. data/lib/coradoc/reverse_adoc/converters.rb +0 -53
  131. data/lib/coradoc/reverse_adoc/errors.rb +0 -10
  132. data/lib/coradoc/reverse_adoc.rb +0 -30
  133. /data/{.docker/Dockerfile → Dockerfile} +0 -0
  134. /data/lib/coradoc/{reverse_adoc → input/html}/LICENSE.txt +0 -0
@@ -1,22 +1,55 @@
1
1
  require "parslet"
2
2
  require "parslet/convenience"
3
3
 
4
- require_relative "asciidoc/header"
4
+ require_relative "asciidoc/attribute_list"
5
+ require_relative "asciidoc/base"
6
+ require_relative "asciidoc/block"
7
+ require_relative "asciidoc/citation"
8
+ require_relative "asciidoc/content"
5
9
  require_relative "asciidoc/document_attributes"
10
+ require_relative "asciidoc/header"
11
+ require_relative "asciidoc/inline"
12
+ require_relative "asciidoc/list"
13
+ require_relative "asciidoc/paragraph"
6
14
  require_relative "asciidoc/section"
15
+ require_relative "asciidoc/table"
16
+ require_relative "asciidoc/term"
7
17
 
8
18
  module Coradoc
9
19
  module Parser
10
20
  class Base < Parslet::Parser
11
- include Coradoc::Parser::Asciidoc::Header
21
+ include Coradoc::Parser::Asciidoc::AttributeList
22
+ include Coradoc::Parser::Asciidoc::Base
23
+ include Coradoc::Parser::Asciidoc::Block
24
+ include Coradoc::Parser::Asciidoc::Citation
25
+ include Coradoc::Parser::Asciidoc::Content
12
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
13
31
  include Coradoc::Parser::Asciidoc::Section
32
+ include Coradoc::Parser::Asciidoc::Table
33
+ include Coradoc::Parser::Asciidoc::Term
14
34
 
15
35
  root :document
16
36
  rule(:document) do
17
37
  (
18
- document_attributess.as(:document_attributes) |
38
+ admonition_line |
39
+ bib_entry |
40
+ block_image |
41
+ term | term2 |
42
+ citation |
43
+ tag |
44
+ comment_block |
45
+ comment_line |
46
+ block.as(:block) |
19
47
  section.as(:section) |
48
+ include_directive |
49
+ document_attributes |
50
+ list |
51
+ table.as(:table) |
52
+ paragraph |
20
53
  header.as(:header) |
21
54
  empty_line.as(:line_break) |
22
55
  any.as(:unparsed)
@@ -25,7 +58,9 @@ module Coradoc
25
58
 
26
59
  def self.parse(filename)
27
60
  content = File.read(filename)
28
- new.parse_with_debug(content)
61
+ new.parse(content)
62
+ rescue Parslet::ParseFailed => e
63
+ puts e.parse_failure_cause.ascii_tree
29
64
  end
30
65
  end
31
66
  end
@@ -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)) { Element::TextElement.new(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(text: simple(:text), break: simple(:line_break)) do
37
- Element::TextElement.new(text, line_break: line_break)
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(id: simple(:id), text: simple(:text), break: simple(:line_break)) do
41
- Element::TextElement.new(text, id: id, line_break: line_break)
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: simple(:paragraph)) { paragraph }
46
- rule(lines: sequence(:lines)) { Element::Paragraph.new(lines) }
47
- rule(meta: simple(:meta), lines: sequence(:lines)) do
48
- Element::Paragraph.new(lines, meta: meta)
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
- break: simple(:line_break),
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
- break: simple(:line_break),
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
- # rule(title: simple(:title)) { Element::Section.new(title) }
71
- #
72
- # rule(id: simple(:id), title: simple(:title), content:)
73
- rule(
74
- id: simple(:id),
75
- title: simple(:title),
76
- sections: sequence(:sections),
77
- ) do
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
- rule(
82
- id: simple(:id),
83
- title: simple(:title),
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
- contents: sequence(:contents),
95
- sections: sequence(:sections),
96
- ) do
97
- Element::Section.new(title, id: id, contents: contents,
98
- sections: sections)
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(example: sequence(:example)) do
102
- Element::Core.new("", type: "example", lines: example)
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
- # rule(title: simple(:title), paragraphs: sequence(:paragraphs)) do
106
- # Element::Section.new(title, paragraphs: paragraphs)
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
- break: simple(:line_break)) do
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)) { Element::LineBreak.new(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
- rule(table: simple(:table)) { table }
161
- rule(cols: sequence(:cols)) { Element::Table::Row.new(cols) }
162
- rule(title: simple(:title), rows: sequence(:rows)) do
163
- Element::Table.new(title, rows)
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
@@ -0,0 +1,10 @@
1
+ module Coradoc
2
+ def self.strip_unicode(str)
3
+ str.gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
4
+ end
5
+
6
+ def self.a_single?(obj, klass)
7
+ obj.is_a?(klass) ||
8
+ (obj.is_a?(Array) && obj.length == 1 && obj.first.is_a?(klass))
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Coradoc
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.1"
5
5
  end
data/lib/coradoc.rb CHANGED
@@ -3,10 +3,14 @@
3
3
  require "pathname"
4
4
 
5
5
  require "parslet"
6
- require_relative "coradoc/version"
7
- require_relative "coradoc/parser"
8
- require_relative "coradoc/transformer"
9
- require_relative "coradoc/generator"
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"
10
14
 
11
15
  module Coradoc
12
16
  class Error < StandardError; end
data/lib/reverse_adoc.rb CHANGED
@@ -1,9 +1,9 @@
1
- warn <<~END
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/reverse_adoc'
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::ReverseAdoc.
16
- END
15
+ | with Coradoc::Input::HTML.
16
+ WARN
17
17
 
18
- require "coradoc/reverse_adoc"
18
+ require "coradoc/input/html"
19
19
 
20
- ReverseAdoc = Coradoc::ReverseAdoc
20
+ ReverseAdoc = Coradoc::Input::HTML