metanorma-standoc 1.10.6 → 1.10.7

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 (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asciidoctor/standoc/base.rb +3 -13
  3. data/lib/asciidoctor/standoc/cleanup.rb +26 -1
  4. data/lib/asciidoctor/standoc/cleanup_block.rb +3 -71
  5. data/lib/asciidoctor/standoc/cleanup_inline.rb +0 -102
  6. data/lib/asciidoctor/standoc/cleanup_reqt.rb +3 -3
  7. data/lib/asciidoctor/standoc/cleanup_section_names.rb +5 -5
  8. data/lib/asciidoctor/standoc/cleanup_table.rb +68 -0
  9. data/lib/asciidoctor/standoc/cleanup_text.rb +5 -2
  10. data/lib/asciidoctor/standoc/cleanup_xref.rb +107 -0
  11. data/lib/asciidoctor/standoc/converter.rb +12 -0
  12. data/lib/asciidoctor/standoc/isodoc.rng +9 -0
  13. data/lib/asciidoctor/standoc/macros.rb +14 -43
  14. data/lib/asciidoctor/standoc/macros_note.rb +45 -0
  15. data/lib/metanorma/standoc/version.rb +1 -1
  16. data/spec/asciidoctor/base_spec.rb +0 -33
  17. data/spec/asciidoctor/blank_spec.rb +37 -0
  18. data/spec/asciidoctor/blocks_spec.rb +31 -0
  19. data/spec/asciidoctor/cleanup_sections_spec.rb +146 -5
  20. data/spec/asciidoctor/cleanup_spec.rb +1 -1
  21. data/spec/asciidoctor/inline_spec.rb +36 -0
  22. data/spec/asciidoctor/macros_plantuml_spec.rb +1 -1
  23. data/spec/asciidoctor/macros_spec.rb +1 -1
  24. data/spec/fixtures/datamodel_description_sections_tree.xml +3 -2
  25. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +45 -45
  26. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
  27. data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
  28. data/spec/vcr_cassettes/isobib_get_123_1.yml +23 -23
  29. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +33 -33
  30. data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
  31. data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
  32. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +16 -16
  33. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +52 -50
  34. metadata +6 -2
@@ -6,6 +6,7 @@ require "csv"
6
6
  require_relative "./macros_plantuml"
7
7
  require_relative "./macros_terms"
8
8
  require_relative "./macros_form"
9
+ require_relative "./macros_note"
9
10
  require_relative "./datamodel/attributes_table_preprocessor"
10
11
  require_relative "./datamodel/diagram_preprocessor"
11
12
  require "metanorma-plugin-datastruct"
@@ -41,7 +42,7 @@ module Asciidoctor
41
42
  def process(_parent, target, attr)
42
43
  args = preprocess_attrs(attr) or return
43
44
  ret = "<index-xref also='#{target == 'also'}'>"\
44
- "<primary>#{args[:primary]}</primary>"
45
+ "<primary>#{args[:primary]}</primary>"
45
46
  ret += "<secondary>#{args[:secondary]}</secondary>" if args[:secondary]
46
47
  ret += "<tertiary>#{args[:tertiary]}</tertiary>" if args[:tertiary]
47
48
  ret + "<target>#{args[:target]}</target></index-xref>"
@@ -50,7 +51,7 @@ module Asciidoctor
50
51
 
51
52
  class IndexRangeInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
52
53
  use_dsl
53
- named "index-range".to_sym
54
+ named :"index-range"
54
55
  parse_content_as :text
55
56
 
56
57
  def process(parent, target, attr)
@@ -121,35 +122,6 @@ module Asciidoctor
121
122
  end
122
123
  end
123
124
 
124
- class ToDoAdmonitionBlock < Extensions::BlockProcessor
125
- use_dsl
126
- named :TODO
127
- on_contexts :example, :paragraph
128
-
129
- def process(parent, reader, attrs)
130
- attrs["name"] = "todo"
131
- attrs["caption"] = "TODO"
132
- create_block(parent, :admonition, reader.lines, attrs,
133
- content_model: :compound)
134
- end
135
- end
136
-
137
- class ToDoInlineAdmonitionBlock < Extensions::Treeprocessor
138
- def process(document)
139
- (document.find_by context: :paragraph).each do |para|
140
- next unless /^TODO: /.match? para.lines[0]
141
-
142
- parent = para.parent
143
- para.set_attr("name", "todo")
144
- para.set_attr("caption", "TODO")
145
- para.lines[0].sub!(/^TODO: /, "")
146
- todo = Block.new(parent, :admonition, attributes: para.attributes,
147
- source: para.lines, content_model: :compound)
148
- parent.blocks[parent.blocks.index(para)] = todo
149
- end
150
- end
151
- end
152
-
153
125
  class AutonumberInlineMacro < Extensions::InlineMacroProcessor
154
126
  use_dsl
155
127
  named :autonumber
@@ -177,18 +149,6 @@ module Asciidoctor
177
149
  end
178
150
  end
179
151
 
180
- class FootnoteBlockInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
181
- use_dsl
182
- named :footnoteblock
183
- parse_content_as :text
184
- using_format :short
185
-
186
- def process(parent, _target, attrs)
187
- out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
188
- %{<footnoteblock>#{out}</footnoteblock>}
189
- end
190
- end
191
-
192
152
  class AddMacro < Asciidoctor::Extensions::InlineMacroProcessor
193
153
  use_dsl
194
154
  named :add
@@ -229,5 +189,16 @@ module Asciidoctor
229
189
  "<toc>#{content}</toc>"
230
190
  end
231
191
  end
192
+
193
+ class PassInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
194
+ use_dsl
195
+ named :"pass-format"
196
+
197
+ def process(parent, target, attrs)
198
+ format = target || "metanorma"
199
+ out = Asciidoctor::Inline.new(parent, :quoted, attrs[1]).convert
200
+ %{<passthrough formats="#{format}">#{out}</passthrough>}
201
+ end
202
+ end
232
203
  end
233
204
  end
@@ -0,0 +1,45 @@
1
+ module Asciidoctor
2
+ module Standoc
3
+ class ToDoAdmonitionBlock < Extensions::BlockProcessor
4
+ use_dsl
5
+ named :TODO
6
+ on_contexts :example, :paragraph
7
+
8
+ def process(parent, reader, attrs)
9
+ attrs["name"] = "todo"
10
+ attrs["caption"] = "TODO"
11
+ create_block(parent, :admonition, reader.lines, attrs,
12
+ content_model: :compound)
13
+ end
14
+ end
15
+
16
+ class ToDoInlineAdmonitionBlock < Extensions::Treeprocessor
17
+ def process(document)
18
+ (document.find_by context: :paragraph).each do |para|
19
+ next unless /^TODO: /.match? para.lines[0]
20
+
21
+ parent = para.parent
22
+ para.set_attr("name", "todo")
23
+ para.set_attr("caption", "TODO")
24
+ para.lines[0].sub!(/^TODO: /, "")
25
+ todo = Block.new(parent, :admonition, attributes: para.attributes,
26
+ source: para.lines,
27
+ content_model: :compound)
28
+ parent.blocks[parent.blocks.index(para)] = todo
29
+ end
30
+ end
31
+ end
32
+
33
+ class FootnoteBlockInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
34
+ use_dsl
35
+ named :footnoteblock
36
+ parse_content_as :text
37
+ using_format :short
38
+
39
+ def process(parent, _target, attrs)
40
+ out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
41
+ %{<footnoteblock>#{out}</footnoteblock>}
42
+ end
43
+ end
44
+ end
45
+ end
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "1.10.6".freeze
22
+ VERSION = "1.10.7".freeze
23
23
  end
24
24
  end
@@ -6,39 +6,6 @@ RSpec.describe Asciidoctor::Standoc do
6
6
  expect(Metanorma::Standoc::VERSION).not_to be nil
7
7
  end
8
8
 
9
- it "processes a blank document" do
10
- input = <<~INPUT
11
- #{ASCIIDOC_BLANK_HDR}
12
- INPUT
13
- output = <<~OUTPUT
14
- #{BLANK_HDR}
15
- <sections/>
16
- </standard-document>
17
- OUTPUT
18
- expect(xmlpp(Asciidoctor.convert(input, *OPTIONS)))
19
- .to be_equivalent_to xmlpp(output)
20
- end
21
-
22
- it "converts a blank document" do
23
- FileUtils.rm_f "test.doc"
24
- input = <<~INPUT
25
- = Document title
26
- Author
27
- :docfile: test.adoc
28
- :novalid:
29
- INPUT
30
- output = <<~OUTPUT
31
- #{BLANK_HDR}
32
- <sections/>
33
- </standard-document>
34
- OUTPUT
35
- expect(xmlpp(Asciidoctor.convert(input, *OPTIONS)))
36
- .to be_equivalent_to xmlpp(output)
37
- expect(File.exist?("test.doc")).to be true
38
- expect(File.exist?("test.pdf")).to be true
39
- expect(File.exist?("htmlstyle.css")).to be false
40
- end
41
-
42
9
  it "assigns default scripts to major languages" do
43
10
  FileUtils.rm_f "test.doc"
44
11
  input = <<~INPUT
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+ require "fileutils"
3
+
4
+ RSpec.describe Asciidoctor::Standoc do
5
+ it "processes a blank document" do
6
+ input = <<~INPUT
7
+ #{ASCIIDOC_BLANK_HDR}
8
+ INPUT
9
+ output = <<~OUTPUT
10
+ #{BLANK_HDR}
11
+ <sections/>
12
+ </standard-document>
13
+ OUTPUT
14
+ expect(xmlpp(Asciidoctor.convert(input, *OPTIONS)))
15
+ .to be_equivalent_to xmlpp(output)
16
+ end
17
+
18
+ it "converts a blank document" do
19
+ FileUtils.rm_f "test.doc"
20
+ input = <<~INPUT
21
+ = Document title
22
+ Author
23
+ :docfile: test.adoc
24
+ :novalid:
25
+ INPUT
26
+ output = <<~OUTPUT
27
+ #{BLANK_HDR}
28
+ <sections/>
29
+ </standard-document>
30
+ OUTPUT
31
+ expect(xmlpp(Asciidoctor.convert(input, *OPTIONS)))
32
+ .to be_equivalent_to xmlpp(output)
33
+ expect(File.exist?("test.doc")).to be true
34
+ expect(File.exist?("test.pdf")).to be true
35
+ expect(File.exist?("htmlstyle.css")).to be false
36
+ end
37
+ end
@@ -1605,4 +1605,35 @@ RSpec.describe Asciidoctor::Standoc do
1605
1605
  expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
1606
1606
  .to be_equivalent_to xmlpp(output)
1607
1607
  end
1608
+
1609
+ it "processes hard breaks" do
1610
+ input = <<~INPUT
1611
+ #{ASCIIDOC_BLANK_HDR}
1612
+
1613
+ [%hardbreaks]
1614
+ One hardbreak
1615
+ Two
1616
+
1617
+ Three hardbreaks +
1618
+ Four
1619
+ INPUT
1620
+ output = <<~OUTPUT
1621
+ #{BLANK_HDR}
1622
+ <sections>
1623
+ <p id='_'>
1624
+ One hardbreak
1625
+ <br/>
1626
+ Two
1627
+ </p>
1628
+ <p id='_'>
1629
+ Three hardbreaks
1630
+ <br/>
1631
+ Four
1632
+ </p>
1633
+ </sections>
1634
+ </standard-document>
1635
+ OUTPUT
1636
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
1637
+ .to be_equivalent_to xmlpp(output)
1638
+ end
1608
1639
  end
@@ -1610,7 +1610,7 @@ RSpec.describe Asciidoctor::Standoc do
1610
1610
  == Clause
1611
1611
 
1612
1612
  [.variant-title,type=toc]
1613
- Clause _A_ stem:[x]
1613
+ Clause _A_ stem:[y]
1614
1614
 
1615
1615
  Text
1616
1616
  INPUT
@@ -1622,8 +1622,8 @@ RSpec.describe Asciidoctor::Standoc do
1622
1622
  <p id='_'>Text</p>
1623
1623
  <clause id='_' inline-header='false' obligation='normative'>
1624
1624
  <title>Subclause</title>
1625
- <variant-title variant_title='true' type='sub'>&#8220;A&#8221; &#8216;B&#8217;</variant-title>
1626
- <variant-title variant_title='true' type='toc'>
1625
+ <variant-title type='sub'>&#8220;A&#8221; &#8216;B&#8217;</variant-title>
1626
+ <variant-title type='toc'>
1627
1627
  Clause
1628
1628
  <em>A</em>
1629
1629
  <stem type='MathML'>
@@ -1638,12 +1638,153 @@ RSpec.describe Asciidoctor::Standoc do
1638
1638
  </sections>
1639
1639
  <annex id='_' inline-header='false' obligation='normative'>
1640
1640
  <title>Clause</title>
1641
- <variant-title variant_title='true' type='toc'>
1641
+ <variant-title type='toc'>
1642
1642
  Clause
1643
1643
  <em>A</em>
1644
1644
  <stem type='MathML'>
1645
1645
  <math xmlns='http://www.w3.org/1998/Math/MathML'>
1646
- <mi>x</mi>
1646
+ <mi>y</mi>
1647
+ </math>
1648
+ </stem>
1649
+ </variant-title>
1650
+ <p id='_'>Text</p>
1651
+ </annex>
1652
+ </standard-document>
1653
+ OUTPUT
1654
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
1655
+ .to be_equivalent_to xmlpp(output)
1656
+ end
1657
+
1658
+ it "processes TOC clause" do
1659
+ input = <<~INPUT
1660
+ #{ASCIIDOC_BLANK_HDR}
1661
+
1662
+ == Clause
1663
+ Text
1664
+
1665
+ [type=toc]
1666
+ === Table of contents
1667
+
1668
+ Text at the start
1669
+
1670
+ ==== Toc 1
1671
+
1672
+ * <<cl2>>
1673
+ ** <<a1>>
1674
+
1675
+ ==== Toc 2
1676
+
1677
+ * <<cl2,some text>>
1678
+ ** <<a1,some more text>>
1679
+
1680
+ [[cl2]]
1681
+ == Clause2
1682
+
1683
+ [.variant-title,type=toc]
1684
+ Clause _A_ stem:[x]
1685
+
1686
+ [.variant-title,type=sub]
1687
+ "A" 'B'
1688
+
1689
+ Text
1690
+
1691
+ [[a1]]
1692
+ [appendix]
1693
+ == Clause
1694
+
1695
+ [.variant-title,type=toc]
1696
+ Clause _A_ stem:[y]
1697
+
1698
+ Text
1699
+ INPUT
1700
+ output = <<~OUTPUT
1701
+ #{BLANK_HDR}
1702
+ <sections>
1703
+ <clause id='_' inline-header='false' obligation='normative'>
1704
+ <title>Clause</title>
1705
+ <p id='_'>Text</p>
1706
+ <clause id='_' type='toc' inline-header='false' obligation='normative'>
1707
+ <title>Table of contents</title>
1708
+ <p id='_'>Text at the start</p>
1709
+ <clause id='_' inline-header='false' obligation='normative'>
1710
+ <title>Toc 1</title>
1711
+ <toc>
1712
+ <ul id='_'>
1713
+ <li>
1714
+ <p id='_'>
1715
+ <xref target='cl2'>
1716
+ Clause
1717
+ <em>A</em>
1718
+ <stem type='MathML'>
1719
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
1720
+ <mi>x</mi>
1721
+ </math>
1722
+ </stem>
1723
+ </xref>
1724
+ </p>
1725
+ <ul id='_'>
1726
+ <li>
1727
+ <p id='_'>
1728
+ <xref target='a1'>
1729
+ Clause
1730
+ <em>A</em>
1731
+ <stem type='MathML'>
1732
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
1733
+ <mi>y</mi>
1734
+ </math>
1735
+ </stem>
1736
+ </xref>
1737
+ </p>
1738
+ </li>
1739
+ </ul>
1740
+ </li>
1741
+ </ul>
1742
+ </toc>
1743
+ </clause>
1744
+ <clause id='_' inline-header='false' obligation='normative'>
1745
+ <title>Toc 2</title>
1746
+ <toc>
1747
+ <ul id='_'>
1748
+ <li>
1749
+ <p id='_'>
1750
+ <xref target='cl2'>some text</xref>
1751
+ </p>
1752
+ <ul id='_'>
1753
+ <li>
1754
+ <p id='_'>
1755
+ <xref target='a1'>some more text</xref>
1756
+ </p>
1757
+ </li>
1758
+ </ul>
1759
+ </li>
1760
+ </ul>
1761
+ </toc>
1762
+ </clause>
1763
+ </clause>
1764
+ </clause>
1765
+ <clause id='cl2' inline-header='false' obligation='normative'>
1766
+ <title>Clause2</title>
1767
+ <variant-title type='sub'>&#8220;A&#8221; &#8216;B&#8217;</variant-title>
1768
+ <variant-title type='toc'>
1769
+ Clause
1770
+ <em>A</em>
1771
+ <stem type='MathML'>
1772
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
1773
+ <mi>x</mi>
1774
+ </math>
1775
+ </stem>
1776
+ </variant-title>
1777
+ <p id='_'>Text</p>
1778
+ </clause>
1779
+ </sections>
1780
+ <annex id='a1' inline-header='false' obligation='normative'>
1781
+ <title>Clause</title>
1782
+ <variant-title type='toc'>
1783
+ Clause
1784
+ <em>A</em>
1785
+ <stem type='MathML'>
1786
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
1787
+ <mi>y</mi>
1647
1788
  </math>
1648
1789
  </stem>
1649
1790
  </variant-title>
@@ -819,7 +819,7 @@ RSpec.describe Asciidoctor::Standoc do
819
819
  <abstract format="text/plain" language="en" script="Latn">IEC 60050-103:2009 gives the terminology relative to functions of one or more variables. Together with IEC 60050-102, it covers the mathematical terminology used in the fields of electricity, electronics and telecommunications. It maintains a clear distinction between mathematical concepts and physical concepts, even if some terms are used in both cases. Mathematical symbols are generally in accordance with IEC 60027-1 and ISO 80000-2. This standard cancels and replaces Sections 101-13, 101-14 and 101-15 of International Standard IEC 60050-101:1998. It has the status of a horizontal standard in accordance with IEC Guide 108.</abstract>
820
820
  <status>
821
821
  <stage>60</stage>
822
- <substage>00</substage>
822
+ <substage>60</substage>
823
823
  </status>
824
824
  <copyright>
825
825
  <from>2009</from>
@@ -480,4 +480,40 @@ RSpec.describe Asciidoctor::Standoc do
480
480
  expect((strip_guid(Asciidoctor.convert(input, *OPTIONS))))
481
481
  .to be_equivalent_to(output)
482
482
  end
483
+
484
+ it "processes format-specific inline pass" do
485
+ input = <<~INPUT
486
+ #{ASCIIDOC_BLANK_HDR}
487
+
488
+ pass-format:rfc,html[<abc>X &gt; Y</abc>]
489
+ INPUT
490
+ output = <<~OUTPUT
491
+ #{BLANK_HDR}
492
+ <sections>
493
+ <p id='_'>
494
+ <passthrough formats='rfc,html'>&lt;abc&gt;X &gt; Y&lt;/abc&gt;</passthrough>
495
+ </p>
496
+ </sections>
497
+ </standard-document>
498
+ OUTPUT
499
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
500
+ .to be_equivalent_to xmlpp(output)
501
+ end
502
+
503
+ it "processes Metanorma XML inline pass" do
504
+ input = <<~INPUT
505
+ #{ASCIIDOC_BLANK_HDR}
506
+
507
+ +<abc>X &gt;+ +++Y+++ pass:c[</abc>]
508
+ INPUT
509
+ output = <<~OUTPUT
510
+ #{BLANK_HDR}
511
+ <sections>
512
+ <p id='_'>&lt;abc&gt;X &gt; Y &lt;/abc&gt;</p>
513
+ </sections>
514
+ </standard-document>
515
+ OUTPUT
516
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
517
+ .to be_equivalent_to xmlpp(output)
518
+ end
483
519
  end
@@ -201,7 +201,7 @@ RSpec.describe Asciidoctor::Standoc do
201
201
  <tr>
202
202
  <th valign='top' align='left'>Name</th>
203
203
  <th valign='top' align='left'>Definition</th>
204
- <th valign='top' align='left'>Mandatory/ Optional/ Conditional</th>
204
+ <th valign='top' align='left'>Mandatory / Optional / Conditional</th>
205
205
  <th valign='top' align='left'>Max Occur</th>
206
206
  <th valign='top' align='left'>Data Type</th>
207
207
  </tr>
@@ -1187,7 +1187,7 @@ RSpec.describe Asciidoctor::Standoc do
1187
1187
  </clause>
1188
1188
  <clause id='clause1Ab' inline-header='false' obligation='normative'>
1189
1189
  <title>Clause 1Ab</title>
1190
- <variant-title variant_title='true' type='toc'>1Ab Clause</variant-title>
1190
+ <variant-title type='toc'>1Ab Clause</variant-title>
1191
1191
  </clause>
1192
1192
  </clause>
1193
1193
  <clause id='clause1B' inline-header='false' obligation='normative'>
@@ -37,7 +37,7 @@
37
37
  <table id='section-EAID_82206E96_8D23_48dd_AC2F_31939C484AF2' width='100%'>
38
38
  <name>
39
39
  Elements of &#8220;ISO 19135 Procedures for item registration
40
- XML::RE_Register&#8221; (class)
40
+ XML::RE_Register&#8221; (interface)
41
41
  </name>
42
42
  <tbody>
43
43
  <tr>
@@ -288,7 +288,7 @@
288
288
  as its value a set of URI&#8217;s, each referencing
289
289
  information about online resources associated with the
290
290
  register. EXAMPLE
291
- &#239;&#191;&#189;http://www.digest.org/Navigate2.htm&#239;&#191;
291
+ &#239;&#191;&#189;http://www.digest.org/Navigate2.htm&#239;&#191;&#189; and &#239;&#191;&#189;http://www.epa.gov/opppmsd1/PPISdata/index.html&#239;&#191;&#189; are sample valuescorresponding value of the attribute
292
292
  <em>OnLineResource.linkage</em>
293
293
  specifies a resource providing access to the complete
294
294
  content of the register. EXAMPLE
@@ -313,6 +313,7 @@
313
313
  <td colspan='7' valign='top' align='left'>
314
314
  <p id='_'>
315
315
  <tt>count(self.version +self.dateOfLastChange) &gt;= 1</tt>
316
+ : ``
316
317
  </p>
317
318
  </td>
318
319
  </tr>