coradoc-adoc 2.0.8 → 2.0.9
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.
- checksums.yaml +4 -4
- data/lib/coradoc/asciidoc/model/list/definition_item.rb +6 -0
- data/lib/coradoc/asciidoc/parser/list.rb +18 -13
- data/lib/coradoc/asciidoc/serializer/serializers/list/definition_item.rb +21 -1
- data/lib/coradoc/asciidoc/transform/element_transformers/list_transformer.rb +6 -0
- data/lib/coradoc/asciidoc/transform/from_core_model.rb +13 -6
- data/lib/coradoc/asciidoc/transformer/list_rules.rb +54 -11
- data/lib/coradoc/asciidoc/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ed044cb4af9fd1e18a9cb2c34ddc5c322d801fd24962058a5b6ec55e7a3a9c43
|
|
4
|
+
data.tar.gz: 751978667c8663723085bf0a79d5908cf4a3368e827366a1d703c2602671fcb3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: caf485068682d2b714078ff0ec934601a35498fb546d5a97677cbae3b08aa237b598768ca7bafb3f1075868ae5524a01ab20a9fede25d2e4a374d8e67390baca
|
|
7
|
+
data.tar.gz: cf951b3c317c1a40ac4b2d170dba913b4a83d375aa60a8a7a8a16e47865d3ebe7609b61630436d90726fe682e3d78412beadac3ced3589bf642b865ad7250628
|
|
@@ -32,6 +32,12 @@ module Coradoc
|
|
|
32
32
|
attribute :id, :string
|
|
33
33
|
attribute :terms, Coradoc::AsciiDoc::Model::Term, collection: true
|
|
34
34
|
attribute :contents, Coradoc::AsciiDoc::Model::TextElement, collection: true
|
|
35
|
+
attribute :delimiter, :string, default: -> { '::' }
|
|
36
|
+
attribute :nested,
|
|
37
|
+
Coradoc::AsciiDoc::Model::Base,
|
|
38
|
+
polymorphic: [Coradoc::AsciiDoc::Model::List::Definition],
|
|
39
|
+
collection: true,
|
|
40
|
+
initialize_empty: true
|
|
35
41
|
|
|
36
42
|
def to_adoc(delimiter: '')
|
|
37
43
|
Coradoc::AsciiDoc::Serializer.serialize(self, delimiter: delimiter)
|
|
@@ -29,10 +29,10 @@ module Coradoc
|
|
|
29
29
|
attrs >> r.repeat(1).as(:unordered)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def definition_list(
|
|
32
|
+
def definition_list(_delimiter = nil)
|
|
33
33
|
(attribute_list >> newline).maybe >>
|
|
34
|
-
dlist_item
|
|
35
|
-
dlist_item
|
|
34
|
+
dlist_item.repeat(1).as(:definition_list) >>
|
|
35
|
+
dlist_item.absent?
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def list_marker(nesting_level = 1)
|
|
@@ -98,27 +98,32 @@ module Coradoc
|
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
def dlist_delimiter
|
|
101
|
-
(
|
|
101
|
+
(
|
|
102
|
+
(str(':::::') >> match(':').absent?) |
|
|
103
|
+
(str('::::') >> match(':').absent?) |
|
|
104
|
+
(str(':::') >> match(':').absent?) |
|
|
105
|
+
(str('::') >> match(':').absent?) |
|
|
106
|
+
str(';;')
|
|
102
107
|
).as(:delimiter)
|
|
103
108
|
end
|
|
104
109
|
|
|
105
|
-
def dlist_term(_delimiter)
|
|
106
|
-
|
|
107
|
-
match("[^\n
|
|
108
|
-
|
|
109
|
-
).as(:dlist_term) >> dlist_delimiter
|
|
110
|
+
def dlist_term(_delimiter = nil)
|
|
111
|
+
term_chars =
|
|
112
|
+
(dlist_delimiter.absent? >> match("[^\n]")).repeat(1)
|
|
113
|
+
.as(:text)
|
|
114
|
+
(element_id_inline.maybe >> term_chars).as(:dlist_term) >> dlist_delimiter
|
|
110
115
|
end
|
|
111
116
|
|
|
112
117
|
def dlist_definition
|
|
113
|
-
text
|
|
118
|
+
text
|
|
114
119
|
.as(:definition) >> line_ending >> empty_line.repeat(0)
|
|
115
120
|
end
|
|
116
121
|
|
|
117
|
-
def dlist_item(
|
|
118
|
-
(((dlist_term
|
|
122
|
+
def dlist_item(_delimiter = nil)
|
|
123
|
+
(((dlist_term.as(:terms).repeat(1) >> line_ending >>
|
|
119
124
|
empty_line.repeat(0)).repeat(1) >>
|
|
120
125
|
dlist_definition) |
|
|
121
|
-
(dlist_term
|
|
126
|
+
(dlist_term.repeat(1, 1).as(:terms) >> space >>
|
|
122
127
|
dlist_definition)
|
|
123
128
|
).as(:definition_list_item)
|
|
124
129
|
end
|
|
@@ -8,7 +8,8 @@ module Coradoc
|
|
|
8
8
|
class DefinitionItem < Base
|
|
9
9
|
def to_adoc(model, options_or_context = {})
|
|
10
10
|
context = normalize_context(options_or_context)
|
|
11
|
-
delimiter =
|
|
11
|
+
delimiter = model.delimiter.to_s
|
|
12
|
+
delimiter = context.option(:delimiter, '::') if delimiter.empty?
|
|
12
13
|
_anchor = model.anchor.nil? ? '' : serialize_child(model.anchor, context)
|
|
13
14
|
content = +''
|
|
14
15
|
|
|
@@ -26,6 +27,25 @@ module Coradoc
|
|
|
26
27
|
|
|
27
28
|
d = model.contents ? serialize_children(model.contents, context) : ''
|
|
28
29
|
content << "#{d}\n"
|
|
30
|
+
|
|
31
|
+
nested_delimiter = "#{delimiter}:"
|
|
32
|
+
Array(model.nested).each do |nested_list|
|
|
33
|
+
next unless nested_list.is_a?(Coradoc::AsciiDoc::Model::List::Definition)
|
|
34
|
+
|
|
35
|
+
nested_list.items.each do |nested_item|
|
|
36
|
+
content << serialize_with_options(nested_item, delimiter: nested_delimiter)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
content
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def serialize_with_options(child, options = {})
|
|
46
|
+
serializer_class = ElementRegistry.lookup(child.class)
|
|
47
|
+
serializer = serializer_class.new
|
|
48
|
+
serializer.to_adoc(child, options)
|
|
29
49
|
end
|
|
30
50
|
end
|
|
31
51
|
end
|
|
@@ -48,6 +48,12 @@ module Coradoc
|
|
|
48
48
|
definition_children: def_children
|
|
49
49
|
)
|
|
50
50
|
di.id = item.id if item.id
|
|
51
|
+
|
|
52
|
+
nested_adoc = Array(item.nested).find do |n|
|
|
53
|
+
n.is_a?(Coradoc::AsciiDoc::Model::List::Definition) && n.items.any?
|
|
54
|
+
end
|
|
55
|
+
di.nested = transform_list(nested_adoc, 'definition') if nested_adoc
|
|
56
|
+
|
|
51
57
|
di
|
|
52
58
|
end
|
|
53
59
|
|
|
@@ -298,22 +298,29 @@ module Coradoc
|
|
|
298
298
|
)
|
|
299
299
|
end
|
|
300
300
|
|
|
301
|
-
def transform_definition_list(definition_list)
|
|
301
|
+
def transform_definition_list(definition_list, depth = 1)
|
|
302
|
+
delimiter = ':' * (depth + 1)
|
|
302
303
|
items = Array(definition_list.items).map do |item|
|
|
303
|
-
transform_definition_item(item)
|
|
304
|
+
transform_definition_item(item, depth)
|
|
304
305
|
end
|
|
305
|
-
Coradoc::AsciiDoc::Model::List::Definition.new(items: items)
|
|
306
|
+
list = Coradoc::AsciiDoc::Model::List::Definition.new(items: items)
|
|
307
|
+
list.delimiter = delimiter
|
|
308
|
+
list
|
|
306
309
|
end
|
|
307
310
|
|
|
308
|
-
def transform_definition_item(item)
|
|
311
|
+
def transform_definition_item(item, depth = 1)
|
|
312
|
+
delimiter = ':' * (depth + 1)
|
|
309
313
|
term = Coradoc::AsciiDoc::Model::Term.new(term: item.term.to_s)
|
|
310
314
|
contents = Array(item.definitions).map do |defn|
|
|
311
315
|
Coradoc::AsciiDoc::Model::TextElement.new(content: defn.to_s)
|
|
312
316
|
end
|
|
313
|
-
Coradoc::AsciiDoc::Model::List::DefinitionItem.new(
|
|
317
|
+
di = Coradoc::AsciiDoc::Model::List::DefinitionItem.new(
|
|
314
318
|
terms: [term],
|
|
315
|
-
contents: contents
|
|
319
|
+
contents: contents,
|
|
320
|
+
delimiter: delimiter
|
|
316
321
|
)
|
|
322
|
+
di.nested << transform_definition_list(item.nested, depth + 1) if item.nested&.items&.any?
|
|
323
|
+
di
|
|
317
324
|
end
|
|
318
325
|
|
|
319
326
|
def transform_toc(_toc)
|
|
@@ -5,6 +5,42 @@ module Coradoc
|
|
|
5
5
|
class Transformer < Parslet::Transform
|
|
6
6
|
# Module containing list transformation rules
|
|
7
7
|
module ListRules
|
|
8
|
+
class << self
|
|
9
|
+
def build_dlist_tree(items)
|
|
10
|
+
root = Model::List::Definition.new(items: [])
|
|
11
|
+
stack = [[root, 0]]
|
|
12
|
+
|
|
13
|
+
items.each do |item|
|
|
14
|
+
depth = dlist_depth(item.delimiter)
|
|
15
|
+
stack.pop while stack.last[1] >= depth
|
|
16
|
+
|
|
17
|
+
stack.last[0].items << item
|
|
18
|
+
nested_list = Model::List::Definition.new(items: [])
|
|
19
|
+
item.nested << nested_list
|
|
20
|
+
stack.push([nested_list, depth])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
prune_empty_nested(root)
|
|
24
|
+
root
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def dlist_depth(delimiter)
|
|
28
|
+
delim = delimiter.to_s
|
|
29
|
+
return 1 if delim == ';;' || delim.empty?
|
|
30
|
+
|
|
31
|
+
[delim.count(':') - 1, 1].max
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def prune_empty_nested(list)
|
|
35
|
+
list.items.each do |item|
|
|
36
|
+
item.nested.select! do |n|
|
|
37
|
+
n.is_a?(Model::List::Definition) && n.items.any?
|
|
38
|
+
end
|
|
39
|
+
item.nested.each { |n| prune_empty_nested(n) }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
8
44
|
def self.apply(transformer_class)
|
|
9
45
|
transformer_class.class_eval do
|
|
10
46
|
# List item
|
|
@@ -68,7 +104,7 @@ module Coradoc
|
|
|
68
104
|
end
|
|
69
105
|
|
|
70
106
|
# Definition list term (with optional anchor)
|
|
71
|
-
rule(dlist_term: subtree(:term_data), delimiter: simple(:
|
|
107
|
+
rule(dlist_term: subtree(:term_data), delimiter: simple(:delim)) do
|
|
72
108
|
case term_data
|
|
73
109
|
when Hash
|
|
74
110
|
text = term_data[:text]
|
|
@@ -76,11 +112,11 @@ module Coradoc
|
|
|
76
112
|
text = text.content.to_s if text.is_a?(Model::TextElement)
|
|
77
113
|
id = term_data[:id]
|
|
78
114
|
id = id.to_s if id.is_a?(Parslet::Slice)
|
|
79
|
-
{ text: text.to_s, id: id }
|
|
115
|
+
{ text: text.to_s, id: id, delimiter: delim.to_s }
|
|
80
116
|
when Model::TextElement
|
|
81
|
-
{ text: term_data.content.to_s, id: term_data.id }
|
|
117
|
+
{ text: term_data.content.to_s, id: term_data.id, delimiter: delim.to_s }
|
|
82
118
|
else
|
|
83
|
-
{ text: term_data.to_s, id: nil }
|
|
119
|
+
{ text: term_data.to_s, id: nil, delimiter: delim.to_s }
|
|
84
120
|
end
|
|
85
121
|
end
|
|
86
122
|
|
|
@@ -95,13 +131,15 @@ module Coradoc
|
|
|
95
131
|
t.is_a?(Hash) ? t[:text].to_s : t.to_s
|
|
96
132
|
end
|
|
97
133
|
item_id = nil
|
|
134
|
+
item_delim = '::'
|
|
98
135
|
terms.each do |t|
|
|
99
|
-
next unless t.is_a?(Hash)
|
|
136
|
+
next unless t.is_a?(Hash)
|
|
100
137
|
|
|
101
|
-
item_id = t[:id].to_s
|
|
102
|
-
|
|
138
|
+
item_id = t[:id].to_s if t[:id]
|
|
139
|
+
item_delim = t[:delimiter].to_s if t[:delimiter]
|
|
103
140
|
end
|
|
104
|
-
Model::List::DefinitionItem.new(terms: term_strings, contents: contents,
|
|
141
|
+
Model::List::DefinitionItem.new(terms: term_strings, contents: contents,
|
|
142
|
+
id: item_id, delimiter: item_delim)
|
|
105
143
|
end
|
|
106
144
|
|
|
107
145
|
# Definition list item with hash terms (single term case)
|
|
@@ -111,6 +149,7 @@ module Coradoc
|
|
|
111
149
|
data = item_data.is_a?(Hash) ? item_data : { terms: Array(item_data), definition: '' }
|
|
112
150
|
|
|
113
151
|
item_id = nil
|
|
152
|
+
item_delim = '::'
|
|
114
153
|
terms_data = data[:terms]
|
|
115
154
|
definition = data[:definition].to_s
|
|
116
155
|
|
|
@@ -118,17 +157,19 @@ module Coradoc
|
|
|
118
157
|
case t
|
|
119
158
|
when Hash
|
|
120
159
|
item_id ||= t[:id].to_s if t[:id]
|
|
160
|
+
item_delim = t[:delimiter].to_s if t[:delimiter]
|
|
121
161
|
t[:text].to_s
|
|
122
162
|
else
|
|
123
163
|
t.to_s
|
|
124
164
|
end
|
|
125
165
|
end
|
|
126
166
|
|
|
127
|
-
Model::List::DefinitionItem.new(terms: terms, contents: definition,
|
|
167
|
+
Model::List::DefinitionItem.new(terms: terms, contents: definition,
|
|
168
|
+
id: item_id, delimiter: item_delim)
|
|
128
169
|
end
|
|
129
170
|
|
|
130
171
|
rule(definition_list: sequence(:list_items)) do
|
|
131
|
-
|
|
172
|
+
ListRules.build_dlist_tree(list_items)
|
|
132
173
|
end
|
|
133
174
|
|
|
134
175
|
# Definition list with attribute_list (e.g., [%key])
|
|
@@ -136,7 +177,9 @@ module Coradoc
|
|
|
136
177
|
attribute_list: simple(:attribute_list),
|
|
137
178
|
definition_list: sequence(:list_items)
|
|
138
179
|
) do
|
|
139
|
-
|
|
180
|
+
tree = ListRules.build_dlist_tree(list_items)
|
|
181
|
+
tree.attrs = attribute_list if attribute_list
|
|
182
|
+
tree
|
|
140
183
|
end
|
|
141
184
|
end
|
|
142
185
|
end
|