metanorma-standoc 1.6.4 → 1.7.3

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +17 -0
  3. data/lib/asciidoctor/standoc/base.rb +8 -16
  4. data/lib/asciidoctor/standoc/basicdoc.rng +50 -3
  5. data/lib/asciidoctor/standoc/cleanup.rb +1 -1
  6. data/lib/asciidoctor/standoc/cleanup_block.rb +0 -8
  7. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +33 -20
  8. data/lib/asciidoctor/standoc/cleanup_inline.rb +3 -1
  9. data/lib/asciidoctor/standoc/cleanup_ref.rb +17 -24
  10. data/lib/asciidoctor/standoc/cleanup_terms.rb +4 -6
  11. data/lib/asciidoctor/standoc/converter.rb +4 -49
  12. data/lib/asciidoctor/standoc/front_contributor.rb +8 -4
  13. data/lib/asciidoctor/standoc/inline.rb +7 -5
  14. data/lib/asciidoctor/standoc/isodoc.rng +48 -3
  15. data/lib/asciidoctor/standoc/macros.rb +30 -61
  16. data/lib/asciidoctor/standoc/macros_terms.rb +82 -0
  17. data/lib/asciidoctor/standoc/ref.rb +12 -21
  18. data/lib/asciidoctor/standoc/section.rb +22 -20
  19. data/lib/asciidoctor/standoc/table.rb +12 -0
  20. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +86 -0
  21. data/lib/asciidoctor/standoc/utils.rb +2 -0
  22. data/lib/metanorma/standoc/version.rb +1 -1
  23. data/metanorma-standoc.gemspec +1 -2
  24. data/spec/asciidoctor-standoc/base_spec.rb +14 -8
  25. data/spec/asciidoctor-standoc/blocks_spec.rb +14 -9
  26. data/spec/asciidoctor-standoc/cleanup_sections_spec.rb +18 -13
  27. data/spec/asciidoctor-standoc/cleanup_spec.rb +75 -11
  28. data/spec/asciidoctor-standoc/inline_spec.rb +4 -5
  29. data/spec/asciidoctor-standoc/macros_lutaml_spec.rb +1 -1
  30. data/spec/asciidoctor-standoc/macros_plantuml_spec.rb +307 -0
  31. data/spec/asciidoctor-standoc/macros_spec.rb +258 -277
  32. data/spec/asciidoctor-standoc/refs_dl_spec.rb +4 -4
  33. data/spec/asciidoctor-standoc/section_spec.rb +155 -12
  34. data/spec/asciidoctor-standoc/table_spec.rb +146 -0
  35. data/spec/fixtures/diagram_definitions.lutaml +4 -4
  36. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +49 -49
  37. data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
  38. data/spec/vcr_cassettes/isobib_get_123_1.yml +25 -25
  39. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +33 -33
  40. data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -14
  41. data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
  42. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
  43. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +71 -75
  44. metadata +7 -18
@@ -44,6 +44,75 @@ RSpec.describe Asciidoctor::Standoc do
44
44
  OUTPUT
45
45
  end
46
46
 
47
+ it "processes the Asciidoctor::Standoc index macros" do
48
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
49
+ #{ASCIIDOC_BLANK_HDR}
50
+ index:also[]
51
+ index:see[A]
52
+ index:also[B,C~x~]
53
+ index:see[D,_E_,F]
54
+ index:also[G,H,I,J]
55
+ index:see[K,L,M,N,O]
56
+ index-range:id2[P]
57
+ index-range:id3[((_P_))]
58
+ index-range:id3[(((Q, R, S)))]
59
+
60
+ Text [[id2]]
61
+
62
+ Text [[id3]]
63
+ INPUT
64
+ #{BLANK_HDR}
65
+ <sections>
66
+ <p id='_'>
67
+ <index-xref also='true'>
68
+ <primary>B</primary>
69
+ <target>
70
+ C
71
+ <sub>x</sub>
72
+ </target>
73
+ </index-xref>
74
+ <index-xref also='false'>
75
+ <primary>D</primary>
76
+ <secondary>
77
+ <em>E</em>
78
+ </secondary>
79
+ <target>F</target>
80
+ </index-xref>
81
+ <index-xref also='true'>
82
+ <primary>G</primary>
83
+ <secondary>H</secondary>
84
+ <tertiary>I</tertiary>
85
+ <target>J</target>
86
+ </index-xref>
87
+ P
88
+ <index to="id2">
89
+ <primary>P</primary>
90
+ </index>
91
+ <em>P</em>
92
+ <index to="id3">
93
+ <primary>
94
+ <em>P</em>
95
+ </primary>
96
+ </index>
97
+ <index to="id3">
98
+ <primary>Q</primary>
99
+ <secondary>R</secondary>
100
+ <tertiary>S</tertiary>
101
+ </index>
102
+ </p>
103
+ <p id='_'>
104
+ Text
105
+ <bookmark id='id2'/>
106
+ </p>
107
+ <p id='_'>
108
+ Text
109
+ <bookmark id='id3'/>
110
+ </p>
111
+ </sections>
112
+ </standard-document>
113
+ OUTPUT
114
+ end
115
+
47
116
  it "processes the Asciidoctor::Standoc variant macros" do
