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
@@ -2,69 +2,192 @@ module Coradoc
2
2
  module Parser
3
3
  module Asciidoc
4
4
  module Inline
5
+ def attribute_reference
6
+ str("{").present? >> str("{") >>
7
+ match("[a-zA-Z0-9_-]").repeat(1).as(:attribute_reference) >>
8
+ str("}")
9
+ end
5
10
 
6
11
  def bold_constrained
7
- (str('*') >>
8
- match("[^*]").repeat(1).as(:text).repeat(1,1) >>
9
- str('*') >> str('*').absent?
10
- ).as(:bold_constrained)
12
+ (str("*").present? >> str("*") >>
13
+ match("[^*]").repeat(1).as(:text).repeat(1, 1) >>
14
+ str("*") >> str("*").absent? >>
15
+ str("\n\n").absent?
16
+ ).as(:bold_constrained)
11
17
  end
12
18
 
13
19
  def bold_unconstrained
14
- (str('**') >>
15
- match("[^*\n]").repeat(1).as(:text).repeat(1,1) >>
16
- str('**')
17
- ).as(:bold_unconstrained)
20
+ (str("**").present? >> str("**") >>
21
+ match("[^*]").repeat(1).as(:text).repeat(1, 1) >>
22
+ str("**")
23
+ ).as(:bold_unconstrained)
18
24
  end
19
25
 
20
- def highlight_constrained
21
- (str('#') >>
22
- match('[^#]').repeat(1).as(:text).repeat(1,1) >>
23
- str('#') >> str('#').absent?
24
- ).as(:highlight_constrained)
26
+ def span_constrained
27
+ (attribute_list >>
28
+ str("#") >>
29
+ match("[^#]").repeat(1).as(:text) >>
30
+ str("#") >> str("#").absent?
31
+ ).as(:span_constrained)
25
32
  end
26
33
 
27
- def highlight_unconstrained
28
- (str('##') >>
29
- match('[^#]').repeat(1).as(:text).repeat(1,1) >>
30
- str('##')
31
- ).as(:highlight_unconstrained)
34
+ def span_unconstrained
35
+ (attribute_list >>
36
+ str("##") >>
37
+ match("[^#]").repeat(1).as(:text) >>
38
+ str("##")
39
+ ).as(:span_unconstrained)
32
40
  end
33
41
 
34
42
  def italic_constrained
35
- (str('_') >>
36
- match('[^_]').repeat(1).as(:text).repeat(1,1) >>
37
- str('_') >> str('_').absent?
38
- ).as(:italic_constrained)
43
+ (str("_") >> str("_").absent? >>
44
+ match("[^_]").repeat(1).as(:text).repeat(1, 1) >>
45
+ str("_") >> str("_").absent?
46
+ ).as(:italic_constrained)
39
47
  end
40
48
 
41
49
  def italic_unconstrained
