coradoc 1.1.5 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +1 -0
  3. data/.irbrc +1 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +5 -1
  6. data/.rubocop_todo.yml +179 -0
  7. data/Gemfile +11 -0
  8. data/README.adoc +5 -7
  9. data/coradoc.gemspec +5 -16
  10. data/exe/reverse_adoc +1 -1
  11. data/exe/w2a +1 -1
  12. data/flake.lock +114 -0
  13. data/flake.nix +135 -0
  14. data/lib/coradoc/cli.rb +1 -1
  15. data/lib/coradoc/converter.rb +4 -5
  16. data/lib/coradoc/element/attribute.rb +10 -1
  17. data/lib/coradoc/element/attribute_list.rb +4 -3
  18. data/lib/coradoc/element/audio.rb +1 -1
  19. data/lib/coradoc/element/author.rb +2 -2
  20. data/lib/coradoc/element/base.rb +14 -2
  21. data/lib/coradoc/element/bibliography.rb +1 -1
  22. data/lib/coradoc/element/bibliography_entry.rb +1 -1
  23. data/lib/coradoc/element/block/open.rb +1 -1
  24. data/lib/coradoc/element/block.rb +1 -1
  25. data/lib/coradoc/element/document_attributes.rb +8 -2
  26. data/lib/coradoc/element/image/block_image.rb +3 -2
  27. data/lib/coradoc/element/image/core.rb +5 -4
  28. data/lib/coradoc/element/inline/attribute_reference.rb +19 -0
  29. data/lib/coradoc/element/inline/cross_reference.rb +4 -3
  30. data/lib/coradoc/element/inline/footnote.rb +24 -0
  31. data/lib/coradoc/element/inline/small.rb +19 -0
  32. data/lib/coradoc/element/inline/span.rb +37 -0
  33. data/lib/coradoc/element/inline/underline.rb +19 -0
  34. data/lib/coradoc/element/inline.rb +5 -1
  35. data/lib/coradoc/element/list/core.rb +2 -2
  36. data/lib/coradoc/element/list/ordered.rb +1 -0
  37. data/lib/coradoc/element/list/unordered.rb +1 -0
  38. data/lib/coradoc/element/list_item.rb +19 -20
  39. data/lib/coradoc/element/table.rb +4 -2
  40. data/lib/coradoc/element/term.rb +1 -0
  41. data/lib/coradoc/element/text_element.rb +4 -1
  42. data/lib/coradoc/element/title.rb +1 -1
  43. data/lib/coradoc/element/video.rb +2 -2
  44. data/lib/coradoc/input/adoc.rb +20 -18
  45. data/lib/coradoc/input/docx.rb +25 -23
  46. data/lib/coradoc/input/html/README.adoc +1 -1
  47. data/lib/coradoc/input/html/cleaner.rb +121 -117
  48. data/lib/coradoc/input/html/config.rb +58 -56
  49. data/lib/coradoc/input/html/converters/a.rb +44 -39
  50. data/lib/coradoc/input/html/converters/aside.rb +12 -8
  51. data/lib/coradoc/input/html/converters/audio.rb +24 -20
  52. data/lib/coradoc/input/html/converters/base.rb +103 -99
  53. data/lib/coradoc/input/html/converters/blockquote.rb +18 -14
  54. data/lib/coradoc/input/html/converters/br.rb +11 -7
  55. data/lib/coradoc/input/html/converters/bypass.rb +77 -73
  56. data/lib/coradoc/input/html/converters/code.rb +18 -14
  57. data/lib/coradoc/input/html/converters/div.rb +15 -11
  58. data/lib/coradoc/input/html/converters/dl.rb +51 -44
  59. data/lib/coradoc/input/html/converters/drop.rb +21 -17
  60. data/lib/coradoc/input/html/converters/em.rb +16 -12
  61. data/lib/coradoc/input/html/converters/figure.rb +19 -15
  62. data/lib/coradoc/input/html/converters/h.rb +32 -30
  63. data/lib/coradoc/input/html/converters/head.rb +17 -13
  64. data/lib/coradoc/input/html/converters/hr.rb +11 -7
  65. data/lib/coradoc/input/html/converters/ignore.rb +15 -11
  66. data/lib/coradoc/input/html/converters/img.rb +98 -93
  67. data/lib/coradoc/input/html/converters/li.rb +13 -9
  68. data/lib/coradoc/input/html/converters/mark.rb +14 -10
  69. data/lib/coradoc/input/html/converters/markup.rb +22 -18
  70. data/lib/coradoc/input/html/converters/math.rb +26 -19
  71. data/lib/coradoc/input/html/converters/ol.rb +55 -50
  72. data/lib/coradoc/input/html/converters/p.rb +16 -12
  73. data/lib/coradoc/input/html/converters/pass_through.rb +12 -8
  74. data/lib/coradoc/input/html/converters/pre.rb +49 -45
  75. data/lib/coradoc/input/html/converters/q.rb +12 -8
  76. data/lib/coradoc/input/html/converters/strong.rb +15 -11
  77. data/lib/coradoc/input/html/converters/sub.rb +15 -11
  78. data/lib/coradoc/input/html/converters/sup.rb +15 -11
  79. data/lib/coradoc/input/html/converters/table.rb +21 -13
  80. data/lib/coradoc/input/html/converters/td.rb +64 -60
  81. data/lib/coradoc/input/html/converters/text.rb +24 -20
  82. data/lib/coradoc/input/html/converters/th.rb +13 -9
  83. data/lib/coradoc/input/html/converters/tr.rb +17 -13
  84. data/lib/coradoc/input/html/converters/video.rb +24 -20
  85. data/lib/coradoc/input/html/converters.rb +45 -43
  86. data/lib/coradoc/input/html/errors.rb +8 -6
  87. data/lib/coradoc/input/html/html_converter.rb +93 -90
  88. data/lib/coradoc/input/html/plugin.rb +104 -104
  89. data/lib/coradoc/input/html/plugins/plateau.rb +197 -190
  90. data/lib/coradoc/input/html/postprocessor.rb +188 -182
  91. data/lib/coradoc/input/html.rb +34 -32
  92. data/lib/coradoc/oscal.rb +18 -5
  93. data/lib/coradoc/output/adoc.rb +13 -11
  94. data/lib/coradoc/output/coradoc_tree_debug.rb +15 -13
  95. data/lib/coradoc/parser/asciidoc/admonition.rb +6 -6
  96. data/lib/coradoc/parser/asciidoc/attribute_list.rb +43 -27
  97. data/lib/coradoc/parser/asciidoc/base.rb +3 -6
  98. data/lib/coradoc/parser/asciidoc/bibliography.rb +5 -6
  99. data/lib/coradoc/parser/asciidoc/block.rb +30 -31
  100. data/lib/coradoc/parser/asciidoc/citation.rb +11 -29
  101. data/lib/coradoc/parser/asciidoc/content.rb +23 -33
  102. data/lib/coradoc/parser/asciidoc/document_attributes.rb +2 -3
  103. data/lib/coradoc/parser/asciidoc/header.rb +1 -2
  104. data/lib/coradoc/parser/asciidoc/inline.rb +165 -42
  105. data/lib/coradoc/parser/asciidoc/list.rb +27 -27
  106. data/lib/coradoc/parser/asciidoc/paragraph.rb +28 -19
  107. data/lib/coradoc/parser/asciidoc/section.rb +11 -17
  108. data/lib/coradoc/parser/asciidoc/table.rb +5 -5
  109. data/lib/coradoc/parser/asciidoc/term.rb +24 -8
  110. data/lib/coradoc/parser/asciidoc/text.rb +18 -21
  111. data/lib/coradoc/parser/base.rb +0 -3
  112. data/lib/coradoc/reverse_adoc.rb +3 -3
  113. data/lib/coradoc/transformer.rb +167 -137
  114. data/lib/coradoc/version.rb +1 -1
  115. data/lib/reverse_adoc.rb +1 -1
  116. data/utils/inspect_asciidoc.rb +29 -0
  117. data/utils/parser_analyzer.rb +14 -14
  118. data/utils/round_trip.rb +31 -15
  119. metadata +34 -137
  120. data/.hound.yml +0 -5
  121. data/lib/coradoc/element/inline/citation.rb +0 -24
  122. data/todo.md +0 -10