48
117
  expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
49
118
  #{ASCIIDOC_BLANK_HDR}
@@ -329,13 +398,11 @@ OUTPUT
329
398
  <formula id='_'>
330
399
  <stem type='MathML'>
331
400
  <math xmlns='http://www.w3.org/1998/Math/MathML'>
332
- <mover>
401
+ <mover accent="true">
333
402
  <mrow>
334
403
  <mi>X</mi>
335
404
  </mrow>
336
- <mrow>
337
405
  <mo>¯</mo>
338
- </mrow>
339
406
  </mover>
340
407
  <mo>′</mo>
341
408
  <mo>=</mo>
@@ -508,309 +575,223 @@ OUTPUT
508
575
  OUTPUT
509
576
  end
510
577
 
511
- it "processes the PlantUML macro" do
512
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{plantuml/plantuml[^./]+\.}, "plantuml/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT")
513
- #{ASCIIDOC_BLANK_HDR}
514
-
515
- [plantuml]
516
- ....
517
- @startuml
518
- Alice -> Bob: Authentication Request
519
- Bob --> Alice: Authentication Response
520
-
521
- Alice -> Bob: Another authentication Request
522
- Alice <-- Bob: another authentication Response
523
- @enduml
524
- ....
525
-
526
- [plantuml]
527
- ....
528
- Alice -> Bob: Authentication Request
529
- Bob --> Alice: Authentication Response
530
-
531
- Alice -> Bob: Another authentication Request
532
- Alice <-- Bob: another authentication Response
533
- ....
534
-
535
- [plantuml]
536
- ....
537
- @startuml filename
538
- Alice -> Bob: Authentication Request
539
- Bob --> Alice: Authentication Response
540
-
541
- Alice -> Bob: Another authentication Request
542
- Alice <-- Bob: another authentication Response
543
- @enduml
544
- ....
545
- INPUT
546
- #{BLANK_HDR}
547
- <sections><figure id="_">
548
- <image src="plantuml/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
549
- </figure>
550
- <figure id="_">
551
- <image src="plantuml/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
552
- </figure>
553
- <figure id="_">
554
- <image src="plantuml/filename.png" id="_" mimetype="image/png" height="auto" width="auto"/>
555
- </figure>
556
- </sections>
557
-
558
- </standard-document>
559
- OUTPUT
560
- end
561
-
562
- it "processes the PlantUML macro with imagesdir" do
563
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{spec/assets/[^./]+\.}, "spec/assets/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT")
564
- = Document title
565
- Author
566
- :docfile: test.adoc
567
- :nodoc:
568
- :novalid:
569
- :no-isobib:
570
- :imagesdir: spec/assets
571
-
572
- [plantuml]
573
- ....
574
- @startuml
575
- Alice -> Bob: Authentication Request
576
- Bob --> Alice: Authentication Response
577
-
578
- Alice -> Bob: Another authentication Request
579
- Alice <-- Bob: another authentication Response
580
- @enduml
581
- ....
582
- INPUT
583
- #{BLANK_HDR}
584
- <sections>
585
- <figure id="_">
586
- <image src="spec/assets/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
587
- </figure>
588
- </sections>
589
- </standard-document>
590
- OUTPUT
578
+ describe 'term inline macros' do
579
+ subject(:convert) do
580
+ xmlpp(
581
+ strip_guid(
582
+ Asciidoctor.convert(
583
+ input, backend: :standoc, header_footer: true)))
591
584
  end
592
-
593
- context 'when lutaml_diagram' do
594
585
  let(:input) do
