metanorma-standoc 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62c4c0677dbb6e87bca34d3c5d7526ceb5cf92d22e49d85f1f86a8ca183878d6
4
- data.tar.gz: 62f43be22140fc902bb9a032fea49a100b8cbae54e3cf7143ffdba29b4f41fb5
3
+ metadata.gz: 3e25ec1e8d5bc7bd069b096125a76184bd1349bc64bc79a4e5c51f2441d3fb89
4
+ data.tar.gz: 888e53e4d5a11a260d74a520715c9343cf6d5889430e8491c91a1abf2476e057
5
5
  SHA512:
6
- metadata.gz: b572b2f23a0db15863b7d2876d28c8fadfe16ea843043e4e9b9bd802f5f210c4a01f7df4b9ead558a023d6cf56602cb0b42f81f182b642efe44fe54af495132d
7
- data.tar.gz: c6f7b9327802626322175c729b386cf8396d79fe32e1dd8b2b22c95f5a9a7cc5f7f53978ac1797de43f9902ebce0e1cf55e30551cf653e973a173034f72a649a
6
+ metadata.gz: d0b4f072611604bd9d6859676f98baaa6f09c95d886dbac7e5e21172fa34ccaec156c7560eccbb69a1e9bca784aae39325dce0e82bbbdf64dd0f27d05835b3b2
7
+ data.tar.gz: 405c4e68f48462b48249cc5d76de89b80b412f546a47992b37bd36ff68cce0a52f0cb82467439e7fe666b3b03fbf102831e17f3fb8b47757b56093627914581d
@@ -85,6 +85,7 @@ module Asciidoctor
85
85
  @no_isobib_cache = node.attr("no-isobib-cache")
86
86
  @no_isobib = node.attr("no-isobib")
87
87
  @bibdb = nil
88
+ @seen_headers = []
88
89
  init_bib_caches(node)
89
90
  init_iev_caches(node)
90
91
  end
@@ -102,8 +102,7 @@ module Asciidoctor
102
102
  return term_example(node) if in_terms?
103
103
  noko do |xml|
104
104
  xml.example **id_attr(node) do |ex|
105
- content = node.content
106
- ex << content
105
+ wrap_in_para(node, ex)
107
106
  end
108
107
  end.join("\n")
109
108
  end
@@ -27,11 +27,12 @@ module Asciidoctor
27
27
  biblio_cleanup(xmldoc)
28
28
  reference_names(xmldoc)
29
29
  xref_cleanup(xmldoc)
30
+ origin_cleanup(xmldoc)
31
+ iev_cleanup(xmldoc)
30
32
  bpart_cleanup(xmldoc)
31
33
  quotesource_cleanup(xmldoc)
32
34
  para_cleanup(xmldoc)
33
35
  callout_cleanup(xmldoc)
34
- origin_cleanup(xmldoc)
35
36
  element_name_cleanup(xmldoc)
36
37
  footnote_renumber(xmldoc)
37
38
  empty_element_cleanup(xmldoc)
@@ -1,3 +1,5 @@
1
+ require "set"
2
+
1
3
  module Asciidoctor
2
4
  module Standoc
3
5
  module Cleanup
@@ -120,6 +122,40 @@ module Asciidoctor
120
122
  @anchors[ref["id"]] = { xref: reference }
121
123
  end
122
124
  end
125
+
126
+ # converts generic IEV citation to citation of IEC 60050-n
127
+ # assumes IEV citations are of form
128
+ # <eref type="inline" bibitemid="a" citeas="IEC 60050">
129
+ # <locality type="clause"><referenceFrom>101-01-01</referenceFrom></locality></eref>
130
+ def linksIev2iec60050part(xmldoc)
131
+ parts = Set.new()
132
+ xmldoc.xpath("//eref[@citeas = 'IEC 60050'] | //origin[@citeas = 'IEC 60050']").each do |x|
133
+ cl = x&.at("./locality[@type = 'clause']/referenceFrom")&.text || next
134
+ m = /^(\d+)/.match cl || next
135
+ parts << m[0]
136
+ x["citeas"] += "-#{m[0]}"
137
+ end
138
+ parts
139
+ end
140
+
141
+ # replace generic IEV reference with references to all extracted
142
+ # IEV parts
143
+ def refsIev2iec60050part(parts, iev)
144
+ new_iev = ""
145
+ parts.sort.each do |p|
146
+ hit = @bibdb&.fetch("IEC 60050-#{p}", nil, keep_year: true)
147
+ next if hit.nil?
148
+ new_iev += hit.to_xml
149
+ end
150
+ iev.replace(new_iev)
151
+ end
152
+
153
+ # call after xref_cleanup and origin_cleanup
154
+ def iev_cleanup(xmldoc)
155
+ iev = xmldoc.at("//bibitem[docidentifier = 'IEC 60050']") || return
156
+ parts = linksIev2iec60050part(xmldoc)
157
+ refsIev2iec60050part(parts, iev)
158
+ end
123
159
  end
