slaw 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 657367d2055974b4c1e986050ef45bf27e625bec
4
- data.tar.gz: 5b90b89cbc9bd4a3a546d4b2b7cd80e85ff9bc46
3
+ metadata.gz: 60aacb892dc41e5b6f92e698df123bd34c46a585
4
+ data.tar.gz: 4aa1590df1aac33962cb38780235bd45a7e522be
5
5
  SHA512:
6
- metadata.gz: e4f9f19d7f74e1721e5ef43daf946120ac0b518155d7167ef5d0677d249bc1cd47efb3e542d4288837c51561675850beb0591291dea9baa858827f3aedee7bd0
7
- data.tar.gz: ec3b48956ed66ed38b309e6b60e7108d5bd89e90b018ca3f3472806de4ee1f2a4d636149922749b89e6503e9f5ae253c6dcab1765eaeec903a4ad164f01e95bf
6
+ metadata.gz: ebd4dfc35e3f15518236ddea7bfd961482e768a39703bb4e123cb04695825938cd426600773ef3323592a616ea07be9eeaf678222cd7243c6fccf263a9cf1065
7
+ data.tar.gz: 1fbfd3883cb51575e7318f2bf1e1935ad6e5dc3ff1bed9f9dd6d71e19eb9c7bf895b2b7829a3402bc529675d80b34aeb921853c179074d77dc72437a8bc1c6ea
data/README.md CHANGED
@@ -218,6 +218,12 @@ Akoma Ntoso `component` elements at the end of the XML document, with a name of
218
218
 
219
219
  ## Changelog
220
220
 
221
+ ### 0.13.0
222
+
223
+ * FIX allow Schedule, Part and other headings at the start of blocklist and subsections
224
+ * FIX replace empty CONTENT elements with empty P tags so XML validates
225
+ * Better handling of empty subsections and blocklist items
226
+
221
227
  ### 0.12.0
222
228
 
223
229
  * Support links/references using Markdown-like \[text](href) syntax.
data/lib/slaw/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slaw
2
- VERSION = "0.12.0"
2
+ VERSION = "0.13.0"
3
3
  end
@@ -52,8 +52,11 @@ module Slaw
52
52
  end
53
53
 
54
54
  rule subsection
55
- # TODO: do it make sense to allow an eol here?
56
- space? subsection_prefix whitespace eol?
55
+ space? subsection_prefix space?
56
+ # eg: (2) (a) foo
57
+ first_child:inline_block_element?
58
+ # eg: (2)
59
+ eol?
57
60
  children:block_element* <Subsection>
58
61
  end
59
62
 
@@ -125,6 +128,9 @@ module Slaw
125
128
  end
126
129
 
127
130
  rule section_title_content
131
+ # don't match subsections, eg.
132
+ #
133
+ # 10. (1) subsection content...
128
134
  space !subsection_prefix content eol
129
135
  end
130
136
 
@@ -145,12 +151,19 @@ module Slaw
145
151
  (table / blocklist / naked_statement)
146
152
  end
147
153
 
154
+ # Block elements that don't have to appear at the start of a line.
155
+ # ie. we don't need to guard against the start of a chapter, section, etc.
156
+ rule inline_block_element
157
+ (table / blocklist / inline_statement)
158
+ end
159
+
148
160
  rule blocklist
149
161
  blocklist_item+ <Blocklist>
150
162
  end
151
163
 
152
164
  rule blocklist_item
153
- space? blocklist_item_prefix whitespace item_content:(!blocklist_item_prefix clauses eol)? eol?
165
+ # TODO: this whitespace should probably be space, to allow empty blocklist items followed by plain text
166
+ space? blocklist_item_prefix whitespace item_content:(!blocklist_item_prefix clauses:clauses? eol)? eol?
154
167
  <BlocklistItem>
155
168
  end
156
169
 
@@ -187,12 +200,17 @@ module Slaw
187
200
  <NakedStatement>
188
201
  end
189
202
 
203
+ rule inline_statement
204
+ space? '\\'? clauses eol
205
+ <NakedStatement>
206
+ end
207
+
190
208
  ##########
191
209
  # inline content
192
210
 
193
211
  # one or more words, allowing inline elements
194
212
  rule clauses