42
- (str('__') >>
43
- match('[^_]').repeat(1).as(:text).repeat(1,1) >>
44
- str('__')
45
- ).as(:italic_unconstrained)
50
+ (str("__") >>
51
+ match("[^_]").repeat(1).as(:text).repeat(1, 1) >>
52
+ str("__")
53
+ ).as(:italic_unconstrained)
54
+ end
55
+
56
+ def highlight_constrained
57
+ (str("#") >>
58
+ match("[^#]").repeat(1).as(:text).repeat(1, 1) >>
59
+ str("#") >> str("#").absent?
60
+ ).as(:highlight_constrained)
61
+ end
62
+
63
+ def highlight_unconstrained
64
+ (str("##") >>
65
+ match("[^#]").repeat(1).as(:text).repeat(1, 1) >>
66
+ str("##")
67
+ ).as(:highlight_unconstrained)
68
+ end
69
+
70
+ def monospace_constrained
71
+ (str("`") >>
72
+ match("[^`]").repeat(1).as(:text).repeat(1, 1) >>
73
+ str("`") >> str("`").absent?
74
+ ).as(:monospace_constrained)
75
+ end
76
+
77
+ def monospace_unconstrained
78
+ (str("``") >>
79
+ match("[^`]").repeat(1).as(:text).repeat(1, 1) >>
80
+ str("``")
81
+ ).as(:monospace_unconstrained)
82
+ end
83
+
84
+ def superscript
85
+ (str("^") >>
86
+ match("[^^]").repeat(1).as(:text).repeat(1, 1) >>
87
+ str("^")
88
+ ).as(:superscript)
89
+ end
90
+
91
+ def subscript
92
+ (str("~") >>
93
+ match("[^~]").repeat(1).as(:text).repeat(1, 1) >>
94
+ str("~")
95
+ ).as(:subscript)
96
+ end
97
+
98
+ def span
99
+ attribute_list >>
100
+ (str("#") >>
101
+ match("[^#]").repeat(1).as(:text) >>
102
+ str("#") >> str("#").absent?
103
+ ).as(:span)
104
+ end
105
+
106
+ def link
107
+ ((str("http").present? | str("https").present? | str("ftp").present?) >>
108
+ match("[A-Za-z0-9_.\\-:/&?=+,%#~;]+").repeat(1).as(:path) >>
109
+ (str("[") >> match("[^\\]]").repeat(1).as(:text) >> str("]")).maybe
110
+ ).as(:link) |
111
+ (str("link:").present? >> str("link:") >>
112
+ match("[A-Za-z0-9_.\\-:/&?=+,%#~;]+").repeat(1).as(:path) >>
113
+ (str("[") >> match("[^\\]]").repeat(1).as(:text) >> str("]")).maybe
114
+ ).as(:link)
115
+ end
116
+
117
+ def inline_image
118
+ (str("image:").present? >> str("image:") >>
119
+ match("[A-Za-z0-9_.\\-:/&?=+,%#~;]+").repeat(1).as(:path) >>
120
+ (str("[") >> match("[^\\]]").repeat(1).as(:text) >> str("]")).maybe
121
+ ).as(:inline_image)
122
+ end
123
+
124
+ def underline
125
+ (attribute_list >> match("\\[.underline\\]").as(:role) >>
126
+ str("#") >>
127
+ match("[^#]").repeat(1).as(:text) >>
128
+ str("#")
129
+ ).as(:underline)
130
+ end
131
+
132
+ def small
133
+ (attribute_list >> match("\\[.small\\]").as(:role) >>
134
+ str("#") >>
135
+ match("[^#]").repeat(1).as(:text) >>
136
+ str("#")
137
+ ).as(:small)
138
+ end
139
+
140
+ def inline_chars?
141
+ match('[\[*#_{<^~`]').present? |
142
+ str("http").present? |
143
+ str("https").present? |
144
+ str("link:").present? |
145
+ str("image:").present? |
146
+ term_type.present? |
147
+ str("footnote").present?
148
+ end
149
+
150
+ def inline
151
+ bold_unconstrained |
152
+ bold_constrained |
153
+ span_unconstrained |
154
+ span_constrained |
155
+ italic_unconstrained |
156
+ italic_constrained |
157
+ highlight_unconstrained |
158
+ highlight_constrained |
159
+ monospace_unconstrained |
160
+ monospace_constrained |
161
+ superscript |
162
+ subscript |
163
+ attribute_reference |
164
+ cross_reference |
165
+ term_inline |
166
+ term_inline2 |
167
+ footnote |
168
+ link |
169
+ inline_image |
170
+ underline |
171
+ small
46
172
  end
47
173
 
48
174
  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
- )
175
+ # line_not_text? >>
176
+ (inline.absent? >>
177
+ match("[^\n]")
178
+ ).repeat(1)
59
179
  end
60
180
 
61
181
  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
-
182
+ (inline_chars? >> inline)
183
+ end
184
+
185
+ def text_any
186
+ (text_formatted |
187
+ text_unformatted.as(:text)
188
+ ).repeat(2) |
189
+ text_formatted.repeat(1, 1) |
190
+ text_unformatted
68
191
  end
69
192
  end
70
193
  end
@@ -3,13 +3,12 @@ module Coradoc
3
3
  module Parser
4
4
  module Asciidoc
5
5
  module List
6
-
7
6
  def list(nesting_level = 1)