@@ -7,15 +7,12 @@ require_relative "asciidoc/base"
7
7
  module Coradoc
8
8
  module Parser
9
9
  class Base < Coradoc::Parser::Asciidoc::Base
10
-
11
10
  root :document
12
11
  rule(:document) do
13
12
  (
14
13
  admonition_line |
15
14
  bib_entry |
16
15
  block_image |
17
- term | term2 |
18
- citation |
19
16
  tag |
20
17
  comment_block |
21
18
  comment_line |
@@ -12,7 +12,7 @@ warn <<~WARN
12
12
  | in your code with Coradoc::Input::HTML.
13
13
  WARN
14
14
 
15
- require 'coradoc'
16
- require 'coradoc/input/html'
15
+ require "coradoc"
16
+ require "coradoc/input/html"
17
17
 
18
- Coradoc::ReverseAdoc = Coradoc::Input::HTML
18
+ Coradoc::ReverseAdoc = Coradoc::Input::Html
@@ -28,39 +28,39 @@ module Coradoc
28
28
  end
29
29
 
30
30
  # Comments
31
- rule(comment_line: {comment_text: simple(:comment_text)}) {
31
+ rule(comment_line: { comment_text: simple(:comment_text) }) do
32
32
  Element::Comment::Line.new(comment_text)
33
- }
33
+ end
34
34
 
35
- rule(comment_block: {comment_text: simple(:comment_text)}) {
35
+ rule(comment_block: { comment_text: simple(:comment_text) }) do
36
36
  Element::Comment::Block.new(comment_text)
37
- }
37
+ end
38
38
 
39
- rule(tag: subtree(:tag)) {
39
+ rule(tag: subtree(:tag)) do
40
40
  opts = {}
41
41
  opts[:prefix] = tag[:prefix]
42
42
  opts[:attribute_list] = tag[:attribute_list]
43
43
  opts[:line_break] = tag[:line_break]
44
44
  Element::Tag.new(tag[:name], opts)
45
- }
45
+ end
46
46
 
47
47
  # AttributeList
48
- class NamedAttribute < Struct.new(:key, :value); end
48
+ NamedAttribute = Struct.new(:key, :value)
49
49
 
50
- rule(:named => {named_key: simple(:key),
51
- named_value: simple(:value)} ) {
50
+ rule(named: { named_key: simple(:key),
51
+ named_value: simple(:value) }) do
52
52
  NamedAttribute.new(key.to_s, value.to_s)
53
- }
53
+ end
54
54
 
55
- rule(positional: simple(:positional)){
55
+ rule(positional: simple(:positional)) do
56
56
  positional.to_s
57
- }
57
+ end
58
58
 
59
- rule(attribute_array: nil){
59
+ rule(attribute_array: nil) do
60
60
  Element::AttributeList.new
61
- }
61
+ end
62
62
 
63
- rule(attribute_array: sequence(:attributes)){
63
+ rule(attribute_array: sequence(:attributes)) do
64
64
  attr_list = Element::AttributeList.new
65
65
  attributes.each do |a|
66
66
  if a.is_a?(String)
@@ -70,114 +70,149 @@ module Coradoc
70
70
  end
71
71
  end
72
72
  attr_list
73
- }
73
+ end
74
74
 
75
75
  # Include
76
76
  rule(include: {
77
- path: simple(:path),
78
- attribute_list: simple(:attribute_list),
79
- line_break: simple(:line_break)}
80
- ) {
77
+ path: simple(:path),
78
+ attribute_list: simple(:attribute_list),
79
+ line_break: simple(:line_break),
80
+ }) do
81
81
  Element::Include.new(
82
82
  path.to_s,
83
83
  attributes: attribute_list,
84
- line_break: line_break)
85
- }
86
-
84
+ line_break: line_break,
85
+ )
86
+ end
87
87
 