124
160
  end
125
161
  end
@@ -956,6 +956,11 @@
956
956
  </define>
957
957
  <define name="li">
958
958
  <element name="li">
959
+ <optional>
960
+ <attribute name="id">
961
+ <data type="ID"/>
962
+ </attribute>
963
+ </optional>
959
964
  <oneOrMore>
960
965
  <ref name="paragraph-with-footnote"/>
961
966
  </oneOrMore>
@@ -999,7 +1004,9 @@
999
1004
  </define>
1000
1005
  <define name="dt">
1001
1006
  <element name="dt">
1002
- <ref name="TextElement"/>
1007
+ <zeroOrMore>
1008
+ <ref name="TextElement"/>
1009
+ </zeroOrMore>
1003
1010
  </element>
1004
1011
  </define>
1005
1012
  <define name="dd">
@@ -80,6 +80,7 @@ module Asciidoctor
80
80
  end
81
81
 
82
82
  def fetch_ref(xml, code, year, **opts)
83
+ #require "byebug"; byebug
83
84
  hit = @bibdb&.fetch(code, year, opts)
84
85
  return nil if hit.nil?
85
86
  xml.parent.add_child(hit.to_xml)
@@ -21,18 +21,19 @@ module Asciidoctor
21
21
  end
22
22
 
23
23
  def sectiontype(node)
24
- node&.attr("heading")&.downcase || node.title.downcase
24
+ ret = node&.attr("heading")&.downcase || node.title.downcase
25
+ return ret if ret == "symbols and abbreviated terms"
26
+ return nil unless node.level == 1
27
+ return nil if @seen_headers.include? ret
28
+ @seen_headers << ret
29
+ ret
25
30
  end
26
31
 
27
32
  def section(node)
28
33
  a = { id: Utils::anchor_or_uuid(node) }
29
34
  noko do |xml|
30
35
  case sectiontype(node)
31
- when "introduction" then
32
- if node.level == 1 then introduction_parse(a, xml, node)
33
- else
34
- clause_parse(a, xml, node)
35
- end
36
+ when "introduction" then introduction_parse(a, xml, node)
36
37
  when "normative references" then norm_ref_parse(a, xml, node)
37
38
  when "terms and definitions",
38
39
  "terms, definitions, symbols and abbreviated terms",
@@ -13,7 +13,7 @@ module Asciidoctor
13
13
 
14
14
  def iev_validate(xmldoc)
15
15
  xmldoc.xpath("//term").each do |t|
16
- /^IEV($|\s|:)/.match(t&.at(".//origin/@citeas")&.text) or next
16
+ /^IEC 60050-/.match(t&.at(".//origin/@citeas")&.text) or next
17
17
  pref = t.xpath("./preferred").inject([]) { |m, x| m << x&.text&.downcase }
18
18
  locality = t.xpath(SOURCELOCALITY)&.text or next
19
19
  iev = @iev.fetch(locality, xmldoc&.at("//language")&.text || "en") or next
@@ -29,7 +29,7 @@ module Asciidoctor
29
29
  root.xpath("//figure[image][not(title)]").each do |node|
30
30
  style_warning(node, "Figure should have title", nil)
31
31
  end
32
- root.xpath("//table[not(title)]").each do |node|
32
+ root.xpath("//table[not(name)]").each do |node|
33
33
  style_warning(node, "Table should have title", nil)
34
34
  end
35
35
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Standoc
3
- VERSION = "1.0.0".freeze
3
+ VERSION = "1.0.1".freeze
4
4
  end
5
5
  end
@@ -757,4 +757,113 @@ r = 1 %</stem>
757
757
  </standard-document>
758
758
  OUTPUT
759
759
  end