195
- (remark / ref / [^\n])*
213
+ (remark / ref / [^\n])+
196
214
  <Clauses>
197
215
  end
198
216
 
@@ -267,10 +267,18 @@ module Slaw
267
267
  id = idprefix + num.gsub(/[()]/, '')
268
268
  idprefix = id + "."
269
269
 
270
+ kids = children.elements
271
+ kids = [first_child] + kids if first_child and !first_child.empty?
272
+
270
273
  b.subsection(id: id) { |b|
271
274
  b.num(num)
272
275
  b.content { |b|
273
- children.elements.each_with_index { |e, i| e.to_xml(b, idprefix, i) }
276
+ if kids.empty?
277
+ # schema requires a non-empty content element
278
+ b.p
279
+ else
280
+ kids.each_with_index { |e, i| e.to_xml(b, idprefix, i) }
281
+ end
274
282
  }
275
283
  }
276
284
  end
@@ -333,7 +341,9 @@ module Slaw
333
341
  def to_xml(b, idprefix)
334
342
  b.item(id: idprefix + num.gsub(/[()]/, '')) { |b|
335
343
  b.num(num)
336
- b.p { |b| item_content.clauses.to_xml(b, idprefix) } if respond_to? :item_content and item_content.respond_to? :clauses
344
+ b.p { |b|
345
+ item_content.clauses.to_xml(b, idprefix) if respond_to? :item_content and item_content.respond_to? :clauses
346
+ }
337
347
  }
338
348
  end
339
349
  end
data/spec/za/act_spec.rb CHANGED
@@ -586,6 +586,63 @@ EOS
586
586
  </subsection>'
587
587
  end
588
588
 
589
+ it 'should handle a subsection that is empty and dives straight into a list' do
590
+ node = parse(:subsection, <<EOS
591
+ (1)
592
+ (a) one
593
+ (b) two
594
+ EOS
595
+ )
596
+ to_xml(node, "", 1).should == '<subsection id="1">
597
+ <num>(1)</num>
598
+ <content>
599
+ <blockList id="1.list0">
600
+ <item id="1.list0.a">
601
+ <num>(a)</num>
602
+ <p>one</p>
603
+ </item>
604
+ <item id="1.list0.b">
605
+ <num>(b)</num>
606
+ <p>two</p>
607
+ </item>
608
+ </blockList>
609
+ </content>
610
+ </subsection>'
611
+ end
612
+
613
+ it 'should handle empty subsections' do
614
+ node = parse(:section, <<EOS
615
+ 1. Section
616
+ (1)
617
+ (2)
618
+ next line
619
+ (3) third
620
+ EOS
621
+ )
622
+ to_xml(node).should == '<section id="section-1">
623
+ <num>1.</num>
624
+ <heading>Section</heading>
625
+ <subsection id="section-1.1">
626
+ <num>(1)</num>
627
+ <content>
628
+ <p/>
629
+ </content>
630
+ </subsection>
631
+ <subsection id="section-1.2">
632
+ <num>(2)</num>
633
+ <content>
634
+ <p>next line</p>
635
+ </content>
636
+ </subsection>
637
+ <subsection id="section-1.3">
638
+ <num>(3)</num>
639
+ <content>
640
+ <p>third</p>
641
+ </content>
642
+ </subsection>
643
+ </section>'
644
+ end
645
+
589
646
  it 'should handle a blocklist that dives straight into another list' do
590
647
  node = parse(:subsection, <<EOS
591
648
  (1) here's my really cool list,
@@ -605,6 +662,41 @@ EOS
605
662
  </item>
606
663
  <item id="1.list1.b">
607
664
  <num>(b)</num>
665
+ <p/>
666
+ </item>
667
+ <item id="1.list1.i">
668
+ <num>(i)</num>
669
+ <p>single</p>
670
+ </item>
671
+ <item id="1.list1.ii">
672
+ <num>(ii)</num>
673
+ <p>double</p>
674
+ </item>
675
+ </blockList>
676
+ </content>
677
+ </subsection>'
678
+ end
679
+
680
+ it 'should handle a blocklist with empty elements' do
681
+ node = parse(:subsection, <<EOS
682
+ (1) here's my really cool list,
683
+ (a)
684
+ (b) (i) single
685
+ (ii) double
686
+ EOS
687
+ )
688
+ to_xml(node, "", 1).should == '<subsection id="1">
689
+ <num>(1)</num>
690
+ <content>
691
+ <p>here\'s my really cool list,</p>
692
+ <blockList id="1.list1">
693
+ <item id="1.list1.a">
694
+ <num>(a)</num>
695
+ <p/>
696
+ </item>
697
+ <item id="1.list1.b">
698
+ <num>(b)</num>
699
+ <p/>
608
700
  </item>
609
701
  <item id="1.list1.i">
610
702
  <num>(i)</num>
@@ -721,6 +813,33 @@ EOS
721
813
  </content>
722
814
  </subsection>'
723
815
  end
816
+
817
+ it 'should ignore block elements mid-subsection' do
818
+ node = parse :body, <<EOS
819
+ 1. Section
820
+
821
+ (2) Schedule 1 is cool.
822
+ (3) Part 1
823
+ EOS
824
+ to_xml(node).should == '<body>
825
+ <section id="section-1">
826
+ <num>1.</num>
827
+ <heading>Section</heading>
828
+ <subsection id="section-1.2">
829
+ <num>(2)</num>
830
+ <content>
831
+ <p>Schedule 1 is cool.</p>
832
+ </content>
833
+ </subsection>
834
+ <subsection id="section-1.3">
835
+ <num>(3)</num>
836
+ <content>
837
+ <p>Part 1</p>
838
+ </content>
839
+ </subsection>
840
+ </section>
841
+ </body>'
842
+ end
724
843
  end
725
844
 
726
845
  #-------------------------------------------------------------------------------
@@ -1407,6 +1526,48 @@ EOS
1407
1526
  </section>'
1408
1527
  end
1409
1528
 
1529
+ it 'should handle empty subsections and empty lines' do
1530
+ node = parse :section, <<EOS
1531
+ 1. Section
1532
+
1533
+ (1)
1534
+
1535
+ something
1536
+
1537
+ (2) Schedule 1
1538
+
1539
+ (a) Part 1
1540
+
1541
+ (b) thing
1542
+ EOS
1543
+ to_xml(node, "").should == '<section id="section-1">
1544
+ <num>1.</num>
1545
+ <heading>Section</heading>
1546
+ <subsection id="section-1.1">
1547
+ <num>(1)</num>
1548
+ <content>
1549
+ <p>something</p>
1550
+ </content>
1551
+ </subsection>
1552
+ <subsection id="section-1.2">
1553
+ <num>(2)</num>
1554
+ <content>
1555
+ <p>Schedule 1</p>
1556
+ <blockList id="section-1.2.list1">
1557
+ <item id="section-1.2.list1.a">
1558
+ <num>(a)</num>
1559
+ <p>Part 1</p>
1560
+ </item>
1561
+ <item id="section-1.2.list1.b">
1562
+ <num>(b)</num>
1563
+ <p>thing</p>
1564
+ </item>
1565
+ </blockList>
1566
+ </content>
1567
+ </subsection>
1568
+ </section>'
1569
+ end
1570
+
1410
1571
  it 'should ignore escaped section headings' do
1411
1572
  node = parse :section, <<EOS
1412
1573
  1. Section
@@ -2134,6 +2295,27 @@ EOS
2134
2295
  </content>
2135
2296
  </paragraph>'
2136
2297
  end
2298
+
2299
+ it 'should allow a table as part of a subsection' do
2300
+ node = parse :subsection, <<EOS
2301
+ (1) {|
2302
+ | foo
2303
+ |}
2304
+ EOS
2305
+
2306
+ to_xml(node, '', 0).should == '<subsection id="1">
2307
+ <num>(1)</num>
2308
+ <content>
2309
+ <table id="1.table0">
2310
+ <tr>
2311
+ <td>
2312
+ <p>foo</p>
2313
+ </td>
2314
+ </tr>
2315
+ </table>
2316
+ </content>
2317
+ </subsection>'
2318
+ end
2137
2319
  end
2138
2320
 
2139
2321
  #-------------------------------------------------------------------------------
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: 0.12.0
4
+ version: 0.13.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: 2017-04-23 00:00:00.000000000 Z
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler