asciidoctor-pdf 1.5.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.adoc +22 -0
- data/NOTICE.adoc +76 -0
- data/README.adoc +263 -0
- data/Rakefile +78 -0
- data/bin/asciidoctor-pdf +15 -0
- data/bin/optimize-pdf +63 -0
- data/data/fonts/LICENSE-liberation-fonts-2.00.1 +102 -0
- data/data/fonts/LICENSE-mplus-testflight-58 +16 -0
- data/data/fonts/LICENSE-noto-fonts-2014-01-30 +201 -0
- data/data/fonts/liberationmono-bold-latin.ttf +0 -0
- data/data/fonts/liberationmono-bolditalic-latin.ttf +0 -0
- data/data/fonts/liberationmono-italic-latin.ttf +0 -0
- data/data/fonts/liberationmono-regular-latin.ttf +0 -0
- data/data/fonts/mplus1mn-bold-ascii.ttf +0 -0
- data/data/fonts/mplus1mn-bolditalic-ascii.ttf +0 -0
- data/data/fonts/mplus1mn-italic-ascii.ttf +0 -0
- data/data/fonts/mplus1mn-regular-ascii-conums.ttf +0 -0
- data/data/fonts/mplus1p-bold-latin.ttf +0 -0
- data/data/fonts/mplus1p-light-latin.ttf +0 -0
- data/data/fonts/mplus1p-regular-latin.ttf +0 -0
- data/data/fonts/mplus1p-regular-multilingual.ttf +0 -0
- data/data/fonts/notoserif-bold-latin.ttf +0 -0
- data/data/fonts/notoserif-bolditalic-latin.ttf +0 -0
- data/data/fonts/notoserif-italic-latin.ttf +0 -0
- data/data/fonts/notoserif-regular-latin.ttf +0 -0
- data/data/themes/asciidoctor-theme.yml +174 -0
- data/data/themes/default-theme.yml +182 -0
- data/examples/chronicles.adoc +429 -0
- data/examples/chronicles.pdf +0 -0
- data/examples/example-pdf-screenshot.png +0 -0
- data/examples/example.adoc +27 -0
- data/examples/example.pdf +0 -0
- data/examples/sample-title-logo.jpg +0 -0
- data/examples/wolpertinger.jpg +0 -0
- data/lib/asciidoctor-pdf.rb +3 -0
- data/lib/asciidoctor-pdf/asciidoctor_ext.rb +1 -0
- data/lib/asciidoctor-pdf/asciidoctor_ext/section.rb +26 -0
- data/lib/asciidoctor-pdf/converter.rb +1365 -0
- data/lib/asciidoctor-pdf/core_ext/array.rb +5 -0
- data/lib/asciidoctor-pdf/core_ext/ostruct.rb +9 -0
- data/lib/asciidoctor-pdf/implicit_header_processor.rb +59 -0
- data/lib/asciidoctor-pdf/pdfmarks.rb +30 -0
- data/lib/asciidoctor-pdf/prawn_ext.rb +3 -0
- data/lib/asciidoctor-pdf/prawn_ext/coderay_encoder.rb +94 -0
- data/lib/asciidoctor-pdf/prawn_ext/extensions.rb +529 -0
- data/lib/asciidoctor-pdf/prawn_ext/formatted_text/formatter.rb +29 -0
- data/lib/asciidoctor-pdf/prawn_ext/formatted_text/parser.rb +1012 -0
- data/lib/asciidoctor-pdf/prawn_ext/formatted_text/parser.treetop +115 -0
- data/lib/asciidoctor-pdf/prawn_ext/formatted_text/transform.rb +178 -0
- data/lib/asciidoctor-pdf/roman_numeral.rb +107 -0
- data/lib/asciidoctor-pdf/theme_loader.rb +103 -0
- data/lib/asciidoctor-pdf/version.rb +5 -0
- metadata +248 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'treetop'
|
2
|
+
require 'set'
|
3
|
+
require_relative 'parser'
|
4
|
+
require_relative 'transform'
|
5
|
+
|
6
|
+
module Asciidoctor
|
7
|
+
module Prawn
|
8
|
+
class FormattedTextFormatter
|
9
|
+
FormattingSnifferPattern = /[<&]/
|
10
|
+
|
11
|
+
def initialize options = {}
|
12
|
+
@parser = FormattedTextParser.new
|
13
|
+
@transform = FormattedTextTransform.new merge_adjacent_text_nodes: true, theme: options[:theme]
|
14
|
+
end
|
15
|
+
|
16
|
+
def format string, *args
|
17
|
+
options = args.first || {}
|
18
|
+
string = string.tr_s("\n", ' ') if options[:normalize]
|
19
|
+
return [text: string] unless string.match(FormattingSnifferPattern)
|
20
|
+
if (parsed = @parser.parse(string)) == nil
|
21
|
+
warn %(Failed to parse formatted text: #{string})
|
22
|
+
[text: string]
|
23
|
+
else
|
24
|
+
@transform.apply(parsed.content)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,1012 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module Asciidoctor
|
5
|
+
module Prawn
|
6
|
+
module FormattedText
|
7
|
+
include Treetop::Runtime
|
8
|
+
|
9
|
+
def root
|
10
|
+
@root ||= :text
|
11
|
+
end
|
12
|
+
|
13
|
+
def _nt_text
|
14
|
+
start_index = index
|
15
|
+
if node_cache[:text].has_key?(index)
|
16
|
+
cached = node_cache[:text][index]
|
17
|
+
if cached
|
18
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
19
|
+
@index = cached.interval.end
|
20
|
+
end
|
21
|
+
return cached
|
22
|
+
end
|
23
|
+
|
24
|
+
r0 = _nt_complex
|
25
|
+
|
26
|
+
node_cache[:text][start_index] = r0
|
27
|
+
|
28
|
+
r0
|
29
|
+
end
|
30
|
+
|
31
|
+
module Complex0
|
32
|
+
def content
|
33
|
+
elements.map {|e| e.content }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def _nt_complex
|
38
|
+
start_index = index
|
39
|
+
if node_cache[:complex].has_key?(index)
|
40
|
+
cached = node_cache[:complex][index]
|
41
|
+
if cached
|
42
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
43
|
+
@index = cached.interval.end
|
44
|
+
end
|
45
|
+
return cached
|
46
|
+
end
|
47
|
+
|
48
|
+
s0, i0 = [], index
|
49
|
+
loop do
|
50
|
+
i1 = index
|
51
|
+
r2 = _nt_cdata
|
52
|
+
if r2
|
53
|
+
r1 = r2
|
54
|
+
else
|
55
|
+
r3 = _nt_element
|
56
|
+
if r3
|
57
|
+
r1 = r3
|
58
|
+
else
|
59
|
+
r4 = _nt_entity
|
60
|
+
if r4
|
61
|
+
r1 = r4
|
62
|
+
else
|
63
|
+
@index = i1
|
64
|
+
r1 = nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
if r1
|
69
|
+
s0 << r1
|
70
|
+
else
|
71
|
+
break
|
72
|
+
end
|
73
|
+
end
|
74
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
75
|
+
r0.extend(Complex0)
|
76
|
+
|
77
|
+
node_cache[:complex][start_index] = r0
|
78
|
+
|
79
|
+
r0
|
80
|
+
end
|
81
|
+
|
82
|
+
module Element0
|
83
|
+
def start_tag
|
84
|
+
elements[0]
|
85
|
+
end
|
86
|
+
|
87
|
+
def complex
|
88
|
+
elements[1]
|
89
|
+
end
|
90
|
+
|
91
|
+
def end_tag
|
92
|
+
elements[2]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
module Element1
|
97
|
+
# NOTE content only applies to non-empty element
|
98
|
+
def content
|
99
|
+
{ type: :element, name: (tag_element = elements[0]).name.to_sym, attributes: tag_element.attributes, pcdata: elements[1].content }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def _nt_element
|
104
|
+
start_index = index
|
105
|
+
if node_cache[:element].has_key?(index)
|
106
|
+
cached = node_cache[:element][index]
|
107
|
+
if cached
|
108
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
109
|
+
@index = cached.interval.end
|
110
|
+
end
|
111
|
+
return cached
|
112
|
+
end
|
113
|
+
|
114
|
+
i0 = index
|
115
|
+
r1 = _nt_empty_element
|
116
|
+
if r1
|
117
|
+
r0 = r1
|
118
|
+
else
|
119
|
+
i2, s2 = index, []
|
120
|
+
r3 = _nt_start_tag
|
121
|
+
s2 << r3
|
122
|
+
if r3
|
123
|
+
r4 = _nt_complex
|
124
|
+
s2 << r4
|
125
|
+
if r4
|
126
|
+
r5 = _nt_end_tag
|
127
|
+
s2 << r5
|
128
|
+
end
|
129
|
+
end
|
130
|
+
if s2.last
|
131
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
132
|
+
r2.extend(Element0)
|
133
|
+
r2.extend(Element1)
|
134
|
+
else
|
135
|
+
@index = i2
|
136
|
+
r2 = nil
|
137
|
+
end
|
138
|
+
if r2
|
139
|
+
r0 = r2
|
140
|
+
else
|
141
|
+
@index = i0
|
142
|
+
r0 = nil
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
node_cache[:element][start_index] = r0
|
147
|
+
|
148
|
+
r0
|
149
|
+
end
|
150
|
+
|
151
|
+
module EmptyElement0
|
152
|
+
end
|
153
|
+
|
154
|
+
module EmptyElement1
|
155
|
+
end
|
156
|
+
|
157
|
+
module EmptyElement2
|
158
|
+
def content
|
159
|
+
{ type: :element, name: :br, attributes: {} }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def _nt_empty_element
|
164
|
+
start_index = index
|
165
|
+
if node_cache[:empty_element].has_key?(index)
|
166
|
+
cached = node_cache[:empty_element][index]
|
167
|
+
if cached
|
168
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
169
|
+
@index = cached.interval.end
|
170
|
+
end
|
171
|
+
return cached
|
172
|
+
end
|
173
|
+
|
174
|
+
i0, s0 = index, []
|
175
|
+
if has_terminal?('<br', false, index)
|
176
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 3))
|
177
|
+
@index += 3
|
178
|
+
else
|
179
|
+
terminal_parse_failure('<br')
|
180
|
+
r1 = nil
|
181
|
+
end
|
182
|
+
s0 << r1
|
183
|
+
if r1
|
184
|
+
i3, s3 = index, []
|
185
|
+
r5 = _nt_spaces
|
186
|
+
if r5
|
187
|
+
r4 = r5
|
188
|
+
else
|
189
|
+
r4 = instantiate_node(SyntaxNode,input, index...index)
|
190
|
+
end
|
191
|
+
s3 << r4
|
192
|
+
if r4
|
193
|
+
if has_terminal?('/', false, index)
|
194
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
195
|
+
@index += 1
|
196
|
+
else
|
197
|
+
terminal_parse_failure('/')
|
198
|
+
r6 = nil
|
199
|
+
end
|
200
|
+
s3 << r6
|
201
|
+
end
|
202
|
+
if s3.last
|
203
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
204
|
+
r3.extend(EmptyElement0)
|
205
|
+
else
|
206
|
+
@index = i3
|
207
|
+
r3 = nil
|
208
|
+
end
|
209
|
+
if r3
|
210
|
+
r2 = r3
|
211
|
+
else
|
212
|
+
r2 = instantiate_node(SyntaxNode,input, index...index)
|
213
|
+
end
|
214
|
+
s0 << r2
|
215
|
+
if r2
|
216
|
+
if has_terminal?('>', false, index)
|
217
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
218
|
+
@index += 1
|
219
|
+
else
|
220
|
+
terminal_parse_failure('>')
|
221
|
+
r7 = nil
|
222
|
+
end
|
223
|
+
s0 << r7
|
224
|
+
end
|
225
|
+
end
|
226
|
+
if s0.last
|
227
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
228
|
+
r0.extend(EmptyElement1)
|
229
|
+
r0.extend(EmptyElement2)
|
230
|
+
else
|
231
|
+
@index = i0
|
232
|
+
r0 = nil
|
233
|
+
end
|
234
|
+
|
235
|
+
node_cache[:empty_element][start_index] = r0
|
236
|
+
|
237
|
+
r0
|
238
|
+
end
|
239
|
+
|
240
|
+
module StartTag0
|
241
|
+
def tag_name
|
242
|
+
elements[1]
|
243
|
+
end
|
244
|
+
|
245
|
+
def attributes
|
246
|
+
elements[2]
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
module StartTag1
|
252
|
+
def name
|
253
|
+
elements[1].text_value
|
254
|
+
end
|
255
|
+
|
256
|
+
def attributes
|
257
|
+
elements[2].content
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def _nt_start_tag
|
262
|
+
start_index = index
|
263
|
+
if node_cache[:start_tag].has_key?(index)
|
264
|
+
cached = node_cache[:start_tag][index]
|
265
|
+
if cached
|
266
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
267
|
+
@index = cached.interval.end
|
268
|
+
end
|
269
|
+
return cached
|
270
|
+
end
|
271
|
+
|
272
|
+
i0, s0 = index, []
|
273
|
+
if has_terminal?('<', false, index)
|
274
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
275
|
+
@index += 1
|
276
|
+
else
|
277
|
+
terminal_parse_failure('<')
|
278
|
+
r1 = nil
|
279
|
+
end
|
280
|
+
s0 << r1
|
281
|
+
if r1
|
282
|
+
r2 = _nt_tag_name
|
283
|
+
s0 << r2
|
284
|
+
if r2
|
285
|
+
r3 = _nt_attributes
|
286
|
+
s0 << r3
|
287
|
+
if r3
|
288
|
+
if has_terminal?('>', false, index)
|
289
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
290
|
+
@index += 1
|
291
|
+
else
|
292
|
+
terminal_parse_failure('>')
|
293
|
+
r4 = nil
|
294
|
+
end
|
295
|
+
s0 << r4
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
if s0.last
|
300
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
301
|
+
r0.extend(StartTag0)
|
302
|
+
r0.extend(StartTag1)
|
303
|
+
else
|
304
|
+
@index = i0
|
305
|
+
r0 = nil
|
306
|
+
end
|
307
|
+
|
308
|
+
node_cache[:start_tag][start_index] = r0
|
309
|
+
|
310
|
+
r0
|
311
|
+
end
|
312
|
+
|
313
|
+
def _nt_tag_name
|
314
|
+
start_index = index
|
315
|
+
if node_cache[:tag_name].has_key?(index)
|
316
|
+
cached = node_cache[:tag_name][index]
|
317
|
+
if cached
|
318
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
319
|
+
@index = cached.interval.end
|
320
|
+
end
|
321
|
+
return cached
|
322
|
+
end
|
323
|
+
|
324
|
+
i0 = index
|
325
|
+
if has_terminal?('a', false, index)
|
326
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
327
|
+
@index += 1
|
328
|
+
else
|
329
|
+
terminal_parse_failure('a')
|
330
|
+
r1 = nil
|
331
|
+
end
|
332
|
+
if r1
|
333
|
+
r0 = r1
|
334
|
+
else
|
335
|
+
if has_terminal?('b', false, index)
|
336
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
337
|
+
@index += 1
|
338
|
+
else
|
339
|
+
terminal_parse_failure('b')
|
340
|
+
r2 = nil
|
341
|
+
end
|
342
|
+
if r2
|
343
|
+
r0 = r2
|
344
|
+
else
|
345
|
+
if has_terminal?('code', false, index)
|
346
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
347
|
+
@index += 4
|
348
|
+
else
|
349
|
+
terminal_parse_failure('code')
|
350
|
+
r3 = nil
|
351
|
+
end
|
352
|
+
if r3
|
353
|
+
r0 = r3
|
354
|
+
else
|
355
|
+
if has_terminal?('color', false, index)
|
356
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 5))
|
357
|
+
@index += 5
|
358
|
+
else
|
359
|
+
terminal_parse_failure('color')
|
360
|
+
r4 = nil
|
361
|
+
end
|
362
|
+
if r4
|
363
|
+
r0 = r4
|
364
|
+
else
|
365
|
+
if has_terminal?('del', false, index)
|
366
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + 3))
|
367
|
+
@index += 3
|
368
|
+
else
|
369
|
+
terminal_parse_failure('del')
|
370
|
+
r5 = nil
|
371
|
+
end
|
372
|
+
if r5
|
373
|
+
r0 = r5
|
374
|
+
else
|
375
|
+
if has_terminal?('em', false, index)
|
376
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
377
|
+
@index += 2
|
378
|
+
else
|
379
|
+
terminal_parse_failure('em')
|
380
|
+
r6 = nil
|
381
|
+
end
|
382
|
+
if r6
|
383
|
+
r0 = r6
|
384
|
+
else
|
385
|
+
if has_terminal?('font', false, index)
|
386
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
387
|
+
@index += 4
|
388
|
+
else
|
389
|
+
terminal_parse_failure('font')
|
390
|
+
r7 = nil
|
391
|
+
end
|
392
|
+
if r7
|
393
|
+
r0 = r7
|
394
|
+
else
|
395
|
+
if has_terminal?('i', false, index)
|
396
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
397
|
+
@index += 1
|
398
|
+
else
|
399
|
+
terminal_parse_failure('i')
|
400
|
+
r8 = nil
|
401
|
+
end
|
402
|
+
if r8
|
403
|
+
r0 = r8
|
404
|
+
else
|
405
|
+
if has_terminal?('link', false, index)
|
406
|
+
r9 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
407
|
+
@index += 4
|
408
|
+
else
|
409
|
+
terminal_parse_failure('link')
|
410
|
+
r9 = nil
|
411
|
+
end
|
412
|
+
if r9
|
413
|
+
r0 = r9
|
414
|
+
else
|
415
|
+
if has_terminal?('span', false, index)
|
416
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
417
|
+
@index += 4
|
418
|
+
else
|
419
|
+
terminal_parse_failure('span')
|
420
|
+
r10 = nil
|
421
|
+
end
|
422
|
+
if r10
|
423
|
+
r0 = r10
|
424
|
+
else
|
425
|
+
if has_terminal?('strikethrough', false, index)
|
426
|
+
r11 = instantiate_node(SyntaxNode,input, index...(index + 13))
|
427
|
+
@index += 13
|
428
|
+
else
|
429
|
+
terminal_parse_failure('strikethrough')
|
430
|
+
r11 = nil
|
431
|
+
end
|
432
|
+
if r11
|
433
|
+
r0 = r11
|
434
|
+
else
|
435
|
+
if has_terminal?('strong', false, index)
|
436
|
+
r12 = instantiate_node(SyntaxNode,input, index...(index + 6))
|
437
|
+
@index += 6
|
438
|
+
else
|
439
|
+
terminal_parse_failure('strong')
|
440
|
+
r12 = nil
|
441
|
+
end
|
442
|
+
if r12
|
443
|
+
r0 = r12
|
444
|
+
else
|
445
|
+
if has_terminal?('sub', false, index)
|
446
|
+
r13 = instantiate_node(SyntaxNode,input, index...(index + 3))
|
447
|
+
@index += 3
|
448
|
+
else
|
449
|
+
terminal_parse_failure('sub')
|
450
|
+
r13 = nil
|
451
|
+
end
|
452
|
+
if r13
|
453
|
+
r0 = r13
|
454
|
+
else
|
455
|
+
if has_terminal?('sup', false, index)
|
456
|
+
r14 = instantiate_node(SyntaxNode,input, index...(index + 3))
|
457
|
+
@index += 3
|
458
|
+
else
|
459
|
+
terminal_parse_failure('sup')
|
460
|
+
r14 = nil
|
461
|
+
end
|
462
|
+
if r14
|
463
|
+
r0 = r14
|
464
|
+
else
|
465
|
+
if has_terminal?('u', false, index)
|
466
|
+
r15 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
467
|
+
@index += 1
|
468
|
+
else
|
469
|
+
terminal_parse_failure('u')
|
470
|
+
r15 = nil
|
471
|
+
end
|
472
|
+
if r15
|
473
|
+
r0 = r15
|
474
|
+
else
|
475
|
+
@index = i0
|
476
|
+
r0 = nil
|
477
|
+
end
|
478
|
+
end
|
479
|
+
end
|
480
|
+
end
|
481
|
+
end
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
486
|
+
end
|
487
|
+
end
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
node_cache[:tag_name][start_index] = r0
|
494
|
+
|
495
|
+
r0
|
496
|
+
end
|
497
|
+
|
498
|
+
module Attributes0
|
499
|
+
def content
|
500
|
+
attrs = {}
|
501
|
+
elements.each {|e|
|
502
|
+
attr_name, attr_val = e.content
|
503
|
+
attrs[attr_name.to_sym] = attr_val
|
504
|
+
}
|
505
|
+
attrs
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
def _nt_attributes
|
510
|
+
start_index = index
|
511
|
+
if node_cache[:attributes].has_key?(index)
|
512
|
+
cached = node_cache[:attributes][index]
|
513
|
+
if cached
|
514
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
515
|
+
@index = cached.interval.end
|
516
|
+
end
|
517
|
+
return cached
|
518
|
+
end
|
519
|
+
|
520
|
+
s0, i0 = [], index
|
521
|
+
loop do
|
522
|
+
r1 = _nt_attribute
|
523
|
+
if r1
|
524
|
+
s0 << r1
|
525
|
+
else
|
526
|
+
break
|
527
|
+
end
|
528
|
+
end
|
529
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
530
|
+
r0.extend(Attributes0)
|
531
|
+
|
532
|
+
node_cache[:attributes][start_index] = r0
|
533
|
+
|
534
|
+
r0
|
535
|
+
end
|
536
|
+
|
537
|
+
module Attribute0
|
538
|
+
def spaces
|
539
|
+
elements[0]
|
540
|
+
end
|
541
|
+
|
542
|
+
end
|
543
|
+
|
544
|
+
module Attribute1
|
545
|
+
def content
|
546
|
+
[elements[1].text_value, elements[4].text_value]
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
def _nt_attribute
|
551
|
+
start_index = index
|
552
|
+
if node_cache[:attribute].has_key?(index)
|
553
|
+
cached = node_cache[:attribute][index]
|
554
|
+
if cached
|
555
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
556
|
+
@index = cached.interval.end
|
557
|
+
end
|
558
|
+
return cached
|
559
|
+
end
|
560
|
+
|
561
|
+
i0, s0 = index, []
|
562
|
+
r1 = _nt_spaces
|
563
|
+
s0 << r1
|
564
|
+
if r1
|
565
|
+
s2, i2 = [], index
|
566
|
+
loop do
|
567
|
+
if has_terminal?('\G[a-z_]', true, index)
|
568
|
+
r3 = true
|
569
|
+
@index += 1
|
570
|
+
else
|
571
|
+
r3 = nil
|
572
|
+
end
|
573
|
+
if r3
|
574
|
+
s2 << r3
|
575
|
+
else
|
576
|
+
break
|
577
|
+
end
|
578
|
+
end
|
579
|
+
if s2.empty?
|
580
|
+
@index = i2
|
581
|
+
r2 = nil
|
582
|
+
else
|
583
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
584
|
+
end
|
585
|
+
s0 << r2
|
586
|
+
if r2
|
587
|
+
if has_terminal?('=', false, index)
|
588
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
589
|
+
@index += 1
|
590
|
+
else
|
591
|
+
terminal_parse_failure('=')
|
592
|
+
r4 = nil
|
593
|
+
end
|
594
|
+
s0 << r4
|
595
|
+
if r4
|
596
|
+
if has_terminal?('"', false, index)
|
597
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
598
|
+
@index += 1
|
599
|
+
else
|
600
|
+
terminal_parse_failure('"')
|
601
|
+
r5 = nil
|
602
|
+
end
|
603
|
+
s0 << r5
|
604
|
+
if r5
|
605
|
+
s6, i6 = [], index
|
606
|
+
loop do
|
607
|
+
if has_terminal?('\G[^"]', true, index)
|
608
|
+
r7 = true
|
609
|
+
@index += 1
|
610
|
+
else
|
611
|
+
r7 = nil
|
612
|
+
end
|
613
|
+
if r7
|
614
|
+
s6 << r7
|
615
|
+
else
|
616
|
+
break
|
617
|
+
end
|
618
|
+
end
|
619
|
+
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
620
|
+
s0 << r6
|
621
|
+
if r6
|
622
|
+
if has_terminal?('"', false, index)
|
623
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
624
|
+
@index += 1
|
625
|
+
else
|
626
|
+
terminal_parse_failure('"')
|
627
|
+
r8 = nil
|
628
|
+
end
|
629
|
+
s0 << r8
|
630
|
+
end
|
631
|
+
end
|
632
|
+
end
|
633
|
+
end
|
634
|
+
end
|
635
|
+
if s0.last
|
636
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
637
|
+
r0.extend(Attribute0)
|
638
|
+
r0.extend(Attribute1)
|
639
|
+
else
|
640
|
+
@index = i0
|
641
|
+
r0 = nil
|
642
|
+
end
|
643
|
+
|
644
|
+
node_cache[:attribute][start_index] = r0
|
645
|
+
|
646
|
+
r0
|
647
|
+
end
|
648
|
+
|
649
|
+
module EndTag0
|
650
|
+
def tag_name
|
651
|
+
elements[1]
|
652
|
+
end
|
653
|
+
|
654
|
+
end
|
655
|
+
|
656
|
+
module EndTag1
|
657
|
+
def name
|
658
|
+
elements[1].text_value
|
659
|
+
end
|
660
|
+
end
|
661
|
+
|
662
|
+
def _nt_end_tag
|
663
|
+
start_index = index
|
664
|
+
if node_cache[:end_tag].has_key?(index)
|
665
|
+
cached = node_cache[:end_tag][index]
|
666
|
+
if cached
|
667
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
668
|
+
@index = cached.interval.end
|
669
|
+
end
|
670
|
+
return cached
|
671
|
+
end
|
672
|
+
|
673
|
+
i0, s0 = index, []
|
674
|
+
if has_terminal?('</', false, index)
|
675
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
676
|
+
@index += 2
|
677
|
+
else
|
678
|
+
terminal_parse_failure('</')
|
679
|
+
r1 = nil
|
680
|
+
end
|
681
|
+
s0 << r1
|
682
|
+
if r1
|
683
|
+
r2 = _nt_tag_name
|
684
|
+
s0 << r2
|
685
|
+
if r2
|
686
|
+
if has_terminal?('>', false, index)
|
687
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
688
|
+
@index += 1
|
689
|
+
else
|
690
|
+
terminal_parse_failure('>')
|
691
|
+
r3 = nil
|
692
|
+
end
|
693
|
+
s0 << r3
|
694
|
+
end
|
695
|
+
end
|
696
|
+
if s0.last
|
697
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
698
|
+
r0.extend(EndTag0)
|
699
|
+
r0.extend(EndTag1)
|
700
|
+
else
|
701
|
+
@index = i0
|
702
|
+
r0 = nil
|
703
|
+
end
|
704
|
+
|
705
|
+
node_cache[:end_tag][start_index] = r0
|
706
|
+
|
707
|
+
r0
|
708
|
+
end
|
709
|
+
|
710
|
+
module Cdata0
|
711
|
+
def content
|
712
|
+
{ type: :text, value: text_value }
|
713
|
+
end
|
714
|
+
end
|
715
|
+
|
716
|
+
def _nt_cdata
|
717
|
+
start_index = index
|
718
|
+
if node_cache[:cdata].has_key?(index)
|
719
|
+
cached = node_cache[:cdata][index]
|
720
|
+
if cached
|
721
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
722
|
+
@index = cached.interval.end
|
723
|
+
end
|
724
|
+
return cached
|
725
|
+
end
|
726
|
+
|
727
|
+
s0, i0 = [], index
|
728
|
+
loop do
|
729
|
+
if has_terminal?('\G[^<&]', true, index)
|
730
|
+
r1 = true
|
731
|
+
@index += 1
|
732
|
+
else
|
733
|
+
r1 = nil
|
734
|
+
end
|
735
|
+
if r1
|
736
|
+
s0 << r1
|
737
|
+
else
|
738
|
+
break
|
739
|
+
end
|
740
|
+
end
|
741
|
+
if s0.empty?
|
742
|
+
@index = i0
|
743
|
+
r0 = nil
|
744
|
+
else
|
745
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
746
|
+
r0.extend(Cdata0)
|
747
|
+
end
|
748
|
+
|
749
|
+
node_cache[:cdata][start_index] = r0
|
750
|
+
|
751
|
+
r0
|
752
|
+
end
|
753
|
+
|
754
|
+
module Entity0
|
755
|
+
def entity_number
|
756
|
+
elements[1]
|
757
|
+
end
|
758
|
+
end
|
759
|
+
|
760
|
+
module Entity1
|
761
|
+
end
|
762
|
+
|
763
|
+
module Entity2
|
764
|
+
def content
|
765
|
+
if (entity_value = elements[1]).terminal?
|
766
|
+
{ type: :entity, name: entity_value.text_value.to_sym }
|
767
|
+
else
|
768
|
+
{ type: :entity, number: entity_value.elements[1].text_value.to_i }
|
769
|
+
end
|
770
|
+
end
|
771
|
+
end
|
772
|
+
|
773
|
+
def _nt_entity
|
774
|
+
start_index = index
|
775
|
+
if node_cache[:entity].has_key?(index)
|
776
|
+
cached = node_cache[:entity][index]
|
777
|
+
if cached
|
778
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
779
|
+
@index = cached.interval.end
|
780
|
+
end
|
781
|
+
return cached
|
782
|
+
end
|
783
|
+
|
784
|
+
i0, s0 = index, []
|
785
|
+
if has_terminal?('&', false, index)
|
786
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
787
|
+
@index += 1
|
788
|
+
else
|
789
|
+
terminal_parse_failure('&')
|
790
|
+
r1 = nil
|
791
|
+
end
|
792
|
+
s0 << r1
|
793
|
+
if r1
|
794
|
+
i2 = index
|
795
|
+
i3, s3 = index, []
|
796
|
+
if has_terminal?('#', false, index)
|
797
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
798
|
+
@index += 1
|
799
|
+
else
|
800
|
+
terminal_parse_failure('#')
|
801
|
+
r4 = nil
|
802
|
+
end
|
803
|
+
s3 << r4
|
804
|
+
if r4
|
805
|
+
r5 = _nt_entity_number
|
806
|
+
s3 << r5
|
807
|
+
end
|
808
|
+
if s3.last
|
809
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
810
|
+
r3.extend(Entity0)
|
811
|
+
else
|
812
|
+
@index = i3
|
813
|
+
r3 = nil
|
814
|
+
end
|
815
|
+
if r3
|
816
|
+
r2 = r3
|
817
|
+
else
|
818
|
+
r6 = _nt_entity_name
|
819
|
+
if r6
|
820
|
+
r2 = r6
|
821
|
+
else
|
822
|
+
@index = i2
|
823
|
+
r2 = nil
|
824
|
+
end
|
825
|
+
end
|
826
|
+
s0 << r2
|
827
|
+
if r2
|
828
|
+
if has_terminal?(';', false, index)
|
829
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
830
|
+
@index += 1
|
831
|
+
else
|
832
|
+
terminal_parse_failure(';')
|
833
|
+
r7 = nil
|
834
|
+
end
|
835
|
+
s0 << r7
|
836
|
+
end
|
837
|
+
end
|
838
|
+
if s0.last
|
839
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
840
|
+
r0.extend(Entity1)
|
841
|
+
r0.extend(Entity2)
|
842
|
+
else
|
843
|
+
@index = i0
|
844
|
+
r0 = nil
|
845
|
+
end
|
846
|
+
|
847
|
+
node_cache[:entity][start_index] = r0
|
848
|
+
|
849
|
+
r0
|
850
|
+
end
|
851
|
+
|
852
|
+
def _nt_entity_number
|
853
|
+
start_index = index
|
854
|
+
if node_cache[:entity_number].has_key?(index)
|
855
|
+
cached = node_cache[:entity_number][index]
|
856
|
+
if cached
|
857
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
858
|
+
@index = cached.interval.end
|
859
|
+
end
|
860
|
+
return cached
|
861
|
+
end
|
862
|
+
|
863
|
+
s0, i0 = [], index
|
864
|
+
loop do
|
865
|
+
if has_terminal?('\G[0-9]', true, index)
|
866
|
+
r1 = true
|
867
|
+
@index += 1
|
868
|
+
else
|
869
|
+
r1 = nil
|
870
|
+
end
|
871
|
+
if r1
|
872
|
+
s0 << r1
|
873
|
+
else
|
874
|
+
break
|
875
|
+
end
|
876
|
+
if s0.size == 4
|
877
|
+
break
|
878
|
+
end
|
879
|
+
end
|
880
|
+
if s0.size < 2
|
881
|
+
@index = i0
|
882
|
+
r0 = nil
|
883
|
+
else
|
884
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
885
|
+
end
|
886
|
+
|
887
|
+
node_cache[:entity_number][start_index] = r0
|
888
|
+
|
889
|
+
r0
|
890
|
+
end
|
891
|
+
|
892
|
+
def _nt_entity_name
|
893
|
+
start_index = index
|
894
|
+
if node_cache[:entity_name].has_key?(index)
|
895
|
+
cached = node_cache[:entity_name][index]
|
896
|
+
if cached
|
897
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
898
|
+
@index = cached.interval.end
|
899
|
+
end
|
900
|
+
return cached
|
901
|
+
end
|
902
|
+
|
903
|
+
i0 = index
|
904
|
+
if has_terminal?('amp', false, index)
|
905
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 3))
|
906
|
+
@index += 3
|
907
|
+
else
|
908
|
+
terminal_parse_failure('amp')
|
909
|
+
r1 = nil
|
910
|
+
end
|
911
|
+
if r1
|
912
|
+
r0 = r1
|
913
|
+
else
|
914
|
+
if has_terminal?('apos', false, index)
|
915
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
916
|
+
@index += 4
|
917
|
+
else
|
918
|
+
terminal_parse_failure('apos')
|
919
|
+
r2 = nil
|
920
|
+
end
|
921
|
+
if r2
|
922
|
+
r0 = r2
|
923
|
+
else
|
924
|
+
if has_terminal?('gt', false, index)
|
925
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
926
|
+
@index += 2
|
927
|
+
else
|
928
|
+
terminal_parse_failure('gt')
|
929
|
+
r3 = nil
|
930
|
+
end
|
931
|
+
if r3
|
932
|
+
r0 = r3
|
933
|
+
else
|
934
|
+
if has_terminal?('lt', false, index)
|
935
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
936
|
+
@index += 2
|
937
|
+
else
|
938
|
+
terminal_parse_failure('lt')
|
939
|
+
r4 = nil
|
940
|
+
end
|
941
|
+
if r4
|
942
|
+
r0 = r4
|
943
|
+
else
|
944
|
+
if has_terminal?('quot', false, index)
|
945
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
946
|
+
@index += 4
|
947
|
+
else
|
948
|
+
terminal_parse_failure('quot')
|
949
|
+
r5 = nil
|
950
|
+
end
|
951
|
+
if r5
|
952
|
+
r0 = r5
|
953
|
+
else
|
954
|
+
@index = i0
|
955
|
+
r0 = nil
|
956
|
+
end
|
957
|
+
end
|
958
|
+
end
|
959
|
+
end
|
960
|
+
end
|
961
|
+
|
962
|
+
node_cache[:entity_name][start_index] = r0
|
963
|
+
|
964
|
+
r0
|
965
|
+
end
|
966
|
+
|
967
|
+
def _nt_spaces
|
968
|
+
start_index = index
|
969
|
+
if node_cache[:spaces].has_key?(index)
|
970
|
+
cached = node_cache[:spaces][index]
|
971
|
+
if cached
|
972
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
973
|
+
@index = cached.interval.end
|
974
|
+
end
|
975
|
+
return cached
|
976
|
+
end
|
977
|
+
|
978
|
+
s0, i0 = [], index
|
979
|
+
loop do
|
980
|
+
if has_terminal?(' ', false, index)
|
981
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
982
|
+
@index += 1
|
983
|
+
else
|
984
|
+
terminal_parse_failure(' ')
|
985
|
+
r1 = nil
|
986
|
+
end
|
987
|
+
if r1
|
988
|
+
s0 << r1
|
989
|
+
else
|
990
|
+
break
|
991
|
+
end
|
992
|
+
end
|
993
|
+
if s0.empty?
|
994
|
+
@index = i0
|
995
|
+
r0 = nil
|
996
|
+
else
|
997
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
998
|
+
end
|
999
|
+
|
1000
|
+
node_cache[:spaces][start_index] = r0
|
1001
|
+
|
1002
|
+
r0
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
end
|
1006
|
+
|
1007
|
+
class FormattedTextParser < Treetop::Runtime::CompiledParser
|
1008
|
+
include FormattedText
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
end
|
1012
|
+
end
|