asciidoctor-rfc 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.oss-guides.rubocop.yml +1077 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +19 -1063
  6. data/.travis.yml +3 -2
  7. data/Guardfile +22 -0
  8. data/README.adoc +1151 -0
  9. data/Rakefile +1 -1
  10. data/asciidoctor-rfc.gemspec +20 -3
  11. data/bin/asciidoctor-rfc2 +15 -0
  12. data/bin/asciidoctor-rfc3 +15 -0
  13. data/bin/rspec +0 -1
  14. data/lib/asciidoctor-rfc.rb +4 -0
  15. data/lib/asciidoctor/rfc/common/base.rb +218 -0
  16. data/lib/asciidoctor/rfc/common/front.rb +120 -0
  17. data/lib/asciidoctor/rfc/v2/base.rb +341 -0
  18. data/lib/asciidoctor/rfc/v2/blocks.rb +192 -0
  19. data/lib/asciidoctor/rfc/v2/converter.rb +64 -0
  20. data/lib/asciidoctor/rfc/v2/front.rb +69 -0
  21. data/lib/asciidoctor/rfc/v2/inline_anchor.rb +102 -0
  22. data/lib/asciidoctor/rfc/v2/lists.rb +134 -0
  23. data/lib/asciidoctor/rfc/v2/table.rb +112 -0
  24. data/lib/asciidoctor/rfc/v2/validate.rb +738 -0
  25. data/lib/asciidoctor/rfc/v2/validate2.rng +716 -0
  26. data/lib/asciidoctor/rfc/v3/base.rb +358 -0
  27. data/lib/asciidoctor/rfc/v3/blocks.rb +203 -0
  28. data/lib/asciidoctor/rfc/v3/converter.rb +64 -0
  29. data/lib/asciidoctor/rfc/v3/front.rb +115 -0
  30. data/lib/asciidoctor/rfc/v3/inline_anchor.rb +90 -0
  31. data/lib/asciidoctor/rfc/v3/lists.rb +190 -0
  32. data/lib/asciidoctor/rfc/v3/svg.rng +9081 -0
  33. data/lib/asciidoctor/rfc/v3/table.rb +65 -0
  34. data/lib/asciidoctor/rfc/v3/validate.rb +2168 -0
  35. data/lib/asciidoctor/rfc/v3/validate.rng +2143 -0
  36. data/lib/asciidoctor/rfc/version.rb +2 -2
  37. data/spec/asciidoctor/rfc/v2/appendix_spec.rb +124 -0
  38. data/spec/asciidoctor/rfc/v2/area_spec.rb +60 -0
  39. data/spec/asciidoctor/rfc/v2/author_spec.rb +444 -0
  40. data/spec/asciidoctor/rfc/v2/comments_spec.rb +316 -0
  41. data/spec/asciidoctor/rfc/v2/crossref_spec.rb +205 -0
  42. data/spec/asciidoctor/rfc/v2/date_spec.rb +166 -0
  43. data/spec/asciidoctor/rfc/v2/dlist_spec.rb +108 -0
  44. data/spec/asciidoctor/rfc/v2/document_spec.rb +161 -0
  45. data/spec/asciidoctor/rfc/v2/example_spec.rb +50 -0
  46. data/spec/asciidoctor/rfc/v2/front_spec.rb +75 -0
  47. data/spec/asciidoctor/rfc/v2/image_spec.rb +81 -0
  48. data/spec/asciidoctor/rfc/v2/indexterm_spec.rb +66 -0
  49. data/spec/asciidoctor/rfc/v2/inline_formatting_spec.rb +177 -0
  50. data/spec/asciidoctor/rfc/v2/keyword_spec.rb +63 -0
  51. data/spec/asciidoctor/rfc/v2/listing_spec.rb +59 -0
  52. data/spec/asciidoctor/rfc/v2/literal_spec.rb +53 -0
  53. data/spec/asciidoctor/rfc/v2/olist_spec.rb +147 -0
  54. data/spec/asciidoctor/rfc/v2/paragraph_spec.rb +68 -0
  55. data/spec/asciidoctor/rfc/v2/preamble_spec.rb +140 -0
  56. data/spec/asciidoctor/rfc/v2/quote_spec.rb +24 -0
  57. data/spec/asciidoctor/rfc/v2/references_spec.rb +96 -0
  58. data/spec/asciidoctor/rfc/v2/section_spec.rb +260 -0
  59. data/spec/asciidoctor/rfc/v2/sidebar_spec.rb +32 -0
  60. data/spec/asciidoctor/rfc/v2/table_spec.rb +293 -0
  61. data/spec/asciidoctor/rfc/v2/ulist_spec.rb +96 -0
  62. data/spec/asciidoctor/rfc/v2/workgroup_spec.rb +60 -0
  63. data/spec/asciidoctor/rfc/v3/appendix_spec.rb +130 -0
  64. data/spec/asciidoctor/rfc/v3/area_spec.rb +63 -0
  65. data/spec/asciidoctor/rfc/v3/author_spec.rb +540 -0
  66. data/spec/asciidoctor/rfc/v3/comments_spec.rb +308 -0
  67. data/spec/asciidoctor/rfc/v3/crossref_spec.rb +269 -0
  68. data/spec/asciidoctor/rfc/v3/date_spec.rb +149 -0
  69. data/spec/asciidoctor/rfc/v3/dlist_spec.rb +121 -0
  70. data/spec/asciidoctor/rfc/v3/document_spec.rb +109 -0
  71. data/spec/asciidoctor/rfc/v3/example_spec.rb +34 -0
  72. data/spec/asciidoctor/rfc/v3/front_spec.rb +43 -0
  73. data/spec/asciidoctor/rfc/v3/image_spec.rb +81 -0
  74. data/spec/asciidoctor/rfc/v3/indexterm_spec.rb +69 -0
  75. data/spec/asciidoctor/rfc/v3/inline_formatting_spec.rb +319 -0
  76. data/spec/asciidoctor/rfc/v3/keyword_spec.rb +33 -0
  77. data/spec/asciidoctor/rfc/v3/link_spec.rb +34 -0
  78. data/spec/asciidoctor/rfc/v3/listing_spec.rb +59 -0
  79. data/spec/asciidoctor/rfc/v3/literal_spec.rb +51 -0
  80. data/spec/asciidoctor/rfc/v3/olist_spec.rb +168 -0
  81. data/spec/asciidoctor/rfc/v3/paragraph_spec.rb +73 -0
  82. data/spec/asciidoctor/rfc/v3/preamble_spec.rb +112 -0
  83. data/spec/asciidoctor/rfc/v3/quote_spec.rb +91 -0
  84. data/spec/asciidoctor/rfc/v3/references_spec.rb +147 -0
  85. data/spec/asciidoctor/rfc/v3/section_spec.rb +198 -0
  86. data/spec/asciidoctor/rfc/v3/series_info_spec.rb +151 -0
  87. data/spec/asciidoctor/rfc/v3/sidebar_spec.rb +30 -0
  88. data/spec/asciidoctor/rfc/v3/table_spec.rb +275 -0
  89. data/spec/asciidoctor/rfc/v3/ulist_spec.rb +74 -0
  90. data/spec/asciidoctor/rfc/v3/workgroup_spec.rb +33 -0
  91. data/spec/examples/davies-template-bare-06.adoc +361 -0
  92. data/spec/examples/davies-template-bare-06.xml.orig +426 -0
  93. data/spec/examples/example-v2.adoc +181 -0
  94. data/spec/examples/example-v2.xml +675 -0
  95. data/spec/examples/example-v3.adoc +185 -0
  96. data/spec/examples/example-v3.xml +1009 -0
  97. data/spec/examples/mib-doc-template-xml-06.adoc +596 -0
  98. data/spec/examples/mib-doc-template-xml-06.xml.orig +654 -0
  99. data/spec/examples/rfc1149.md +76 -0
  100. data/spec/examples/rfc1149.md.2.xml +94 -0
  101. data/spec/examples/rfc1149.md.3.xml +93 -0
  102. data/spec/examples/rfc1149.md.adoc +65 -0
  103. data/spec/examples/rfc2100.md +149 -0
  104. data/spec/examples/rfc2100.md.2.xml +169 -0
  105. data/spec/examples/rfc2100.md.3.xml +163 -0
  106. data/spec/examples/rfc2100.md.adoc +136 -0
  107. data/spec/examples/rfc3514.md +203 -0
  108. data/spec/examples/rfc3514.md.2.xml +238 -0
  109. data/spec/examples/rfc3514.md.3.xml +258 -0
  110. data/spec/examples/rfc3514.md.adoc +324 -0
  111. data/spec/examples/rfc5841.md +342 -0
  112. data/spec/examples/rfc5841.md.2.xml +393 -0
  113. data/spec/examples/rfc5841.md.3.xml +449 -0
  114. data/spec/examples/rfc5841.md.adoc +414 -0
  115. data/spec/examples/rfc6350.adoc +3499 -0
  116. data/spec/examples/rfc6350.bib +763 -0
  117. data/spec/examples/rfc748.md +79 -0
  118. data/spec/examples/rfc748.md.2.xml +116 -0
  119. data/spec/examples/rfc748.md.3.xml +109 -0
  120. data/spec/examples/rfc748.md.adoc +80 -0
  121. data/spec/examples/rfc7511.md +257 -0
  122. data/spec/examples/rfc7511.md.2.xml +300 -0
  123. data/spec/examples/rfc7511.md.3.xml +347 -0
  124. data/spec/examples/rfc7511.md.adoc +417 -0
  125. data/spec/spec_helper.rb +115 -5
  126. metadata +274 -9
  127. data/.hound.yml +0 -3
  128. data/README.md +0 -84
  129. data/lib/asciidoctor/rfc.rb +0 -7
  130. data/spec/asciidoctor-rfc/.keep +0 -0
