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