8
- (
7
+ (
9
8
  unordered_list(nesting_level) |
10
9
  ordered_list(nesting_level) |
11
10
  definition_list
12
- ).as(:list)
11
+ ).as(:list)
13
12
  end
14
13
 
15
14
  def list_continuation
@@ -30,8 +29,8 @@ module Coradoc
30
29
 
31
30
  def definition_list(delimiter = "::")
32
31
  (attribute_list >> newline).maybe >>
33
- dlist_item(delimiter).as(:definition_list).repeat(1) >>
34
- dlist_item(delimiter).absent?
32
+ dlist_item(delimiter).repeat(1).as(:definition_list) >>
33
+ dlist_item(delimiter).absent?
35
34
  end
36
35
 
37
36
  def list_marker(nesting_level = 1)
@@ -39,75 +38,76 @@ module Coradoc
39
38
  end
40
39
 
41
40
  def olist_marker(nesting_level = 1)
42
- line_start? >> str('.' * nesting_level) >> str('.').absent?
41
+ line_start? >> str("." * nesting_level) >> str(".").absent?
43
42
  end
44
43
 
45
44
  def olist_item(nesting_level = 1)
46
45
  item = olist_marker(nesting_level).as(:marker) >>
47
- match("\n").absent? >> space >> text_line(true)# >>
48
- # (list_continuation.present? >> list_continuation >>
46
+ match("\n").absent? >> space >> text_line(true)
47
+ # >>
48
+ # (list_continuation.present? >> list_continuation >>
49
49
  # paragraph #| example_block(n_deep: 1)
50
50
  # ).repeat(0).as(:attached)
51
51
 
52
52
  att = (list_continuation.present? >>
53
- list_continuation >>
54
- (admonition_line | paragraph | block) #(n_deep: 1))
53
+ list_continuation >>
54
+ (admonition_line | paragraph | block) # (n_deep: 1))
55
55
  ).repeat(0).as(:attached)
56
56
  item = item >> att.maybe
57
57
 
58
-
59
58
  if nesting_level <= 4
60
59
  item = item >>
61
60
  (list_marker(nesting_level + 1).present? >>
62
- list(nesting_level + 1)).repeat(0).as(:nested)#).maybe
61
+ list(nesting_level + 1)).repeat(0).as(:nested) # ).maybe
63
62
  end
64
63
  olist_marker(nesting_level).present? >> item.as(:list_item)
65
64
  end
66
65
 
67
66
  def ulist_marker(nesting_level = 1)
68
- line_start? >> str('*' * nesting_level) >> str('*').absent?
67
+ line_start? >> str("*" * nesting_level) >> str("*").absent?
69
68
  end
70
69
 
71
70
  def ulist_item(nesting_level = 1)
72
71
  item = ulist_marker(nesting_level).as(:marker) >>
73
- str(' [[[').absent? >>
74
- match("\n").absent? >> space >> text_line(true)
72
+ str(" [[[").absent? >>
73
+ match("\n").absent? >> space >> text_line(true)
75
74
 
76
75
  att = (list_continuation.present? >>
77
- list_continuation >>
78
- (admonition_line | paragraph | block) #(n_deep: 1))
76
+ list_continuation >>
77
+ (admonition_line | paragraph | block) # (n_deep: 1))
79
78
  ).repeat(0).as(:attached)
80
79
  item = item >> att.maybe
81
80
 
82
81
  if nesting_level <= 4
83
82
  item = item >>
84
83
  (list_marker(nesting_level + 1).present? >>
85
- list(nesting_level + 1)).repeat(0).as(:nested)#).maybe
84
+ list(nesting_level + 1)).repeat(0).as(:nested) # ).maybe
86
85
  end
87
86
  ulist_marker(nesting_level).present? >> item.as(:list_item)
88
87
  end
89
88
 
90
89
  def dlist_delimiter
91
90
  (str("::") | str(":::") | str("::::") | str(";;")
92
- ).as(:delimiter)
91
+ ).as(:delimiter)
93
92
  end
94
93
 