595
- <<~"OUTPUT"
596
- = Document title
597
- Author
598
- :docfile: test.adoc
599
- :nodoc:
600
- :novalid:
601
- :no-isobib:
602
- :imagesdir: spec/assets
603
-
604
- [lutaml_diagram]
605
- ....
606
- diagram MyView {
607
- fontname "Arial"
608
- title "my diagram"
609
- class Foo {}
610
- }
611
- ....
612
- OUTPUT
613
- end
614
- let(:output) do
615
- <<~"OUTPUT"
616
- #{BLANK_HDR}
617
- <sections>
618
- <figure id="_">
619
- <image src="spec/assets/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
620
- </figure>
621
- </sections>
622
- </standard-document>
623
- OUTPUT
624
- end
586
+ <<~XML
587
+ #{ASCIIDOC_BLANK_HDR}
588
+ == Terms and Definitions
625
589
 
626
- it "processes the lutaml_diagram" do
627
- expect(
628
- xmlpp(
629
- strip_guid(Asciidoctor.convert(input, backend: :standoc, header_footer: true))
630
- .gsub(%r{".+spec\/assets\/lutaml\/[^.\/]+\.}, %q("spec/assets/_.))))
631
- .to(be_equivalent_to xmlpp(output))
632
- end
633
- end
590
+ === name2
634
591
 
635
- =begin
636
- context 'when lutaml_uml_attributes_table' do
637
- let(:example_file) { fixtures_path("diagram_definitions.lutaml") }
638
- let(:input) do
639
- <<~"OUTPUT"
640
- = Document title
641
- Author
642
- :docfile: test.adoc
643
- :nodoc:
644
- :novalid:
645
- :no-isobib:
646
- :imagesdir: spec/assets
647
-
648
- [lutaml_uml_attributes_table,#{example_file},AttributeProfile]
649
- OUTPUT
592
+ == Main
593
+
594
+ term:[name,name2] is a term
595
+ XML
650
596
  end
651
597
  let(:output) do
652
- <<~"OUTPUT"
653
- #{BLANK_HDR}
598
+ <<~XML
599
+ #{BLANK_HDR}
654
600
  <sections>
601
+ <terms id='_' obligation='normative'>
602
+ <title>Terms and definitions</title>
603
+ <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
604
+ <term id='term-name2'>
605
+ <preferred>name2</preferred>
606
+ </term>
607
+ </terms>
655
608
  <clause id='_' inline-header='false' obligation='normative'>
656
- <title>AttributeProfile</title>
657
- <table id='_'>
658
- <name>AttributeProfile attributes</name>
659
- <thead>
660
- <tr>
661
- <th valign='top' align='left'>Name</th>
662
- <th valign='top' align='left'>Definition</th>
663
- <th valign='top' align='left'>Mandatory/ Optional/ Conditional</th>
664
- <th valign='top' align='left'>Max Occur</th>
665
- <th valign='top' align='left'>Data Type</th>
666
- </tr>
667
- </thead>
668
- <tbody>
669
- <tr>
670
- <td valign='top' align='left'>addressClassProfile</td>
671
- <td valign='top' align='left'>TODO: enum ‘s definition</td>
672
- <td valign='top' align='left'>M</td>
673
- <td valign='top' align='left'>1</td>
674
- <td valign='top' align='left'>
675
- <tt>CharacterString</tt>
676
- </td>
677
- </tr>
678
- <tr>
679
- <td valign='top' align='left'>imlicistAttributeProfile</td>
680
- <td valign='top' align='left'>this is attribute definition with multiply lines</td>
681
- <td valign='top' align='left'>M</td>
682
- <td valign='top' align='left'>1</td>
683
- <td valign='top' align='left'>
684
- <tt>CharacterString</tt>
685
- </td>
686
- </tr>
687
- </tbody>
688
- </table>
609
+ <title>Main</title>
610
+ <p id='_'>
611
+ <em>name</em>
612
+ (
613
+ <xref target='term-name2'/>
614
+ ) is a term
615
+ </p>
689
616
  </clause>
690
617
  </sections>
691
618
  </standard-document>
692
- OUTPUT
619
+ XML
693
620
  end
694
621
 
695
- it "processes the lutaml_diagram" do
696
- expect(
697
- xmlpp(
698
- strip_guid(Asciidoctor.convert(input, backend: :standoc, header_footer: true))))
699
- .to(be_equivalent_to(xmlpp(output)))
622
+ it 'converts macro into the correct xml' do
623
+ expect(convert).to(be_equivalent_to(xmlpp(output)))
700
624
  end
701
- end
702
- =end
703
625
 
704
- it "processes the PlantUML macro with PlantUML disabled" do
705
- mock_plantuml_disabled
706
- expect { Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) }.to output(%r{PlantUML not installed}).to_stderr
707
- #{ASCIIDOC_BLANK_HDR}
626
+ context 'default params' do
627
+ let(:input) do
628
+ <<~XML
629
+ #{ASCIIDOC_BLANK_HDR}
708
630
 
