slaw 3.1.1 → 3.2.0
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/README.md +5 -1
- data/lib/slaw/grammars/terminals.treetop +0 -9
- data/lib/slaw/grammars/za/act.treetop +4 -4
- data/lib/slaw/grammars/za/act_nodes.rb +29 -25
- data/lib/slaw/version.rb +1 -1
- data/spec/za/act_block_spec.rb +132 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4411a620b2f2ff5cad3942e1944d344a9e6282e654df6313a78a99e654a91347
|
4
|
+
data.tar.gz: '0789f05372eda817a52d97ba55ec4481f77d69557908709e3d4117b57c5d822b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b0da1d5da9fb240a3efac4cd280fc567fc58979f219186c3b8719b13c3a3d2ebba5c20abc939e84b187539fa8a3d4ad1c5c7431b421902c0a7ae831dff51fda
|
7
|
+
data.tar.gz: be10a3d7c7ca33d81490b4c9c126a1bf2d6db2a9ec008bd989af4d3fb9485b55d74f560cf561b08b41669babd85831568be6f47937ee8b748ec6d4be02805712
|
data/README.md
CHANGED
@@ -81,7 +81,11 @@ You can create your own grammar by creating a gem that provides these files and
|
|
81
81
|
|
82
82
|
## Changelog
|
83
83
|
|
84
|
-
### 3.
|
84
|
+
### 3.2.0 (22 April 2019)
|
85
|
+
|
86
|
+
* Permit inline content in chapter, part and section headings
|
87
|
+
|
88
|
+
### 3.1.1 (10 April 2019)
|
85
89
|
|
86
90
|
* FIX don't error when a line is just a backslash
|
87
91
|
|
@@ -3,15 +3,6 @@
|
|
3
3
|
module Slaw
|
4
4
|
module Grammars
|
5
5
|
grammar Terminals
|
6
|
-
#########
|
7
|
-
## one line of basic content
|
8
|
-
|
9
|
-
rule content
|
10
|
-
# anything but a newline, followed by a
|
11
|
-
# newline or end of file (without consuming the newline)
|
12
|
-
[^\n]+ &eol
|
13
|
-
end
|
14
|
-
|
15
6
|
##########
|
16
7
|
# terminals
|
17
8
|
|
@@ -106,12 +106,12 @@ module Slaw
|
|
106
106
|
# headings
|
107
107
|
|
108
108
|
rule chapter_heading
|
109
|
-
space? chapter_heading_prefix heading:(newline?
|
109
|
+
space? chapter_heading_prefix heading:(newline? space? inline_items)? eol
|
110
110
|
<ChapterHeading>
|
111
111
|
end
|
112
112
|
|
113
113
|
rule part_heading
|
114
|
-
space? part_heading_prefix heading:(newline?
|
114
|
+
space? part_heading_prefix heading:(newline? space? inline_items)? eol
|
115
115
|
<PartHeading>
|
116
116
|
end
|
117
117
|
|
@@ -123,7 +123,7 @@ module Slaw
|
|
123
123
|
&{ |s| options[:section_number_after_title] }
|
124
124
|
# Section title
|
125
125
|
# 1. Section content
|
126
|
-
|
126
|
+
space? inline_items eol
|
127
127
|
section_title_prefix whitespace <SectionTitleType1>
|
128
128
|
end
|
129
129
|
|
@@ -141,7 +141,7 @@ module Slaw
|
|
141
141
|
# don't match subsections, eg.
|
142
142
|
#
|
143
143
|
# 10. (1) subsection content...
|
144
|
-
space !subsection_prefix
|
144
|
+
space !subsection_prefix inline_items eol
|
145
145
|
end
|
146
146
|
|
147
147
|
##########
|
@@ -154,15 +154,13 @@ module Slaw
|
|
154
154
|
part_heading_prefix.alphanums.text_value
|
155
155
|
end
|
156
156
|
|
157
|
-
def title
|
158
|
-
if heading.text_value and heading.respond_to? :content
|
159
|
-
heading.content.text_value.strip
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
157
|
def to_xml(b)
|
164
158
|
b.num(num)
|
165
|
-
|
159
|
+
if heading.respond_to? :inline_items
|
160
|
+
b.heading { |b|
|
161
|
+
heading.inline_items.to_xml(b)
|
162
|
+
}
|
163
|
+
end
|
166
164
|
end
|
167
165
|
end
|
168
166
|
|
@@ -191,15 +189,13 @@ module Slaw
|
|
191
189
|
chapter_heading_prefix.alphanums.text_value
|
192
190
|
end
|
193
191
|
|
194
|
-
def title
|
195
|
-
if heading.text_value and heading.respond_to? :content
|
196
|
-
heading.content.text_value.strip
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
192
|
def to_xml(b)
|
201
193
|
b.num(num)
|
202
|
-
|
194
|
+
if heading.respond_to? :inline_items
|
195
|
+
b.heading { |b|
|
196
|
+
heading.inline_items.to_xml(b)
|
197
|
+
}
|
198
|
+
end
|
203
199
|
end
|
204
200
|
end
|
205
201
|
|
@@ -208,18 +204,12 @@ module Slaw
|
|
208
204
|
section_title.num
|
209
205
|
end
|
210
206
|
|
211
|
-
def title
|
212
|
-
section_title.title
|
213
|
-
end
|
214
|
-
|
215
207
|
def to_xml(b, *args)
|
216
208
|
id = "section-#{num}"
|
217
209
|
b.section(id: id) { |b|
|
218
|
-
|
219
|
-
b.heading(title)
|
210
|
+
section_title.to_xml(b)
|
220
211
|
|
221
212
|
idprefix = "#{id}."
|
222
|
-
|
223
213
|
children.elements.each_with_index { |e, i| e.to_xml(b, idprefix, i) }
|
224
214
|
}
|
225
215
|
end
|
@@ -235,8 +225,14 @@ module Slaw
|
|
235
225
|
section_title_prefix.number_letter.text_value
|
236
226
|
end
|
237
227
|
|
238
|
-
def
|
239
|
-
|
228
|
+
def to_xml(b, *args)
|
229
|
+
b.num("#{num}.")
|
230
|
+
|
231
|
+
if inline_items.text_value
|
232
|
+
b.heading { |b|
|
233
|
+
inline_items.to_xml(b)
|
234
|
+
}
|
235
|
+
end
|
240
236
|
end
|
241
237
|
end
|
242
238
|
|
@@ -253,8 +249,16 @@ module Slaw
|
|
253
249
|
section_title_prefix.number_letter.text_value
|
254
250
|
end
|
255
251
|
|
256
|
-
def
|
257
|
-
|
252
|
+
def to_xml(b, *args)
|
253
|
+
b.num("#{num}.")
|
254
|
+
|
255
|
+
if section_title.respond_to? :inline_items and section_title.inline_items.text_value
|
256
|
+
b.heading { |b|
|
257
|
+
section_title.inline_items.to_xml(b)
|
258
|
+
}
|
259
|
+
else
|
260
|
+
b.heading
|
261
|
+
end
|
258
262
|
end
|
259
263
|
end
|
260
264
|
|
data/lib/slaw/version.rb
CHANGED
data/spec/za/act_block_spec.rb
CHANGED
@@ -201,7 +201,7 @@ CROSSHEADING crossheading
|
|
201
201
|
Some lines at the start of the chapter.
|
202
202
|
EOS
|
203
203
|
node.num.should == "2"
|
204
|
-
node.heading.
|
204
|
+
node.heading.heading.text_value.should == "\nThe Chapter Heading"
|
205
205
|
to_xml(node).should == '<chapter id="chapter-2">
|
206
206
|
<num>2</num>
|
207
207
|
<heading>The Chapter Heading</heading>
|
@@ -227,7 +227,7 @@ Some lines at the start of the chapter.
|
|
227
227
|
Section text.
|
228
228
|
EOS
|
229
229
|
node.num.should == "2"
|
230
|
-
node.heading.
|
230
|
+
node.heading.heading.text_value.should == 'The Chapter Heading'
|
231
231
|
to_xml(node).should == '<chapter id="chapter-2">
|
232
232
|
<num>2</num>
|
233
233
|
<heading>The Chapter Heading</heading>
|
@@ -270,6 +270,51 @@ EOS
|
|
270
270
|
</chapter>'
|
271
271
|
end
|
272
272
|
|
273
|
+
it 'should handle inlines in chapter titles after newline' do
|
274
|
+
node = parse :chapter, <<EOS
|
275
|
+
Chapter 2
|
276
|
+
The **Chapter** [Heading](/za/act/1990/1) [[remark]]
|
277
|
+
|
278
|
+
1. Section
|
279
|
+
Hello there
|
280
|
+
EOS
|
281
|
+
to_xml(node).should == '<chapter id="chapter-2">
|
282
|
+
<num>2</num>
|
283
|
+
<heading>The <b>Chapter</b> <ref href="/za/act/1990/1">Heading</ref> <remark status="editorial">[remark]</remark></heading>
|
284
|
+
<section id="section-1">
|
285
|
+
<num>1.</num>
|
286
|
+
<heading>Section</heading>
|
287
|
+
<paragraph id="section-1.paragraph0">
|
288
|
+
<content>
|
289
|
+
<p>Hello there</p>
|
290
|
+
</content>
|
291
|
+
</paragraph>
|
292
|
+
</section>
|
293
|
+
</chapter>'
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'should handle inlines in chapter titles' do
|
297
|
+
node = parse :chapter, <<EOS
|
298
|
+
Chapter 2 - The **Chapter** [Heading](/za/act/1990/1) [[remark]]
|
299
|
+
|
300
|
+
1. Section
|
301
|
+
Hello there
|
302
|
+
EOS
|
303
|
+
to_xml(node).should == '<chapter id="chapter-2">
|
304
|
+
<num>2</num>
|
305
|
+
<heading>The <b>Chapter</b> <ref href="/za/act/1990/1">Heading</ref> <remark status="editorial">[remark]</remark></heading>
|
306
|
+
<section id="section-1">
|
307
|
+
<num>1.</num>
|
308
|
+
<heading>Section</heading>
|
309
|
+
<paragraph id="section-1.paragraph0">
|
310
|
+
<content>
|
311
|
+
<p>Hello there</p>
|
312
|
+
</content>
|
313
|
+
</paragraph>
|
314
|
+
</section>
|
315
|
+
</chapter>'
|
316
|
+
end
|
317
|
+
|
273
318
|
it 'should handle empty chapters' do
|
274
319
|
node = parse :body, <<EOS
|
275
320
|
Chapter 2 The Chapter Heading
|
@@ -453,6 +498,49 @@ EOS
|
|
453
498
|
</part>'
|
454
499
|
end
|
455
500
|
|
501
|
+
it 'should handle part headers with inline elements after newline' do
|
502
|
+
node = parse :part, <<EOS
|
503
|
+
Part 2
|
504
|
+
The **Part** Heading
|
505
|
+
1. Section
|
506
|
+
Hello there
|
507
|
+
EOS
|
508
|
+
to_xml(node).should == '<part id="part-2">
|
509
|
+
<num>2</num>
|
510
|
+
<heading>The <b>Part</b> Heading</heading>
|
511
|
+
<section id="section-1">
|
512
|
+
<num>1.</num>
|
513
|
+
<heading>Section</heading>
|
514
|
+
<paragraph id="section-1.paragraph0">
|
515
|
+
<content>
|
516
|
+
<p>Hello there</p>
|
517
|
+
</content>
|
518
|
+
</paragraph>
|
519
|
+
</section>
|
520
|
+
</part>'
|
521
|
+
end
|
522
|
+
|
523
|
+
it 'should handle part headers with inline elements' do
|
524
|
+
node = parse :part, <<EOS
|
525
|
+
Part 2 The **Part** Heading
|
526
|
+
1. Section
|
527
|
+
Hello there
|
528
|
+
EOS
|
529
|
+
to_xml(node).should == '<part id="part-2">
|
530
|
+
<num>2</num>
|
531
|
+
<heading>The <b>Part</b> Heading</heading>
|
532
|
+
<section id="section-1">
|
533
|
+
<num>1.</num>
|
534
|
+
<heading>Section</heading>
|
535
|
+
<paragraph id="section-1.paragraph0">
|
536
|
+
<content>
|
537
|
+
<p>Hello there</p>
|
538
|
+
</content>
|
539
|
+
</paragraph>
|
540
|
+
</section>
|
541
|
+
</part>'
|
542
|
+
end
|
543
|
+
|
456
544
|
it 'should handle parts and odd section numbers' do
|
457
545
|
subject.parser.options = {section_number_after_title: false}
|
458
546
|
node = parse :parts, <<EOS
|
@@ -487,7 +575,7 @@ Some text before the part.
|
|
487
575
|
Hello there
|
488
576
|
EOS
|
489
577
|
node.num.should == "2"
|
490
|
-
node.heading.
|
578
|
+
node.heading.heading.text_value.should == "\nThe Part Heading"
|
491
579
|
to_xml(node).should == '<part id="part-2">
|
492
580
|
<num>2</num>
|
493
581
|
<heading>The Part Heading</heading>
|
@@ -1274,6 +1362,47 @@ EOS
|
|
1274
1362
|
</section>'
|
1275
1363
|
end
|
1276
1364
|
|
1365
|
+
it 'should handle sections with inline markup in headings' do
|
1366
|
+
subject.parser.options = {section_number_after_title: false}
|
1367
|
+
node = parse :section, <<EOS
|
1368
|
+
1. Section **bold** [foo](/za/act/1990/1)
|
1369
|
+
|
1370
|
+
something
|
1371
|
+
EOS
|
1372
|
+
|
1373
|
+
s = to_xml(node)
|
1374
|
+
s.should == '<section id="section-1">
|
1375
|
+
<num>1.</num>
|
1376
|
+
<heading>Section <b>bold</b> <ref href="/za/act/1990/1">foo</ref></heading>
|
1377
|
+
<paragraph id="section-1.paragraph0">
|
1378
|
+
<content>
|
1379
|
+
<p>something</p>
|
1380
|
+
</content>
|
1381
|
+
</paragraph>
|
1382
|
+
</section>'
|
1383
|
+
end
|
1384
|
+
|
1385
|
+
it 'should handle prefixed sections with inline markup in headings' do
|
1386
|
+
subject.parser.options = {section_number_after_title: true}
|
1387
|
+
node = parse :section, <<EOS
|
1388
|
+
Section **bold** [foo](/za/act/1990/1)
|
1389
|
+
1.
|
1390
|
+
|
1391
|
+
something
|
1392
|
+
EOS
|
1393
|
+
|
1394
|
+
s = to_xml(node)
|
1395
|
+
s.should == '<section id="section-1">
|
1396
|
+
<num>1.</num>
|
1397
|
+
<heading>Section <b>bold</b> <ref href="/za/act/1990/1">foo</ref></heading>
|
1398
|
+
<paragraph id="section-1.paragraph0">
|
1399
|
+
<content>
|
1400
|
+
<p>something</p>
|
1401
|
+
</content>
|
1402
|
+
</paragraph>
|
1403
|
+
</section>'
|
1404
|
+
end
|
1405
|
+
|
1277
1406
|
it 'should handle a naked statement' do
|
1278
1407
|
should_parse :section, <<EOS
|
1279
1408
|
1. Section
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slaw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Kempe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|