88
88
  # Text Element
89
- rule(text: simple(:text)) {
89
+ rule(text: simple(:text)) do
90
90
  Element::TextElement.new(text.to_s)
91
- }
91
+ end
92
92
 
93
- rule(text: simple(:text), line_break: simple(:line_break)) {
93
+ rule(text_string: subtree(:text_string)) do
94
+ text_string.to_s
95
+ end
96
+
97
+ rule(text: simple(:text), line_break: simple(:line_break)) do
94
98
  Element::TextElement.new(text.to_s, line_break: line_break)
95
- }
99
+ end
100
+
101
+ rule(text: sequence(:text), line_break: simple(:line_break)) do
102
+ Element::TextElement.new(text, line_break: line_break)
103
+ end
96
104
 
97
105
  rule(id: simple(:id), text: simple(:text)) do
98
106
  Element::TextElement.new(text.to_s, id: id.to_s)
99
107
  end
100
108
 
101
- rule(text: sequence(:text)) {
109
+ rule(text: sequence(:text)) do
102
110
  Element::TextElement.new(text)
103
- }
111
+ end
104
112
 
105
113
  rule(
106
114
  text: simple(:text),
107
- line_break: simple(:line_break)
115
+ line_break: simple(:line_break),
108
116
  ) do
109
117
  Element::TextElement.new(
110
118
  text.to_s,
111
- line_break: line_break)
119
+ line_break: line_break,
120
+ )
112
121
  end