95
- def dlist_term(delimiter)
96
- (match("[^\n:]").repeat(1) #>> empty_line.repeat(0)
97
- ).as(:term) >> dlist_delimiter
94
+ def dlist_term(_delimiter)
95
+ match("[^\n:]").repeat(1) # >> empty_line.repeat(0)
96
+ .as(:dlist_term) >> dlist_delimiter
98
97
  end
99
98
 
100
99
  def dlist_definition
101
- (text #>> empty_line.repeat(0)
102
- ).as(:definition) >> line_ending >> empty_line.repeat(0)
100
+ text # >> empty_line.repeat(0)
101
+ .as(:definition) >> line_ending >> empty_line.repeat(0)
103
102
  end
104
103
 
105
104
  def dlist_item(delimiter)
106
105
  (((dlist_term(delimiter).as(:terms).repeat(1) >> line_ending >>
107
106
  empty_line.repeat(0)).repeat(1) >>
108
- dlist_definition) |
109
- (dlist_term(delimiter).repeat(1,1).as(:terms) >> space >> dlist_definition)
110
- ).as(:definition_list_item).repeat(1)
107
+ dlist_definition) |
108
+ (dlist_term(delimiter).repeat(1, 1).as(:terms) >> space >>
109
+ dlist_definition)
110
+ ).as(:definition_list_item)
111
111
  end
112
112
  end
113
113
  end
@@ -2,35 +2,44 @@ module Coradoc
2
2
  module Parser
3
3
  module Asciidoc
4
4
  module Paragraph
5
-
6
5
  def line_not_text?
7
6
  line_start? >>
8
- attribute_list.absent? >>
9
- block_delimiter.absent? >>
10
- list.absent? >>
11
- # list_prefix.absent? >>
12
- section_id.absent? >>
13
- section_prefix.absent?
7
+ (attribute_list >> newline).absent? >>
8
+ block_delimiter.absent? >>
9
+ list.absent? >>
10
+ list_prefix.absent? >>
11
+ list_continuation.absent? >>
12
+ element_id.absent? >>
13
+ section_prefix.absent?
14
14
  end
15
15
 
16
- def paragraph_text_line
17
- line_not_text? >>
18
- (asciidoc_char_with_id.absent? | text_id ) >>
19
- literal_space? >>
20
- (line_not_text? >>
21
- text_formatted.as(:text) # >>
22
- ) | term | term2
16
+ # TODO: This is crazy that many_breaks can be 0, true or false!?
17
+ def paragraph_text_line(many_breaks = false)
18
+ tl = line_not_text? >>
19
+ (asciidoc_char_with_id.absent? |
20
+ element_id_inline >> literal_space? |
21
+ line_start? >> line_not_text?) >>
22
+ text_any.as(:text)
23
+ if many_breaks == 0
24
+ tl >> eof?
25
+ elsif many_breaks
26
+ tl >> (newline.as(:line_break) | eof?)
27
+ else
28
+ tl >> (newline_single.as(:line_break) | eof?)
29
+ end
23
30
  end
24
31
 
25
32
  def paragraph