760
+
761
+ it "separates IEV citations by top-level clause" do
762
+ system "mv ~/.iev.pstore ~/.iev.pstore1"
763
+ system "rm test.iev.pstore"
764
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
765
+ #{CACHED_ISOBIB_BLANK_HDR}
766
+
767
+ [bibliography]
768
+ == Normative References
769
+ * [[[iev,IEV]]], _iev_
770
+
771
+ == Terms and definitions
772
+ === Automation1
773
+
774
+ [.source]
775
+ <<iev,clause="103-01-02">>
776
+
777
+ === Automation2
778
+
779
+ [.source]
780
+ <<iev,clause="102-01-02">>
781
+
782
+ === Automation3
783
+
784
+ [.source]
785
+ <<iev,clause="103-01-02">>
786
+ INPUT
787
+ #{BLANK_HDR}
788
+
789
+ <sections>
790
+ <terms id="_" obligation="normative"><title>Terms and definitions</title><term id="_">
791
+ <preferred>Automation1</preferred>
792
+ <termsource status="identical">
793
+ <origin bibitemid="iev" type="inline" citeas="IEC 60050-103"><locality type="clause"><referenceFrom>103-01-02</referenceFrom></locality></origin>
794
+ </termsource>
795
+ </term>
796
+ <term id="_">
797
+ <preferred>Automation2</preferred>
798
+ <termsource status="identical">
799
+ <origin bibitemid="iev" type="inline" citeas="IEC 60050-102"><locality type="clause"><referenceFrom>102-01-02</referenceFrom></locality></origin>
800
+ </termsource>
801
+ </term>
802
+ <term id="_">
803
+ <preferred>Automation3</preferred>
804
+ <termsource status="identical">
805
+ <origin bibitemid="iev" type="inline" citeas="IEC 60050-103"><locality type="clause"><referenceFrom>103-01-02</referenceFrom></locality></origin>
806
+ </termsource>
807
+ </term></terms></sections><bibliography><references id="_" obligation="informative">
808
+ <title>Normative References</title>
809
+ <bibitem type="international-standard" id="IEC60050-102">
810
+ <title format="text/plain" language="en" script="Latn">International Electrotechnical Vocabulary</title>
811
+ <docidentifier>IEC 60050-102</docidentifier>
812
+ <contributor>
813
+ <role type="publisher"/>
814
+ <organization>
815
+ <name>International Electrotechnical Commission</name>
816
+ <abbreviation>IEC</abbreviation>
817
+ <uri>www.iec.ch</uri>
818
+ </organization>
819
+ </contributor>
820
+ <language>en</language>
821
+ <language>fr</language>
822
+ <script>Latn</script>
823
+ <status>
824
+ <stage>60</stage>
825
+ </status>
826
+ <copyright>
827
+ <from>2018</from>
828
+ <owner>
829
+ <organization>
830
+ <name>International Electrotechnical Commission</name>
831
+ <abbreviation>IEC</abbreviation>
832
+ <uri>www.iec.ch</uri>
833
+ </organization>
834
+ </owner>
835
+ </copyright>
836
+ </bibitem><bibitem type="international-standard" id="IEC60050-103">
837
+ <title format="text/plain" language="en" script="Latn">International Electrotechnical Vocabulary</title>
838
+ <docidentifier>IEC 60050-103</docidentifier>
839
+ <contributor>
840
+ <role type="publisher"/>
841
+ <organization>
842
+ <name>International Electrotechnical Commission</name>
843
+ <abbreviation>IEC</abbreviation>
844
+ <uri>www.iec.ch</uri>
845
+ </organization>
846
+ </contributor>
847
+ <language>en</language>
848
+ <language>fr</language>
849
+ <script>Latn</script>
850
+ <status>
851
+ <stage>60</stage>
852
+ </status>
853
+ <copyright>
854
+ <from>2018</from>
855
+ <owner>
856
+ <organization>
857
+ <name>International Electrotechnical Commission</name>
858
+ <abbreviation>IEC</abbreviation>
859
+ <uri>www.iec.ch</uri>
860
+ </organization>
861
+ </owner>
862
+ </copyright>
863
+ </bibitem>
864
+ </references></bibliography>
865
+ </standard-document>
866
+ OUTPUT
867
+ system "mv ~/.iev.pstore1 ~/.iev.pstore"
868
+ end
760
869
  end
@@ -38,6 +38,8 @@ RSpec.describe Asciidoctor::Standoc do
38
38
 
39
39
  === Clause 4.2
40
40
 
41
+ == Terms and Definitions
42
+
41
43
  [appendix]
42
44
  == Annex
43
45
 
@@ -80,6 +82,10 @@ RSpec.describe Asciidoctor::Standoc do
80
82
  <clause id="_" inline-header="false" obligation="normative">
81
83
  <title>Clause 4.2</title>
82
84
  </clause></clause>
85
+ <clause id="_" inline-header="false" obligation="normative">
86
+ <title>Terms and Definitions</title>
87
+ </clause>
88
+
83
89
 
84
90
  </sections><annex id="_" inline-header="false" obligation="normative">
85
91
  <title>Annex</title>
@@ -1,4 +1,4 @@
1
1
  asciidoctor rice.adoc
2
2
  mv rice.html rice.preview.html
3
- asciidoctor --trace -b iso -r 'asciidoctor-iso' rice.adoc
3
+ asciidoctor --trace -b standoc -r 'metanorma-standoc' rice.adoc
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-standoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-14 00:00:00.000000000 Z
11
+ date: 2018-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor