metanorma-standoc 1.3.20 → 1.3.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,9 @@ module Asciidoctor
7
7
  unnumbered: node.option?("unnumbered") ? "true" : nil,
8
8
  subsequence: node.attr("subsequence"),
9
9
  alt: node.attr("alt"),
10
- summary: node.attr("summary") }
10
+ summary: node.attr("summary"),
11
+ width: node.attr("width"),
12
+ }
11
13
  end
12
14
 
13
15
  def table(node)
@@ -30,27 +30,17 @@ module Asciidoctor
30
30
  docfile.nil? ? './' : Pathname.new(docfile).parent.to_s + '/'
31
31
  end
32
32
 
33
- def current_location(n)
34
- return "Line #{n.lineno}" if n.respond_to?(:lineno) &&
35
- !n.lineno.nil? && !n.lineno.empty?
36
- return "Line #{n.line}" if n.respond_to?(:line) &&
37
- !n.line.nil?
38
- return "ID #{n.id}" if n.respond_to?(:id) && !n.id.nil?
39
- while !n.nil? &&
40
- (!n.respond_to?(:level) || n.level.positive?) &&
41
- (!n.respond_to?(:context) || n.context != :section)
42
- n = n.parent
43
- return "Section: #{n.title}" if n&.respond_to?(:context) &&
44
- n&.context == :section
45
- end
46
- "??"
47
- end
48
-
49
33
  def smartformat(n)
50
34
  n.gsub(/ --? /, " — ").
51
35
  gsub(/--/, "&#8212;").smart_format.gsub(/</, "&lt;").gsub(/>/, "&gt;")
52
36
  end
53
37
 
38
+ def endash_date(elem)
39
+ elem.traverse do |n|
40
+ n.text? and n.replace(n.text.gsub(/\s+--?\s+/, "&#8211;").gsub(/--/, "&#8211;"))
41
+ end
42
+ end
43
+
54
44
  # Set hash value using keys path
55
45
  # mod from https://stackoverflow.com/a/42425884
56
46
  def set_nested_value(hash, keys, new_val)
@@ -76,40 +66,7 @@ module Asciidoctor
76
66
  end
77
67
  end
78
68
 
79
- def mn_code(code)
80
- code.sub(/^\(/, "[").sub(/\).*$/, "]").sub(/^nofetch\((.+)\)$/, "\\1")
81
- end
82
-
83
- def emend_biblio(xml, code, title, usrlbl)
84
- unless xml.at("/bibitem/docidentifier[not(@type = 'DOI')][text()]")
85
- warn "ERROR: No document identifier retrieved for #{code}"
86
- xml.root << "<docidentifier>#{code}</docidentifier>"
87
- end
88
- unless xml.at("/bibitem/title[text()]")
89
- warn "ERROR: No title retrieved for #{code}"
90
- xml.root << "<title>#{title || "(MISSING TITLE)"}</title>"
91
- end
92
- usrlbl and xml.at("/bibitem/docidentifier").next =
93
- "<docidentifier type='metanorma'>#{mn_code(usrlbl)}</docidentifier>"
94
- end
95
-
96
- def endash_date(elem)
97
- elem.traverse do |n|
98
- n.text? and n.replace(n.text.gsub(/\s+--?\s+/, "&#8211;").gsub(/--/, "&#8211;"))
99
- end
100
- end
101
-
102
- def smart_render_xml(x, code, title, usrlbl)
103
- xstr = x.to_xml if x.respond_to? :to_xml
104
- xml = Nokogiri::XML(xstr)
105
- emend_biblio(xml, code, title, usrlbl)
106
- xml.xpath("//date").each { |d| endash_date(d) }
107
- xml.traverse do |n|
108
- n.text? and n.replace(smartformat(n.text))
109
- end
110
- xml.to_xml.sub(/<\?[^>]+>/, "")
111
- end
112
-
69
+ =begin
113
70
  def warning(node, msg, text)
114
71
  return if @novalid
115
72
  warntext = "asciidoctor: WARNING"\
@@ -117,6 +74,7 @@ module Asciidoctor
117
74
  warntext += ": #{text}" if text
118
75
  warn warntext
119
76
  end
77
+ =end
120
78
 
121
79
  def flatten_rawtext_lines(node, result)
122
80
  node.lines.each do |x|
@@ -222,7 +180,8 @@ module Asciidoctor
222
180
  type
223
181
  end
224
182
 
225
- SUBCLAUSE_XPATH = "//clause[not(parent::sections)]".freeze
183
+ SUBCLAUSE_XPATH = "//clause[not(parent::sections)]"\
184
+ "[not(ancestor::boilerplate)]".freeze
226
185
  end
227
186
  end
228
187
  end
@@ -25,24 +25,37 @@ module Asciidoctor
25
25
  @iev = init_iev or return
26
26
  iev = @iev.fetch(locality, xmldoc&.at("//language")&.text || "en") or next
27
27
  pref.include?(iev.downcase) or
28
- warn %(Term "#{pref[0]}" does not match IEV #{locality} "#{iev}")
28
+ #warn %(Term "#{pref[0]}" does not match IEV #{locality} "#{iev}")
29
+ @log.add("Bibliography", t, %(Term "#{pref[0]}" does not match IEV #{locality} "#{iev}"))
29
30
  end
30
31
  end
31
32
 
32
33
  def content_validate(doc)
33
34
  section_validate(doc)
35
+ repeat_id_validate(doc.root)
34
36
  iev_validate(doc.root)
35
37
  end
36
38
 
39
+ def repeat_id_validate(doc)
40
+ ids = {}
41
+ doc.xpath("//*[@id]").each do |x|
42
+ if ids[x["id"]]
43
+ @log.add("Anchors", x, "Anchor #{x['id']} has already been used at line #{ids[x['id']]}")
44
+ else
45
+ ids[x["id"]] = x.line
46
+ end
47
+ end
48
+ end
49
+
37
50
  def schema_validate(doc, schema)
38
51
  Tempfile.open(["tmp", ".xml"], :encoding => 'UTF-8') do |f|
39
52
  begin
40
53
  f.write(doc.to_xml)
41
54
  f.close
42
55
  errors = Jing.new(schema).validate(f.path)
43
- warn "Valid!" if errors.none?
56
+ warn "Syntax Valid!" if errors.none?
44
57
  errors.each do |error|
45
- warn "#{error[:message]} @ #{error[:line]}:#{error[:column]}"
58
+ @log.add("Syntax", "XML Line #{"%06d" % error[:line]}:#{error[:column]}", error[:message])
46
59
  end
47
60
  rescue Jing::Error => e
48
61
  abort "Jing failed with error: #{e}"
@@ -14,16 +14,17 @@ module Asciidoctor
14
14
  callouts = x.elements.select { |e| e.name == "callout" }
15
15
  annotations = x.elements.select { |e| e.name == "annotation" }
16
16
  if callouts.size != annotations.size
17
- warn "#{x['id']}: mismatch of callouts and annotations"
17
+ #warn "#{x['id']}: mismatch of callouts and annotations"
18
+ @log.add("Asciidoctor Input", x, "mismatch of callouts and annotations")
18
19
  end
19
20
  end
20
21
  end
21
22
 
22
23
  def style_warning(node, msg, text = nil)
23
- return if @novalid
24
- w = "ISO style: WARNING (#{Utils::current_location(node)}): #{msg}"
24
+ w = msg
25
25
  w += ": #{text}" if text
26
- warn w
26
+ #warn w
27
+ @log.add("Style Warning", node, w)
27
28
  end
28
29
 
29
30
  def asset_title_style(root)
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Standoc
3
- VERSION = "1.3.20".freeze
3
+ VERSION = "1.3.21".freeze
4
4
  end
5
5
  end
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_dependency "asciidoctor", "~> 2.0.0"
30
30
  spec.add_dependency "ruby-jing"
31
- spec.add_dependency "isodoc", "~> 1.0.0"
31
+ spec.add_dependency "isodoc", "~> 1.0.20"
32
32
  spec.add_dependency "iev", "~> 0.2.1"
33
33
  spec.add_dependency "relaton", "~> 0.10.0"
34
34
  spec.add_dependency "relaton-iev", "~> 0.1.0"
@@ -47,7 +47,6 @@ Gem::Specification.new do |spec|
47
47
  spec.add_development_dependency "rubocop", "= 0.54.0"
48
48
  spec.add_development_dependency "simplecov", "~> 0.15"
49
49
  spec.add_development_dependency "timecop", "~> 0.9"
50
- spec.add_development_dependency "metanorma", "~> 0.3.0"
51
50
  spec.add_development_dependency "vcr", "~> 5.0.0"
52
51
  spec.add_development_dependency "webmock"
53
52
  #spec.add_development_dependency "relaton-iec"
@@ -449,7 +449,7 @@ RSpec.describe Asciidoctor::Standoc do
449
449
  OUTPUT
450
450
  end
451
451
 
452
- it "removes extraneous material from Normative References" do
452
+ it "removes initial extraneous material from Normative References" do
453
453
  expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
454
454
  #{ASCIIDOC_BLANK_HDR}
455
455
  [bibliography]
@@ -458,6 +458,8 @@ RSpec.describe Asciidoctor::Standoc do
458
458
  This is extraneous information
459
459
 
460
460
  * [[[iso216,ISO 216]]], _Reference_
461
+
462
+ This is also extraneous information
461
463
  INPUT
462
464
  #{BLANK_HDR}
463
465
  <sections></sections>
@@ -473,12 +475,85 @@ RSpec.describe Asciidoctor::Standoc do
473
475
  </organization>
474
476
  </contributor>
475
477
  </bibitem>
478
+ <p id='_'>This is also extraneous information</p>
476
479
  </references>
477
480
  </bibliography>
478
481
  </standard-document>
479
482
  OUTPUT
480
483
  end
481
484
 
485
+ it "sorts references with their notes in Bibliography" do
486
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
487
+ #{ASCIIDOC_BLANK_HDR}
488
+ [bibliography]
489
+ == Bibliography
490
+
491
+ This is extraneous information
492
+
493
+ * [[[iso216,ISO 216]]], _Reference_
494
+
495
+ NOTE: ABC
496
+
497
+ NOTE: DEF
498
+
499
+ This is further extraneous information
500
+
501
+ NOTE: GHI
502
+
503
+ * [[[iso216,ISO 215]]], _Reference_
504
+
505
+ NOTE: JKL
506
+
507
+ This is also extraneous information
508
+ INPUT
509
+ #{BLANK_HDR}
510
+ <sections> </sections>
511
+ <bibliography>
512
+ <references id='_' obligation='informative'>
513
+ <title>Bibliography</title>
514
+ <p id='_'>This is extraneous information</p>
515
+ <bibitem id='iso216' type='standard'>
516
+ <title format='text/plain'>Reference</title>
517
+ <docidentifier>ISO 216</docidentifier>
518
+ <contributor>
519
+ <role type='publisher'/>
520
+ <organization>
521
+ <name>ISO</name>
522
+ </organization>
523
+ </contributor>
524
+ </bibitem>
525
+ <note id='_'>
526
+ <p id='_'>ABC</p>
527
+ </note>
528
+ <note id='_'>
529
+ <p id='_'>DEF</p>
530
+ </note>
531
+ <bibitem id='iso216' type='standard'>
532
+ <title format='text/plain'>Reference</title>
533
+ <docidentifier>ISO 215</docidentifier>
534
+ <contributor>
535
+ <role type='publisher'/>
536
+ <organization>
537
+ <name>ISO</name>
538
+ </organization>
539
+ </contributor>
540
+ </bibitem>
541
+ <note id='_'>
542
+ <p id='_'>JKL</p>
543
+ </note>
544
+ <p id='_'>
545
+ This is further extraneous information
546
+ <note id='_'>
547
+ <p id='_'>GHI</p>
548
+ </note>
549
+ </p>
550
+ <p id='_'>This is also extraneous information</p>
551
+ </references>
552
+ </bibliography>
553
+ </standard-document>
554
+ OUTPUT
555
+ end
556
+
482
557
  it "inserts IDs into paragraphs" do
483
558
  expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
484
559
  #{ASCIIDOC_BLANK_HDR}
@@ -689,6 +764,7 @@ RSpec.describe Asciidoctor::Standoc do
689
764
  it "moves footnotes inside figures" do
690
765
  expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
691
766
  #{ASCIIDOC_BLANK_HDR}
767
+ .Figuretitle.footnote:[xyz]
692
768
  image::spec/examples/rice_images/rice_image1.png[]
693
769
 
694
770
  footnote:[This is a footnote to a figure]
@@ -699,6 +775,12 @@ RSpec.describe Asciidoctor::Standoc do
699
775
  INPUT
700
776
  #{BLANK_HDR}
701
777
  <sections><figure id="_">
778
+ <name>
779
+ Figuretitle.
780
+ <fn reference='1'>
781
+ <p id='_'>xyz</p>
782
+ </fn>
783
+ </name>
702
784
  <image src="spec/examples/rice_images/rice_image1.png" id="_" mimetype="image/png" height="auto" width="auto"/>
703
785
  <fn reference="a">
704
786
  <p id="_">This is a footnote to a figure</p>
@@ -707,7 +789,7 @@ RSpec.describe Asciidoctor::Standoc do
707
789
  </fn></figure>
708
790
  <p id='_'>
709
791
  A
710
- <fn reference='1'>
792
+ <fn reference='2'>
711
793
  <p id='_'>This is a third footnote</p>
712
794
  </fn>
713
795
  </p>
@@ -1579,6 +1661,86 @@ it "sorts symbols lists" do
1579
1661
  OUTPUT
1580
1662
  end
1581
1663
 
1664
+ it "moves inherit macros to correct location" do
1665
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
1666
+ #{ASCIIDOC_BLANK_HDR}
1667
+
1668
+ == Clause
1669
+
1670
+ [.requirement,subsequence="A",inherit="/ss/584/2015/level/1 &amp; /ss/584/2015/level/2"]
1671
+ .Title
1672
+ ====
1673
+ inherit:[A]
1674
+ inherit:[B]
1675
+ I recommend this
1676
+ ====
1677
+
1678
+ [.requirement,subsequence="A",classification="X:Y"]
1679
+ .Title
1680
+ ====
1681
+ inherit:[A]
1682
+ I recommend this
1683
+ ====
1684
+
1685
+ [.requirement,subsequence="A"]
1686
+ .Title
1687
+ ====
1688
+ inherit:[A]
1689
+ I recommend this
1690
+ ====
1691
+
1692
+ [.requirement,subsequence="A"]
1693
+ .Title
1694
+ ====
1695
+ inherit:[A]
1696
+ ====
1697
+
1698
+
1699
+ INPUT
1700
+ #{BLANK_HDR}
1701
+ <sections>
1702
+ <clause id='_' inline-header='false' obligation='normative'>
1703
+ <title>Clause</title>
1704
+ <requirement id='_' subsequence='A'>
1705
+ <title>Title</title>
1706
+ <inherit>/ss/584/2015/level/1 &amp; /ss/584/2015/level/2</inherit>
1707
+ <inherit>A</inherit>
1708
+ <inherit>B</inherit>
1709
+ <description>
1710
+ <p id='_'> I recommend this</p>
1711
+ </description>
1712
+ </requirement>
1713
+ <requirement id='_' subsequence='A'>
1714
+ <title>Title</title>
1715
+ <inherit>A</inherit>
1716
+ <classification>
1717
+ <tag>X</tag>
1718
+ <value>Y</value>
1719
+ </classification>
1720
+ <description>
1721
+ <p id='_'> I recommend this</p>
1722
+ </description>
1723
+ </requirement>
1724
+ <requirement id='_' subsequence='A'>
1725
+ <title>Title</title>
1726
+ <inherit>A</inherit>
1727
+ <description>
1728
+ <p id='_'> I recommend this</p>
1729
+ </description>
1730
+ </requirement>
1731
+ <requirement id='_' subsequence='A'>
1732
+ <title>Title</title>
1733
+ <inherit>A</inherit>
1734
+ <description>
1735
+ <p id='_'> </p>
1736
+ </description>
1737
+ </requirement>
1738
+ </clause>
1739
+ </sections>
1740
+ </standard-document>
1741
+ OUTPUT
1742
+ end
1743
+
1582
1744
 
1583
1745
  private
1584
1746
 
@@ -8,6 +8,10 @@ RSpec.describe Asciidoctor::Standoc do
8
8
  * List 2
9
9
  * List 3
10
10
 
11
+ * [*] checked
12
+ * [x] also checked
13
+ * [ ] not checked
14
+
11
15
  . List A
12
16
  . List B
13
17
  . List C
@@ -17,42 +21,51 @@ RSpec.describe Asciidoctor::Standoc do
17
21
 
18
22
  INPUT
19
23
  expect(xmlpp(strip_guid(output))).to be_equivalent_to xmlpp(<<~"OUTPUT")
20
- #{BLANK_HDR}
21
- <sections>
22
- <ul id="_">
23
- <li>
24
- <p id="_">List 1</p>
25
- </li>
26
- <li>
27
- <p id="_">List 2</p>
28
- </li>
29
- <li>
30
- <p id="_">List 3</p>
31
- <ol id="_" type="arabic">
32
- <li>
33
- <p id="_">List A</p>
34
- </li>
35
- <li>
36
- <p id="_">List B</p>
37
- </li>
38
- <li>
39
- <p id="_">List C</p>
40
- <dl id="_">
41
- <dt>List D</dt>
42
- <dd>
43
- <p id="_">List E</p>
44
- </dd>
45
- <dt>List F</dt>
46
- <dd>
47
- <p id="_">List G</p>
48
- </dd>
49
- </dl>
50
- </li>
51
- </ol>
52
- </li>
53
- </ul>
54
- </sections>
55
- </standard-document>
24
+ #{BLANK_HDR}
25
+ <sections>
26
+ <ul id='_'>
27
+ <li>
28
+ <p id='_'>List 1</p>
29
+ </li>
30
+ <li>
31
+ <p id='_'>List 2</p>
32
+ </li>
33
+ <li>
34
+ <p id='_'>List 3</p>
35
+ </li>
36
+ <li uncheckedcheckbox='false' checkedcheckbox='true'>
37
+ <p id='_'>checked</p>
38
+ </li>
39
+ <li uncheckedcheckbox='false' checkedcheckbox='true'>
40
+ <p id='_'>also checked</p>
41
+ </li>
42
+ <li uncheckedcheckbox='true' checkedcheckbox='false'>
43
+ <p id='_'>not checked</p>
44
+ <ol id='_' type='arabic'>
45
+ <li>
46
+ <p id='_'>List A</p>
47
+ </li>
48
+ <li>
49
+ <p id='_'>List B</p>
50
+ </li>
51
+ <li>
52
+ <p id='_'>List C</p>
53
+ <dl id='_'>
54
+ <dt>List D</dt>
55
+ <dd>
56
+ <p id='_'>List E</p>
57
+ </dd>
58
+ <dt>List F</dt>
59
+ <dd>
60
+ <p id='_'>List G</p>
61
+ </dd>
62
+ </dl>
63
+ </li>
64
+ </ol>
65
+ </li>
66
+ </ul>
67
+ </sections>
68
+ </standard-document>
56
69
  OUTPUT
57
70
  end
58
71