26
- ( block_id.maybe >>
33
+ (element_id.maybe >>
27
34
  block_title.maybe >>
28
35
  (attribute_list >> newline).maybe >>
29
- (line_not_text? >> paragraph_text_line.repeat(1,1) >> any.absent? |
30
- (line_not_text? >> paragraph_text_line >> newline_single.as(:line_break)).repeat(1) >>
31
- (line_not_text? >> paragraph_text_line.repeat(1,1)).repeat(0,1)
36
+ ((paragraph_text_line(0).repeat(1, 1) >>
37
+ (newline.repeat(1).as(:line_break) | eof?)) |
38
+ paragraph_text_line(false).repeat(1) >>
39
+ (paragraph_text_line(true).repeat(1, 1) >>
40
+ (newline.repeat(1).as(:line_break) | eof?)).repeat(0, 1)
32
41
  ).as(:lines) >>
33
- newline.repeat(0)
42
+ (newline.repeat(0) | eof?)
34
43
  ).as(:paragraph)
35
44
  end
36
45
 
@@ -2,11 +2,8 @@ module Coradoc
2
2
  module Parser
3
3
  module Asciidoc
4
4
  module Section
5
-
6
5
  def contents
7
6
  (
8
- citation |
9
- term | term2 |
10
7
  bib_entry |
11
8
  block_image |
12
9
  tag |
@@ -16,8 +13,8 @@ module Coradoc
16
13
  admonition_line |
17
14
  block |
18
15
  table.as(:table) |
19
- highlight.as(:highlight) |
20
- glossaries.as(:glossaries) |
16
+ # highlight.as(:highlight) |
17
+ # glossaries.as(:glossaries) |
21
18
  paragraph |
22
19
  list |
23
20
  empty_line.as(:line_break)
@@ -26,41 +23,38 @@ module Coradoc
26
23
 
27
24
  def section_block(level = 2)
28
25
  return nil if level > 8
26
+
29
27
  (attribute_list >> newline).maybe >>
30
- section_id.maybe >>
31
- (attribute_list >> newline).maybe >>
28
+ element_id.maybe >>
29
+ (attribute_list >> newline).maybe >>
32
30
  section_title(level).as(:title) >>
33
31
  contents.as(:contents).maybe
34
32
  end
35
33
 
36
- # Section id
37
- def section_id
38
- line_start? >>
39
- (str("[[") >> keyword.as(:id) >> str("]]") |
40
- str("[#") >> keyword.as(:id) >> str("]")) >> newline
34
+ def section_prefix
35
+ (line_start? >> match("^[=]") >> str("=").repeat(0) >> match('[^\n]'))
41
36
  end
42
37
 
43
38
  # Heading
44
39
  def section_title(level = 2, max_level = 8)
45
40
  line_start? >>
46
- match("=").repeat(level, max_level).as(:level) >>
47
- str('=').absent? >>
41
+ match("=").repeat(level, max_level).as(:level) >>
42
+ str("=").absent? >>
48
43
  space? >> text.as(:text) >> endline.as(:line_break)
49
44
  end
50
45
 
51
46
  # section
52
47
  def section(level = 2)
53
- r = section_block(level)
48
+ r = section_block(level)
54
49
  if level < 8
55
50
  r = r >> section(level + 1).as(:section).repeat(0).as(:sections)
56
51
  end
57
52
  if level == 2
58
- (r).as(:section)
53
+ r.as(:section)
59
54
  else
60
55
  r
61
56
  end
62
57
  end
63
-
64
58
  end
65
59
  end
66
60
  end
@@ -5,10 +5,10 @@ module Coradoc
5
5
  # include Coradoc::Parser::Asciidoc::Base
6
6
 
7
7
  def table
8
- block_id.maybe >>
9
- (attribute_list >> newline).maybe >>
10
- block_title.maybe >>
11
- (attribute_list >> newline).maybe >>
8
+ element_id.maybe >>
9
+ (attribute_list >> newline).maybe >>
10
+ block_title.maybe >>
11
+ (attribute_list >> newline).maybe >>
12
12
  str("|===") >> line_ending >>
13
13
  table_row.repeat(1).as(:rows) >>
14
14
  str("|===") >> line_ending
@@ -29,4 +29,4 @@ module Coradoc
29
29
  end
30
30
  end
31
31
  end
32
- end
32
+ end
@@ -3,21 +3,37 @@ module Coradoc
3
3
  module Asciidoc
4
4
  module Term
5
5
  def term_type
6
- (str("alt") | str("deprecated") | str("domain")).as(:term_type)
6
+ (str("term") |
7
+ str("alt") |
8
+ str("deprecated") |
9
+ str("domain")).as(:term_type)
7
10
  end
8
11
 
9
12
  def term
10
13
  line_start? >>
11
- term_type >> str(':[') >>
12
- match('[^\]]').repeat(1).as(:term) >>
13
- str("]") >> str("\n").repeat(1).as(:line_break)
14
+ term_type >> str(":[") >>
15
+ match('[^\]]').repeat(1).as(:term) >>
16
+ str("]") >> str("\n").repeat(1).as(:line_break)
14
17
  end
15
18
 
16
- def term2
19
+ def footnote
20
+ str("footnote:") >>
21
+ keyword.as(:id).maybe >>
22
+ str("[") >>
23
+ match('[^\]]').repeat(1).as(:footnote) >>
24
+ str("]")
25
+ end
26
+
27
+ def term_inline
28
+ term_type >> str(":[") >>
29
+ match('[^\]]').repeat(1).as(:term) >>
30
+ str("]")
31
+ end
32
+
33
+ def term_inline2
17
34
  line_start? >>
18
- match('^\[') >> term_type >> str(']#') >>
19
- match('[^\#]').repeat(1).as(:term2) >> str('#') >>
20
- str("\n").repeat(1).as(:line_break)
35
+ match('^\[') >> term_type >> str("]#") >>
36
+ match('[^\#]').repeat(1).as(:term2) >> str("#")
21
37
  end
22
38
  end
23
39
  end
@@ -2,13 +2,12 @@ module Coradoc
2
2
  module Parser
3
3
  module Asciidoc
4
4
  module Text
5
-
6
5
  def space?
7
6
  space.maybe
8
7
  end
9
8
 
10
9
  def space
11
- str(' ').repeat(1)
10
+ str(" ").repeat(1)
12
11
  end
13
12
 
14
13
  def text
@@ -20,7 +19,7 @@ module Coradoc
20
19
  end
21
20
 
22
21
  def line_ending
23
- str("\n") #| match('[\z]')# | match('$')
22
+ str("\n") # | match('[\z]')# | match('$')
24
23
  end
25
24
 
26
25
  def eof?
@@ -101,7 +100,7 @@ module Coradoc
101
100
  end
102
101
 
103
102
  def include_directive
104
- (str("include::") >>
103
+ (str("include::") >>
105
104
  file_path.as(:path) >>
106
105
  attribute_list >>
107
106
  (newline | str("")).as(:line_break)
@@ -109,7 +108,7 @@ module Coradoc
109
108
  end
110
109
 
111
110
  def inline_image
112
- (str("image::") >>
111
+ (str("image::") >>
113
112
  file_path.as(:path) >>
114
113
  attribute_list >>
115
114
  (line_ending)
@@ -117,45 +116,43 @@ module Coradoc
117
116
  end
118
117
 
119
118
  def block_image
120
- (block_id.maybe >>
119
+ (element_id.maybe >>
121
120
  block_title.maybe >>
122
121
  (attribute_list >> newline).maybe >>
123
- match('^i') >> str("mage::") >>
122
+ match("^i") >> str("mage::") >>
124
123
  file_path.as(:path) >>
125
124
  attribute_list(:attribute_list_macro) >>
126
125
  newline.as(:line_break)
127
- ).as(:block_image)
126
+ ).as(:block_image)
128
127
  end
129
128
 
130
129
  def comment_line
131
130
  tag.absent? >>
132
- (str('//') >> str("/").absent? >>
133
- space? >>
134
- text.as(:comment_text)
131
+ (str("//") >> str("/").absent? >>
132
+ space? >>
133
+ text.as(:comment_text)
135
134
  ).as(:comment_line)
136
135
  end
137
136
 
138
137
  def tag
139
- (str('//') >> str('/').absent? >>
138
+ (str("//") >> str("/").absent? >>
140
139
  space? >>
141
- (str('tag') | str('end')).as(:prefix) >>
142
- str('::') >> str(':').absent? >>
140
+ (str("tag") | str("end")).as(:prefix) >>
141
+ str("::") >> str(":").absent? >>
143
142
  match('[^\[]').repeat(1).as(:name) >>
144
143
  attribute_list >>
145
144
  line_ending.maybe.as(:line_break)
146
- ).as(:tag)
145
+ ).as(:tag)
147
146
  end
148
147
 
149
148
  def comment_block
150
- ( str('////') >> line_ending >>
151
- ((line_ending >> str('////')).absent? >> any
152
- ).repeat.as(:comment_text) >>
153
- line_ending >> str('////')
149
+ (str("////") >> line_ending >>
150
+ ((line_ending >> str("////")).absent? >> any
151
+ ).repeat.as(:comment_text) >>
152
+ line_ending >> str("////")
154
153
  ).as(:comment_block)
155
154
  end
156
155
  end
157
156
  end
158
157
  end
159
158
  end
160
-
161
-