709
- [plantuml]
710
- ....
711
- @startuml
712
- Alice -> Bob: Authentication Request
713
- Bob --> Alice: Authentication Response
631
+ == Terms and Definitions
714
632
 
715
- Alice -> Bob: Another authentication Request
716
- Alice <-- Bob: another authentication Response
717
- @enduml
718
- ....
719
- INPUT
633
+ === name
720
634
 
721
- mock_plantuml_disabled
722
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
723
- #{ASCIIDOC_BLANK_HDR}
635
+ == Main
724
636
 
725
- [plantuml]
726
- ....
727
- @startuml
728
- Alice -> Bob: Authentication Request
729
- Bob --> Alice: Authentication Response
637
+ term:[name] is a term
638
+ XML
639
+ end
640
+ let(:output) do
641
+ <<~XML
642
+ #{BLANK_HDR}
643
+ <sections>
644
+ <terms id='_' obligation='normative'>
645
+ <title>Terms and definitions</title>
646
+ <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
647
+ <term id='term-name'>
648
+ <preferred>name</preferred>
649
+ </term>
650
+ </terms>
651
+ <clause id='_' inline-header='false' obligation='normative'>
652
+ <title>Main</title>
653
+ <p id='_'>
654
+ <em>name</em>
655
+ (
656
+ <xref target='term-name' />
657
+ ) is a term
658
+ </p>
659
+ </clause>
660
+ </sections>
661
+ </standard-document>
662
+ XML
663
+ end
664
+
665
+ it 'uses `name` as termref name' do
666
+ expect(convert).to(be_equivalent_to(xmlpp(output)))
667
+ end
668
+ end
730
669
 
731
- Alice -> Bob: Another authentication Request
732
- Alice <-- Bob: another authentication Response
733
- @enduml
734
- ....
735
- INPUT
736
- #{BLANK_HDR}
737
- <sections>
738
- <sourcecode id="_" lang="plantuml">@startuml
739
- Alice -&gt; Bob: Authentication Request
740
- Bob --&gt; Alice: Authentication Response
741
-
742
- Alice -&gt; Bob: Another authentication Request
743
- Alice &lt;-- Bob: another authentication Response
744
- @enduml</sourcecode>
745
- </sections>
746
- </standard-document>
747
- OUTPUT
748
- end
670
+ context 'multiply exising ids in document' do
671
+ let(:input) do
672
+ <<~XML
673
+ #{ASCIIDOC_BLANK_HDR}
749
674
 
750
- it "processes the PlantUML macro with localdir unwritable" do
751
- mock_localdir_unwritable
752
- expect { Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) }.to output(%r{not writable for PlantUML}).to_stderr
753
- #{ASCIIDOC_BLANK_HDR}
675
+ == Terms and Definitions
754
676
 
755
- [plantuml]
756
- ....
757
- @startuml
758
- Alice -> Bob: Authentication Request
759
- Bob --> Alice: Authentication Response
677
+ === name
678
+ === name2
760
679
 
761
- Alice -> Bob: Another authentication Request
762
- Alice <-- Bob: another authentication Response
763
- @enduml
764
- ....
765
- INPUT
680
+ [[term-name]]
681
+ == Main
766
682
 
767
- mock_localdir_unwritable
768
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
769
- #{ASCIIDOC_BLANK_HDR}
683
+ paragraph
770
684
 
771
- [plantuml]
772
- ....
773
- @startuml
774
- Alice -> Bob: Authentication Request
775
- Bob --> Alice: Authentication Response
685
+ [[term-name2]]
686
+ == Second
776
687
 