113
122
 
114
123
  rule(
115
124
  id: simple(:id),
116
125
  text: simple(:text),
117
- line_break: simple(:line_break)
126
+ line_break: simple(:line_break),
118
127
  ) do
119
128
  Element::TextElement.new(
120
129
  text.to_s,
121
- id: id,
122
- line_break: line_break)
130
+ id: id.to_s,
131
+ line_break: line_break,
132
+ )
123
133
  end
124
134
 
125
135
  rule(
126
136
  id: simple(:id),
127
137
  text: sequence(:text),
128
- line_break: simple(:line_break)
138
+ line_break: simple(:line_break),
129
139
  ) do
130
140
  Element::TextElement.new(
131
141
  text,
132
- id: id,
133
- line_break: line_break)
142
+ id: id.to_s,
143
+ line_break: line_break,
144
+ )
134
145
  end
135
146
 
136
147
  rule(text: sequence(:text),
137
- line_break: simple(:line_break)
138
- ) do
148
+ line_break: simple(:line_break)) do
139
149
  Element::TextElement.new(
140
150
  text,
141
- line_break: line_break)
151
+ line_break: line_break,
152
+ )
142
153
  end
143
154
 
144
- rule(href: simple(:href)){
155
+ # Inlines
156
+ rule(href: simple(:href)) do
145
157
  Element::Inline::CrossReference.new(
146
- href.to_s
158
+ href.to_s,
147
159
  )
148
- }
160
+ end
149
161
 
150
162
  rule(href: simple(:href),
151
- name: simple(:name)
152
- ){
163
+ name: simple(:name)) do
153
164
  Element::Inline::CrossReference.new(
154
165
  href.to_s,
155
- name.to_s
166
+ name.to_s,
156
167
  )
157
- }
168
+ end
158
169
 
159
- rule(bold_constrained: sequence(:text)){
170
+ rule(bold_constrained: sequence(:text)) do
160
171
  Element::Inline::Bold.new(text, unconstrained: false)
161
- }
172
+ end
162
173
 
163
- rule(bold_unconstrained: sequence(:text)) {
174
+ rule(bold_unconstrained: sequence(:text)) do
164
175
  Element::Inline::Bold.new(text, unconstrained: true)
165
- }
176
+ end
166
177
 
167
- rule(highlight_constrained: sequence(:text)) {
168
- Element::Inline::Highlight.new(text, unconstrained: false)
169
- }
170
- rule(highlight_unconstrained: sequence(:text)) {
171
- Element::Inline::Highlight.new(text, unconstrained: true)
172
- }
178
+ rule(span_constrained: subtree(:span_constrained)) do
179
+ Element::Inline::Span.new(span_constrained[:text],
180
+ unconstrained: false,
181
+ attributes: span_constrained[:attribute_list])
182
+ end
183
+ rule(span_unconstrained: subtree(:span_unconstrained)) do
184
+ Element::Inline::Span.new(span_unconstrained[:text], unconstrained: true,
185
+ attributes: span_unconstrained[:attribute_list])
186
+ end
173
187
 
174
- rule(italic_constrained: sequence(:text)) {
188
+ rule(italic_constrained: sequence(:text)) do
175
189
  Element::Inline::Italic.new(text, unconstrained: false)
176
- }
177
- rule(italic_unconstrained: sequence(:text)) {
190
+ end
191
+ rule(italic_unconstrained: sequence(:text)) do
178
192
  Element::Inline::Italic.new(text, unconstrained: true)
179
- }
193
+ end
194
+
195
+ rule(highlight_constrained: sequence(:text)) do
196
+ Element::Inline::Highlight.new(text, unconstrained: false)
197
+ end
198
+ rule(highlight_unconstrained: sequence(:text)) do
199
+ Element::Inline::Highlight.new(text, unconstrained: true)
200
+ end
180
201
 
202
+ rule(monospace_constrained: sequence(:text)) do
203
+ Element::Inline::Monospace.new(text, unconstrained: false)
204
+ end
205
+ rule(monospace_unconstrained: sequence(:text)) do
206
+ Element::Inline::Monospace.new(text, unconstrained: true)
207
+ end
208
+
209
+ rule(superscript: sequence(:content)) do
210
+ Element::Inline::Superscript.new(content)
211
+ end
212
+
213
+ rule(subscript: sequence(:content)) do
214
+ Element::Inline::Subscript.new(content)
215
+ end
181
216
 
182
217
  # Paragraph
183
218
  rule(paragraph: subtree(:paragraph)) do
@@ -185,12 +220,10 @@ module Coradoc
185
220
  paragraph[:lines],
186
221
  id: paragraph[:id],
187
222
  attributes: paragraph[:attribute_list],
188
- title: paragraph[:title]
189
- )
223
+ title: paragraph[:title],
224
+ )
190
225
  end
191
226
 
192
-
193
-
194
227
  # Title Element
195
228
  rule(
196
229
  level: simple(:level),
@@ -216,91 +249,88 @@ module Coradoc
216
249
  attribute_list = section[:attribute_list] || nil
217
250
  contents = section[:contents] || []
218
251
  sections = section[:sections]
219
- opts = {id:,attribute_list:,contents:,sections: }
252
+ opts = { id:, attribute_list:, contents:, sections: }
220
253
  Element::Section.new(title, opts)
221
254
  end
222
255
 
223
-
224
256
  rule(example: sequence(:example)) do
225
257
  Element::Core.new("", type: "example", lines: example)
226
258
  end
227
259
 
228
- rule(bibliography_entry: subtree(:bib_entry) ){
260
+ rule(bibliography_entry: subtree(:bib_entry)) do
229
261
  Element::BibliographyEntry.new(bib_entry)
230
- }
262
+ end
231
263
 
232
264
  rule(
233
265
  id: simple(:id),
234
266
  title: simple(:title),
235
- entries: sequence(:entries)
236
- ){
267
+ entries: sequence(:entries),
268
+ ) do
237
269
  Element::Bibliography.new(
238
270
  id: id,
239
271
  title: title,
240
- entries: entries
241
- )
242
- }
272
+ entries: entries,
273
+ )
274
+ end
243
275
 
244
276
  rule(
245
277
  key: simple(:key),
246
278
  delimiter: simple(:delimiter),
247
- value: simple(:value)
248
- ){
279
+ value: simple(:value),
280
+ ) do
249
281
  Element::Inline::CrossReferenceArg.new(key, delimiter, value)
250
- }
282
+ end
251
283
 
252
- rule(href_arg: simple(:href_arg)){
253
- href_arg.to_s
254
- }
284
+ rule(href_arg: simple(:href_arg)) do
285
+ href_arg.to_s
286
+ end
255
287
 
256
- rule(citation: subtree(:citation)){
257
- xref = citation[:cross_reference]
258
- xref = Element::Inline::CrossReference.new(xref[0], xref[1..-1]) if xref
259
- comment = citation[:comment]
260
- opts = {}
261
- opts[:cross_reference] = xref if xref
262
- opts[:comment] = comment if comment
263
- Element::Inline::Citation.new(opts)
264
- }
288
+ rule(cross_reference: sequence(:xref)) do
289
+ args = xref.size > 1 ? xref[1..-1] : []
290
+ Element::Inline::CrossReference.new(xref[0], args)
291
+ end
265
292
 
266
- rule(term_type: simple(:term_type),
267
- term: simple(:term),
268
- line_break: simple(:line_break)){
269
- Coradoc::Element::Term.new(term, type: term_type, line_break: line_break, lang: :en)
270
- }
293
+ rule(attribute_reference: simple(:name)) do
294
+ Element::Inline::AttributeReference.new(name)
295
+ end
271
296
 
272
297
  rule(term_type: simple(:term_type),
273
- term2: simple(:term2),
274
- line_break: simple(:line_break)){
275
- Coradoc::Element::Term.new(term2, type: term_type, line_break: line_break, lang: :fr)
276
- }
298
+ term: simple(:term)) do
299
+ Coradoc::Element::Term.new(term, type: term_type, lang: :en)
300
+ end
277
301
 
302
+ rule(footnote: simple(:footnote)) do
303
+ Coradoc::Element::Inline::Footnote.new(footnote)
304
+ end
278
305
 
279
- rule(block: subtree(:block)
280
- ) {
306
+ rule(footnote: simple(:footnote), id: simple(:id)) do
307
+ Coradoc::Element::Inline::Footnote.new(footnote, id)
308
+ end
281
309
 
310
+ rule(block: subtree(:block)) do
282
311
  id = block[:id]
283
312
  title = block[:title]
284
313
  attribute_list = block[:attribute_list]
285
314
  delimiter = block[:delimiter].to_s
286
315
  delimiter_c = delimiter[0]
287
316
  lines = block[:lines]
288
- ordering = block.keys.select{|k|
289
- [:id, :title, :attribute_list, :attribute_list2].include?(k)}
290
-
291
- opts = {id: id,
292
- title: title,
293
- delimiter_len: delimiter.size,
294
- lines: lines,
295
- ordering: ordering}
317
+ ordering = block.keys.select do |k|
318
+ %i[id title attribute_list attribute_list2].include?(k)
319
+ end
320
+
321
+ opts = { id: id,
322
+ title: title,
323
+ delimiter_len: delimiter.size,
324
+ lines: lines,
325
+ ordering: ordering }
296
326
  opts[:attributes] = attribute_list if attribute_list
297
327
  if delimiter_c == "*"
298
328
  if attribute_list
299
- if (attribute_list.positional == [] &&
300
- attribute_list.named.keys[0] == "reviewer")
329
+ if attribute_list.positional == [] &&
330
+ attribute_list.named.keys[0] == "reviewer"
301
331
  Element::Block::ReviewerComment.new(opts)
302
- elsif (attribute_list.positional[0] == "sidebar" &&
303
- attribute_list.named == {})
332
+ elsif attribute_list.positional[0] == "sidebar" &&
333
+ attribute_list.named == {}
304
334
  Element::Block::Side.new(opts)
305
335
  else
306
336
  Element::Block::Side.new(opts)
@@ -314,17 +344,16 @@ module Coradoc
314
344
  Element::Block::Pass.new(opts)
315
345
  elsif delimiter_c == "-" && delimiter.size == 2
316
346
  Element::Block::Open.new(title, opts)
317
- elsif delimiter_c == "-"&& delimiter.size >= 4
347
+ elsif delimiter_c == "-" && delimiter.size >= 4
318
348
  Element::Block::SourceCode.new(title, opts)
319
349
  elsif delimiter_c == "_"
320
350
  Element::Block::Quote.new(title, opts)
321
351
  end
322
- }
352
+ end
323
353
 
324
354
  # Admonition
325
355
  rule(admonition_type: simple(:admonition_type),
326
- content: sequence(:content),
327
- ) do
356
+ content: sequence(:content)) do
328
357
  Element::Admonition.new(content, admonition_type.to_s)
329
358
  end
330
359
 
@@ -334,26 +363,24 @@ module Coradoc
334
363
  path = block_image[:path]
335
364
  opts = {
336
365
  attributes: block_image[:attribute_list_macro],
337
- line_break: block_image[:line_break]
366
+ line_break: block_image[:line_break],
338
367
  }
339
368
  Element::Image::BlockImage.new(title, id, path, opts)
340
369
  end
341
370
 
342
-
343
-
344
371
  # Attribute
345
372
  rule(key: simple(:key), value: simple(:value)) do
346
- Element::Attribute.new(key, value)
373
+ Element::Attribute.new(key.to_s, value.to_s)
347
374
  end
348
375
 
349
376
  rule(key: simple(:key), value: simple(:value),
350
377
  line_break: simple(:line_break)) do
351
- Element::Attribute.new(key, value, line_break: line_break)
378
+ Element::Attribute.new(key.to_s, value.to_s, line_break: line_break.to_s)
352
379
  end
353
380
 
354
- rule(line_break: simple(:line_break)) {
381
+ rule(line_break: simple(:line_break)) do
355
382
  Element::LineBreak.new(line_break)
356
- }
383
+ end
357
384
 
358
385
  rule(document_attributes: sequence(:document_attributes)) do
359
386
  Element::DocumentAttributes.new(document_attributes)
@@ -361,17 +388,17 @@ module Coradoc
361
388
 
362
389
  # Table
363
390
 
364
- rule(cols: sequence(:cols)) {
365
- cells = cols.map{|c| Element::Table::Cell.new(content: c)}
391
+ rule(cols: sequence(:cols)) do
392
+ cells = cols.map { |c| Element::Table::Cell.new(content: c) }
366
393
  Element::Table::Row.new(cells)
367
- }
394
+ end
368
395
 
369
396
  rule(table: subtree(:table)) do
370
397
  title = table[:title] || nil
371
398
  rows = table[:rows] || []
372
399
  opts = {
373
400
  id: table[:id] || nil,
374
- attributes: table[:attribute_list] || nil
401
+ attributes: table[:attribute_list] || nil,
375
402
  }
376
403
  Element::Table.new(title, rows, opts)
377
404
  end
@@ -380,22 +407,22 @@ module Coradoc
380
407
  marker = list_item[:marker]
381
408
  id = list_item[:id]
382
409
  text = list_item[:text]
410
+ text = list_item[:text].to_s if list_item[:text].instance_of?(Parslet::Slice)
383
411
  attached = list_item[:attached]
384
412
  nested = list_item[:nested]
385
413
  line_break = list_item[:line_break]
386
414
  Element::ListItem.new(
387
- text, id:, marker:, attached:, nested:, line_break: )
415
+ text, id:, marker:, attached:, nested:, line_break:
416
+ )
388
417
  end
389
418
 
390
-
391
419
  # List
392
420
  rule(list: simple(:list)) { list }
393
421
  rule(unordered: sequence(:list_items)) do
394
422
  Element::List::Unordered.new(list_items)
395
423
  end
396
424
  rule(attribute_list: simple(:attribute_list),
397
- unordered: sequence(:list_items)
398
- ) do
425
+ unordered: sequence(:list_items)) do
399
426
  Element::List::Unordered.new(list_items, attrs: attribute_list)
400
427
  end
401
428
 
@@ -404,21 +431,25 @@ module Coradoc
404
431
  end
405
432
 
406
433
  rule(attribute_list: simple(:attribute_list),
407
- ordered: sequence(:list_items)
408
- ) do
434
+ ordered: sequence(:list_items)) do
409
435
  Element::List::Ordered.new(list_items, attrs: attribute_list)
410
436
  end
411
437
 
438
+ rule(dlist_term: simple(:t),
439
+ delimiter: simple(:d)) do
440
+ # DefinitionListTerm.new(t.to_s, d.to_s)
441
+ t.to_s
442
+ end
412
443
 
413
- rule(terms: simple(:terms), definition: simple(:definition)) do
444
+ rule(definition_list_item: { terms: sequence(:terms),
445
+ definition: simple(:contents) }) do
414
446
  Element::ListItemDefinition.new(terms, contents)
415
447
  end
416
448
 
417
- rule(definition_list: sequence(:definition_list)) do
449
+ rule(definition_list: sequence(:list_items)) do
418
450
  Element::List::Definition.new(list_items)
419
451
  end
420
452
 
421
-
422
453
  # Highlight
423
454
  rule(highlight: simple(:text)) { Element::Highlight.new(text) }
424
455
 
@@ -434,7 +465,6 @@ module Coradoc
434
465
  Document.from_ast(elements)