@@ -0,0 +1,192 @@
1
+ module Asciidoctor
2
+ module RFC::V2
3
+ module Blocks
4
+ # Syntax:
5
+ # [discrete]
6
+ # == Section
7
+ def floating_title(node)
8
+ noko do |xml|
9
+ xml.t do |xml_t|
10
+ xml_t.spanx node.title, style: "strong"
11
+ end
12
+ end
13
+ end
14
+
15
+ # Syntax:
16
+ # [[id]]
17
+ # .Name
18
+ # [align=left|center|right,alt=alt_text,type] (optional)
19
+ # ....
20
+ # literal
21
+ # ....
22
+ def literal(node)
23
+ artwork_attributes = {
24
+ align: node.attr("align"),
25
+ type: node.attr("type"),
26
+ name: node.title,
27
+ alt: node.attr("alt"),
28
+ }
29
+
30
+ # NOTE: html escaping is performed by Nokogiri
31
+ artwork_content = node.lines.join("\n")
32
+
33
+ ret = noko do |xml|
34
+ if node.parent.context != :example
35
+ xml.figure do |xml_figure|
36
+ xml_figure.artwork artwork_content, **attr_code(artwork_attributes)
37
+ end
38
+ else
39
+ xml.artwork artwork_content, **attr_code(artwork_attributes)
40
+ end
41
+ end
42
+ ret
43
+ end
44
+
45
+ # Syntax:
46
+ # = Title
47
+ # Author
48
+ # :HEADER
49
+ #
50
+ # ABSTRACT
51
+ #
52
+ # NOTE: note
53
+ #
54
+ # [NOTE]
55
+ # .Title (in preamble)
56
+ # ====
57
+ # Content
58
+ # ====
59
+ #
60
+ # [NOTE] (in preamble)
61
+ # [NOTE,source=name] (in body)
62
+ # .Title
63
+ # ====
64
+ # Content
65
+ # ====
66
+ #
67
+ # @note admonitions within preamble are notes. Elsewhere, they are comments.
68
+ def admonition(node)
69
+ result = []
70
+ if node.parent.context == :preamble
71
+ if $seen_abstract
72
+ result << "</abstract>"
73
+ $seen_abstract = false
74
+ end
75
+
76
+ note_attributes = {
77
+ # default title provided: title is mandatory
78
+ title: (node.title.nil? ? "NOTE" : node.title),
79
+ }
80
+
81
+ note_contents = [paragraph1(node)].flatten.join("\n")
82
+
83
+ result << noko do |xml|
84
+ xml.note **attr_code(note_attributes) do |xml_note|
85
+ xml_note << note_contents
86
+ end
87
+ end
88
+ else
89
+ cref_attributes = {
90
+ anchor: node.id,
91
+ source: node.attr("source"),
92
+ }
93
+
94
+ # remove all formatting: cref content is pure text
95
+ cref_contents = flatten_rawtext(node)
96
+ cref_contents = [cref_contents].flatten.join("\n")
97
+ warn <<~WARNING_MESSAGE if node.blocks?
98
+ asciidoctor: WARNING: comment can not contain blocks of text in XML RFC:\n #{node.content}
99
+ WARNING_MESSAGE
100
+
101
+ result << noko do |xml|
102
+ if node.parent.context !~ /table|example|paragraph|section/
103
+ xml.t do |xml_t|
104
+ xml_t.cref **attr_code(cref_attributes) do |xml_cref|
105
+ xml_cref << cref_contents
106
+ end
107
+ end
108
+ else
109
+ xml.cref **attr_code(cref_attributes) do |xml_cref|
110
+ xml_cref << cref_contents
111
+ end
112
+ end
113
+ end
114
+ end
115
+ result
116
+ end
117
+
118
+ # Syntax:
119
+ # [[id]]
120
+ # .Title
121
+ # [align,alt,suppress-title]
122
+ # ====
123
+ # Example
124
+ # ====
125
+ def example(node)
126
+ figure_attributes = {
127
+ anchor: node.id,
128
+ align: node.attr("align"),
129
+ alt: node.alt,
130
+ title: node.title,
131
+ 'suppress-title': node.attr("suppress-title"),
132
+ # TODO: is 'suppress-title' the correct attribute name?
133
+ }
134
+ # TODO iref
135
+ seen_artwork = false
136
+ noko do |xml|
137
+ xml.figure **attr_code(figure_attributes) do |xml_figure|
138
+ node.blocks.each do |b|
139
+ case b.context
140
+ when :listing, :image, :literal
141
+ xml_figure << send(b.context, b).join("\n")
142
+ seen_artwork = true
143
+ else
144
+ # we want to see the para text, not its <t> container
145
+ if seen_artwork
146
+ xml_figure.postamble do |postamble|
147
+ postamble << b.content
148
+ end
149
+ else
150
+ xml_figure.preamble do |preamble|
151
+ preamble << b.content
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
159
+
160
+ # Syntax:
161
+ # .name
162
+ # [source,type,src=uri] (src is mutually exclusive with listing content) (v3)
163
+ # [source,type,src=uri,align,alt] (src is mutually exclusive with listing content) (v2)
164
+ # ----
165
+ # code
166
+ # ----
167
+ def listing(node)
168
+ sourcecode_attributes = {
169
+ align: node.attr("align"),
170
+ alt: node.alt,
171
+ name: node.title,
172
+ type: node.attr("language"),
173
+ src: node.attr("src"),
174
+ }
175
+
176
+ # NOTE: html escaping is performed by Nokogiri
177
+ sourcecode_content =
178
+ sourcecode_attributes[:src].nil? ? node.lines.join("\n") : ""
179
+
180
+ noko do |xml|
181
+ if node.parent.context != :example
182
+ xml.figure do |xml_figure|
183
+ xml_figure.artwork sourcecode_content, **attr_code(sourcecode_attributes)
184
+ end
185
+ else
186
+ xml.artwork sourcecode_content, **attr_code(sourcecode_attributes)
187
+ end
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,64 @@
1
+ require "asciidoctor"
2
+
3
+ require "asciidoctor/rfc/version"
4
+ require "asciidoctor/rfc/common/base"
5
+ require "asciidoctor/rfc/common/front"
6
+ require "asciidoctor/rfc/v2/base"
7
+ require "asciidoctor/rfc/v2/blocks"
8
+ require "asciidoctor/rfc/v2/front"
9
+ require "asciidoctor/rfc/v2/inline_anchor"
10
+ require "asciidoctor/rfc/v2/lists"
11
+ require "asciidoctor/rfc/v2/table"
12
+ require "asciidoctor/rfc/v2/validate"
13
+
14
+ module Asciidoctor
15
+ module RFC::V2
16
+ # A {Converter} implementation that generates RFC XML 2 output, a format used to
17
+ # format RFC proposals (https://tools.ietf.org/html/rfc7749)
18
+ #
19
+ # Features drawn from https://github.com/miekg/mmark/wiki/Syntax and
20
+ # https://github.com/riboseinc/rfc2md
21
+ class Converter
22
+ include ::Asciidoctor::Converter
23
+ include ::Asciidoctor::Writer
24
+
25
+ include ::Asciidoctor::RFC::Common::Base
26
+ include ::Asciidoctor::RFC::Common::Front
27
+ include ::Asciidoctor::RFC::V2::Base
28
+ include ::Asciidoctor::RFC::V2::Blocks
29
+ include ::Asciidoctor::RFC::V2::Front
30
+ include ::Asciidoctor::RFC::V2::InlineAnchor
31
+ include ::Asciidoctor::RFC::V2::Lists
32
+ include ::Asciidoctor::RFC::V2::Table
33
+ include ::Asciidoctor::RFC::V2::Validate
34
+
35
+ register_for "rfc2"
36
+
37
+ $seen_back_matter = false
38
+ $seen_abstract = false
39
+ $xreftext = {}
40
+
41
+ def initialize(backend, opts)
42
+ super
43
+ basebackend "html"
44
+ outfilesuffix ".xml"
45
+ end
46
+
47
+ # alias_method :pass, :content
48
+ alias_method :embedded, :content
49
+ alias_method :sidebar, :content
50
+ alias_method :audio, :skip
51
+ alias_method :colist, :skip
52
+ alias_method :page_break, :skip
53
+ alias_method :thematic_break, :skip
54
+ alias_method :video, :skip
55
+ alias_method :inline_button, :skip
56
+ alias_method :inline_kbd, :skip
57
+ alias_method :inline_menu, :skip
58
+ alias_method :inline_image, :skip
59
+
60
+ alias_method :stem, :literal
61
+ alias_method :quote, :paragraph
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,69 @@
1
+ module Asciidoctor
2
+ module RFC::V2
3
+ module Front
4
+ # Syntax:
5
+ # = Title
6
+ # Author
7
+ # :METADATA
8
+ def front(node, xml)
9
+ xml.front do |xml_front|
10
+ title node, xml_front
11
+ author node, xml_front
12
+ date node, xml_front
13
+ area node, xml_front
14
+ workgroup node, xml_front
15
+ keyword node, xml_front
16
+ end
17
+ end
18
+
19
+ def organization(node, suffix, xml)
20
+ organization = node.attr("organization#{suffix}")
21
+ organization_abbrev = node.attr("organization_abbrev#{suffix}")
22
+ organization_attributes = {
23
+ abbrev: organization_abbrev,
24
+ }
25
+ unless organization.nil?
26
+ xml.organization **attr_code(organization_attributes) do |org|
27
+ org << organization
28
+ end
29
+ end
30
+ end
31
+
32
+ def address(node, suffix, xml)
33
+ email = node.attr("email#{suffix}")
34
+ facsimile = node.attr("fax#{suffix}")
35
+ phone = node.attr("phone#{suffix}")
36
+ street = node.attr("street#{suffix}")
37
+ uri = node.attr("uri#{suffix}")
38
+
39
+ # If there is no provided elements for address, don't show it
40
+ return unless [email, facsimile, phone, street, uri].any?
41
+
42
+ # https://tools.ietf.org/html/rfc7749#section-2.27
43
+ # Note that at least one <street> element needs to be present;
44
+ # however, formatters will handle empty values just fine.
45
+ street = street ? street.split("\\ ") : [""]
46
+
47
+ xml.address do |xml_address|
48
+ xml_address.postal do |xml_postal|
49
+ city = node.attr("city#{suffix}")
50
+ code = node.attr("code#{suffix}")
51
+ country = node.attr("country#{suffix}")
52
+ region = node.attr("region#{suffix}")
53
+
54
+ street.each { |st| xml_postal.street { |s| s << st } }
55
+ xml_postal.city { |c| c << city } unless city.nil?
56
+ xml_postal.region { |r| r << region } unless region.nil?
57
+ xml_postal.code { |c| c << code } unless code.nil?
58
+ xml_postal.country { |c| c << country } unless country.nil?
59
+ end
60
+
61
+ xml_address.phone { |p| p << phone } unless phone.nil?
62
+ xml_address.facsimile { |f| f << facsimile } unless facsimile.nil?
63
+ xml_address.email { |e| e << email } unless email.nil?
64
+ xml_address.uri { |u| u << uri } unless uri.nil?
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,102 @@
1
+ module Asciidoctor
2
+ module RFC::V2
3
+ module InlineAnchor
4
+ def inline_anchor(node)
5
+ case node.type
6
+ when :xref
7
+ inline_anchor_xref node
8
+ when :link
9
+ inline_anchor_link node
10
+ when :bibref
11
+ inline_anchor_bibref node
12
+ when :ref
13
+ inline_anchor_ref node
14
+ else
15
+ warn %(asciidoctor: WARNING: unknown anchor type: #{node.type.inspect})
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def inline_anchor_xref(node)
22
+ if node.text =~ /^\S+ (of|comma|parens|bare)\b/
23
+ # <<crossreference#fragment,section (of|comma|parens|bare): text>> = relref:
24
+ # render equivalent in v2
25
+ matched = /(?<section>\S+)\s+(?<format>[a-z]+)(: )?(?<text>.*)$/.match node.text
26
+
27
+ target = node.target.gsub(/\..*$/, "").gsub(/^#/, "")
28
+ reftarget = target
29
+ reftarget = "#{target}##{node.attributes['fragment']}" unless node.attributes["path"].nil?
30
+
31
+ xref_contents = case matched[:format]
32
+ when "of"
33
+ "Section #{matched[:section]} of [#{target}]"
34
+ when "comma"
35
+ "[#{target}], Section #{matched[:section]}"
36
+ when "parens"
37
+ "[#{target}] (Section #{matched[:section]})"
38
+ when "bare"
39
+ matched[:section]
40
+ else
41
+ "Section #{matched[:section]} of #{target}"
42
+ end
43
+ unless matched[:text].empty?
44
+ xref_contents = "#{xref_contents}: #{matched[:text]}"
45
+ end
46
+
47
+ xref_attributes = {
48
+ target: reftarget,
49
+ }.reject { |_, value| value.nil? }
50
+
51
+ else
52
+
53
+ matched = /^format=(?<format>counter|title|none|default):\s*(?<text>.*)$/.match node.text
54
+ xref_contents = matched.nil? ? node.text : matched[:text]
55
+ matched ||= {}
56
+
57
+ xref_attributes = {
58
+ target: node.target.gsub(/^#/, ""),
59
+ format: matched[:format],
60
+ align: node.attr("align"),
61
+ }
62
+ end
63
+
64
+ noko do |xml|
65
+ xml.xref xref_contents, **attr_code(xref_attributes)
66
+ end.join
67
+ end
68
+
69
+ def inline_anchor_link(node)
70
+ eref_contents = node.target == node.text ? nil : node.text
71
+
72
+ eref_attributes = {
73
+ target: node.target,
74
+ }
75
+
76
+ noko do |xml|
77
+ xml.eref eref_contents, **attr_code(eref_attributes)
78
+ end.join
79
+ end
80
+
81
+ def inline_anchor_bibref(node)
82
+ unless node.xreftext.nil?
83
+ x = node.xreftext.gsub(/^\[(.+)\]$/, "\\1")
84
+ if node.id != x
85
+ $xreftext[node.id] = x
86
+ end
87
+ end
88
+ # NOTE technically node.text should be node.reftext, but subs have already been applied to text
89
+ %(<bibanchor="#{node.id}">) # will convert to anchor attribute upstream
90
+ end
91
+
92
+ def inline_anchor_ref(node)
93
+ # If this is within referencegroup, output as bibanchor anyway
94
+ if $processing_reflist
95
+ %(<bibanchor="#{node.id}">) # will convert to anchor attribute upstream
96
+ else
97
+ warn %(asciidoctor: WARNING: anchor "#{node.id}" is not in a place where XML RFC will recognise it as an anchor attribute)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,134 @@
1
+ module Asciidoctor
2
+ module RFC::V2
3
+ module Lists
4
+ # Syntax:
5
+ # * A
6
+ # * B
7
+ def ulist(node)
8
+ noko { |xml| wrap_list :ulist_naked, node, xml }
9
+ end
10
+
11
+ OLIST_TYPES = Hash.new("numbers").merge(
12
+ arabic: "numbers",
13
+ # decimal: "1", # not supported
14
+ loweralpha: "letters",
15
+ # lowergreek: "lower-greek", # not supported
16
+ lowerroman: "format %i.",
17
+ upperalpha: "format %C.",
18
+ upperroman: "format %I.",
19
+ ).freeze
20
+
21
+ # Syntax:
22
+ # [counter=token] (optional)
23
+ # . A
24
+ # . B
25
+ def olist(node)
26
+ noko { |xml| wrap_list :olist_naked, node, xml }
27
+ end
28
+
29
+ # Syntax:
30
+ # [hangIndent=n] (optional)
31
+ # A:: B
32
+ # C:: D
33
+ def dlist(node)
34
+ noko { |xml| wrap_list :dlist_naked, node, xml }
35
+ end
36
+
37
+ private
38
+
39
+ def wrap_list(method_name, node, xml)
40
+ if node.parent.context !~ /paragraph|list_item/
41
+ xml.t do |xml_t|
42
+ send method_name, node, xml_t
43
+ end
44
+ else
45
+ send method_name, node, xml
46
+ end
47
+ end
48
+
49
+ def ulist_naked(node, xml)
50
+ style = "symbols"
51
+ style = "empty" if node.attr("style") == "empty"
52
+ style = "empty" if node.option?("empty")
53
+ list_attributes = {
54
+ style: style,
55
+ hangIndent: node.attr("hang-indent"),
56
+ }
57
+
58
+ xml.list **attr_code(list_attributes) do |xml_list|
59
+ node.items.each do |item|
60
+ t_attributes = {
61
+ anchor: nil,
62
+ }
63
+
64
+ xml_list.t **attr_code(t_attributes) do |xml_t|
65
+ xml_t << item.text
66
+ xml_t << para_to_vspace(item.content) if item.blocks?
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ def olist_naked(node, xml)
73
+ style = OLIST_TYPES[node.style.to_sym]
74
+ style = "empty" if node.attr("style") == "empty"
75
+ style = "format #{node.attr('format')}" unless node.attr("format").nil?
76
+ list_attributes = {
77
+ hangIndent: node.attr("hang-indent"),
78
+ counter: node.attr("counter"),
79
+ style: style,
80
+ }
81
+
82
+ xml.list **attr_code(list_attributes) do |xml_list|
83
+ node.items.each do |item|
84
+ t_attributes = {
85
+ anchor: item.id,
86
+ }
87
+
88
+ xml_list.t **attr_code(t_attributes) do |xml_t|
89
+ xml_t << item.text
90
+ xml_t << para_to_vspace(item.content) if item.blocks?
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ def dlist_naked(node, xml)
97
+ style = "hanging"
98
+ style = "empty" if node.attr("style") == "empty"
99
+ list_attributes = {
100
+ hangIndent: node.attr("hang-indent"),
101
+ style: style,
102
+ }
103
+
104
+ xml.list **attr_code(list_attributes) do |xml_list|
105
+ node.items.each do |terms, dd|
106
+ # all but last term have empty dd
107
+ terms.each_with_index do |term, idx|
108
+ t_attributes = {
109
+ hangText: term.text,
110
+ }
111
+
112
+ if idx < terms.size - 1
113
+ xml_list.t **attr_code(t_attributes)
114
+ else
115
+ xml_list.t **attr_code(t_attributes) do |xml_t|
116
+ if !dd.nil?
117
+ if dd.blocks?
118
+ xml_t << dd.text if dd.text?
119
+ # v2 does not support multi paragraph list items;
120
+ # vspace is used to emulate them
121
+ xml_t << para_to_vspace(dd.content)
122
+ else
123
+ xml_t << dd.text
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end