777
- Alice -> Bob: Another authentication Request
778
- Alice <-- Bob: another authentication Response
779
- @enduml
780
- ....
781
- INPUT
782
- #{BLANK_HDR}
783
- <sections>
784
- <sourcecode id="_" lang="plantuml">@startuml
785
- Alice -&gt; Bob: Authentication Request
786
- Bob --&gt; Alice: Authentication Response
787
-
788
- Alice -&gt; Bob: Another authentication Request
789
- Alice &lt;-- Bob: another authentication Response
790
- @enduml</sourcecode>
791
- </sections>
792
- </standard-document>
793
- OUTPUT
794
- end
688
+ term:[name] is a term
689
+ term:[name2] is a term
690
+ XML
691
+ end
692
+ let(:output) do
693
+ <<~XML
694
+ #{BLANK_HDR}
695
+ <sections>
696
+ <terms id='_' obligation='normative'>
697
+ <title>Terms and definitions</title>
698
+ <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
699
+ <term id='term-name-1'>
700
+ <preferred>name</preferred>
701
+ </term>
702
+ <term id='term-name2-1'>
703
+ <preferred>name2</preferred>
704
+ </term>
705
+ </terms>
706
+ <clause id='term-name' inline-header='false' obligation='normative'>
707
+ <title>Main</title>
708
+ <p id='_'>paragraph</p>
709
+ </clause>
710
+ <clause id='term-name2' inline-header='false' obligation='normative'>
711
+ <title>Second</title>
712
+ <p id='_'>
713
+ <em>name</em>
714
+ (
715
+ <xref target='term-name-1' />
716
+ ) is a term
717
+ <em>name2</em>
718
+ (
719
+ <xref target='term-name2-1' />
720
+ ) is a term
721
+ </p>
722
+ </clause>
723
+ </sections>
724
+ </standard-document>
725
+ XML
726
+ end
727
+
728
+ it 'generates unique ids which do not match existing ids' do
729
+ expect(convert).to(be_equivalent_to(xmlpp(output)))
730
+ end
731
+ end
795
732
 
796
- private
733
+ context 'when missing actual ref' do
734
+ let(:input) do
735
+ <<~XML
736
+ #{ASCIIDOC_BLANK_HDR}
797
737
 
798
- def mock_plantuml_disabled
799
- expect(Asciidoctor::Standoc::PlantUMLBlockMacroBackend).to receive(:plantuml_installed?) do
800
- raise "PlantUML not installed"
801
- false
802
- end
803
- end
738
+ == Terms and Definitions
804
739
 
805
- def mock_localdir_unwritable
806
- expect(Asciidoctor::Standoc::Utils).to receive(:localdir) do
807
- "/"
808
- end.exactly(2).times
809
- end
740
+ === name identity
741
+
742
+ [[name-check]]
743
+ === name check
744
+
745
+ paragraph
810
746
 
811
- def mock_localdir_unwritable
812
- expect(File).to receive(:writable?) do
813
- false
747
+ term:[name check] is a term
748
+
749
+ term:[name identity] is a term
750
+
751
+ Moreover, term:[missing] is a term
752
+ XML
753
+ end
754
+ let(:output) do
755
+ <<~XML
756
+ #{BLANK_HDR}
757
+ <sections>
758
+ <terms id='_' obligation='normative'>
759
+ <title>Terms and definitions</title>
760
+ <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
761
+ <term id='term-name-identity'>
762
+ <preferred>name identity</preferred>
763
+ </term>
764
+ <term id='name-check'>
765
+ <preferred>name check</preferred>
766
+ <definition>
767
+ <p id='_'>paragraph</p>
768
+ <p id='_'>
769
+ <em>name check</em>
770
+ (
771
+ <xref target='name-check'/>
772
+ ) is a term
773
+ </p>
774
+ <p id='_'>
775
+ <em>name identity</em>
776
+ (
777
+ <xref target='term-name-identity'/>
778
+ ) is a term
779
+ </p>
780
+ <p id="_">Moreover, (<strong>term “missing” not resolved</strong>) is a term
781
+ </p>
782
+ </definition>
783
+ </term>
784
+ </terms>
785
+ </sections>
786
+ </standard-document>
787
+ XML
788
+ end
789
+
790
+ it 'generates unique ids which do not match existing ids' do
791
+ expect(convert).to(be_equivalent_to(xmlpp(output)))
792
+ end
814
793
  end
815
- end
794
+
795
+ end
796
+
816
797
  end