435
466
  end
436
467
 
437
-
438
468
  # rule(unparsed: simple(:text)) do
439
469
  # text.to_s
440
470
  # end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Coradoc
4
- VERSION = "1.1.5"
4
+ VERSION = "1.1.7"
5
5
  end
data/lib/reverse_adoc.rb CHANGED
@@ -17,4 +17,4 @@ WARN
17
17
 
18
18
  require "coradoc/input/html"
19
19
 
20
- ReverseAdoc = Coradoc::Input::HTML
20
+ ReverseAdoc = Coradoc::Input::Html
@@ -0,0 +1,29 @@
1
+ $LOAD_PATH.unshift("../coradoc/lib")
2
+ require "coradoc"
3
+ require "pp"
4
+
5
+ def pretty_print_obj(obj)
6
+ sio = StringIO.new
7
+ PP.pp(obj, sio, 69)
8
+ puts sio.string
9
+ end
10
+
11
+ def print_parsed(str)
12
+ parse = Coradoc::Parser::Base.new.parse(str)
13
+ puts str
14
+ puts ""
15
+ pretty_print_obj parse[:document]
16
+ puts ""
17
+ doc = Coradoc::Transformer.transform(parse[:document])
18
+ pp doc
19
+ puts Coradoc::Generator.gen_adoc(doc)
20
+ end
21
+
22
+ content = <<~END
23
+ [a='quoted named']
24
+ ****
25
+ block
26
+ ****
27
+ END
28
+
29
+ print_parsed(content)
@@ -17,24 +17,25 @@ def is_def?(arr)
17
17
  end
18
18
 
19
19
  path = "lib/coradoc/parser/asciidoc/"
20
- class_files = Dir.entries(path).select{|x| File.file?(path+x)}
20
+ class_files = Dir.entries(path).select { |x| File.file?(path + x) }
21
21
 
22
22
  $all_defs = {}
23
23
 
24
24
  class_files.each do |cf|
25
- a = ast_from(File.open(path+cf).read)
25
+ a = ast_from(File.open(path + cf).read)
26
26
  next if a.nil?
27
+
27
28
  sexp = a.to_sexp_array
28
29
  $defs = []
29
30
  is_def?(sexp)
30
31
  $all_defs[cf] = $defs
31
- end;
32
+ end
32
33
 
33
- relevant_names = $all_defs.map{|fn, defs| defs.map{|d| d[1]}}.flatten;
34
+ relevant_names = $all_defs.map { |_fn, defs| defs.map { |d| d[1] } }.flatten
34
35
 
35
- require 'graphviz'
36
+ require "graphviz"
36
37
 
37
- g = GraphViz.new( :G, :type => :digraph );
38
+ g = GraphViz.new(:G, type: :digraph)
38
39
 
39
40
  g[:fontsize] = 8
40
41
  g[:rankdir] = "LR"
@@ -44,23 +45,22 @@ g[:splines] = false
44
45
  nodes = {}
45
46
 
46
47
  $all_defs.each do |file_name, defs|
47
-
48
48
  defs.each do |ast_def|
49
- calls = ast_def[2..-1].flatten & relevant_names
49
+ ast_def[2..].flatten & relevant_names
50
50
  node_name = ast_def[1]
51
- nodes[node_name] = g.add_nodes( "#{node_name}\n#{file_name}" )
51
+ nodes[node_name] = g.add_nodes("#{node_name}\n#{file_name}")
52
52
  end
53
- end;
53
+ end
54
54
 
55
- $all_defs.each do |file_name, defs|
55
+ $all_defs.each_value do |defs|
56
56
  defs.each do |ast_def|
57
- calls = ast_def[2..-1].flatten & relevant_names
57
+ calls = ast_def[2..].flatten & relevant_names
58
58
  node_name = ast_def[1]
59
59
  calls.each do |cl|
60
60
  w = g.add_edges(nodes[node_name], nodes[cl])
61
61
  w[:weight] = 1.5
62
62
  end
63
63
  end
64
- end;
64
+ end
65
65
 
66
- g.output( :png => "utils/parser_graph.png_#{Time.now.to_i}" );
66
+ g.output(png: "utils/parser_graph.png_#{Time.now.to_i}")