metanorma-iso 1.5.13 → 1.5.14

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
  SHA256:
3
- metadata.gz: 48a523e339d4400dcd168324b8e2452b9fd5e4a0708daa93d45afc96aa2a9ee6
4
- data.tar.gz: 5c39c558619bf58156b604017519b074416e185dbb6554ec78b3490cca6e5db6
3
+ metadata.gz: 0e01ee8230b538949046cc2891d993eb0c6f3c3b9d3276d7e16ad05617c075eb
4
+ data.tar.gz: b1f87a4bc24143414ff469dc73541e4e581c04a803231a1ad10e60faf2a8d6aa
5
5
  SHA512:
6
- metadata.gz: fbf69dcccc16ca0188cef8d64054a577ebf80e5a058581839c9985212db4c363418a3775a0c74dfd718ea1a2c318d59ee10d9f1fe4124ebf74a2ead892deabbc
7
- data.tar.gz: adcf3750158172d4cce858a5a128990d10eee1b297ecdb0530f2ba9110694010061b0e570187f51bffdb11576768a71db7307f7cd53f331a9feb4739606f5556
6
+ metadata.gz: 7e5582b6f64fd353fdcf5dd67fe897a91fb1d500b240cc4ddf7cfceba99435eb75935d4eceb70e5b6512ba3a0a3d68c373e2ecfc2f7a4ee718524449d7891870
7
+ data.tar.gz: 386d6f98b45ff9b03dc56e06177a0fa3b7b750732093c3697c1c32935b1b6e7c931f769d6f3ce4073c562ada67e7fc24e4ae6187337182a9d3234a7d72b6c5fe
@@ -5,7 +5,6 @@ require "pathname"
5
5
  require "open-uri"
6
6
  require "isodoc"
7
7
  require "fileutils"
8
- require 'asciidoctor/iso/macros'
9
8
 
10
9
  module Asciidoctor
11
10
  module ISO
@@ -13,10 +12,6 @@ module Asciidoctor
13
12
  XML_ROOT_TAG = "iso-standard".freeze
14
13
  XML_NAMESPACE = "https://www.metanorma.org/ns/iso".freeze
15
14
 
16
- Asciidoctor::Extensions.register do
17
- inline_macro Asciidoctor::Iso::TermRefInlineMacro
18
- end
19
-
20
15
  def html_converter(node)
21
16
  IsoDoc::Iso::HtmlConvert.new(html_extract_attributes(node))
22
17
  end
@@ -596,6 +596,7 @@
596
596
  <ref name="bookmark"/>
597
597
  <ref name="image"/>
598
598
  <ref name="index"/>
599
+ <ref name="index-xref"/>
599
600
  </choice>
600
601
  </define>
601
602
  <define name="PureTextElement">
@@ -737,6 +738,37 @@
737
738
  </optional>
738
739
  </element>
739
740
  </define>
741
+ <define name="index-xref">
742
+ <element name="index-xref">
743
+ <attribute name="also">
744
+ <data type="boolean"/>
745
+ </attribute>
746
+ <element name="primary">
747
+ <oneOrMore>
748
+ <ref name="PureTextElement"/>
749
+ </oneOrMore>
750
+ </element>
751
+ <optional>
752
+ <element name="secondary">
753
+ <oneOrMore>
754
+ <ref name="PureTextElement"/>
755
+ </oneOrMore>
756
+ </element>
757
+ </optional>
758
+ <optional>
759
+ <element name="tertiary">
760
+ <oneOrMore>
761
+ <ref name="PureTextElement"/>
762
+ </oneOrMore>
763
+ </element>
764
+ </optional>
765
+ <element name="target">
766
+ <oneOrMore>
767
+ <ref name="PureTextElement"/>
768
+ </oneOrMore>
769
+ </element>
770
+ </element>
771
+ </define>
740
772
  <!-- bare ID element, used for referencing arbitrary spans of text -->
741
773
  <define name="bookmark">
742
774
  <element name="bookmark">
@@ -4,7 +4,6 @@ require "htmlentities"
4
4
  require "json"
5
5
  require "pathname"
6
6
  require "open-uri"
7
- require "asciidoctor/iso/term_lookup_cleanup"
8
7
 
9
8
  module Asciidoctor
10
9
  module ISO
@@ -89,11 +88,6 @@ module Asciidoctor
89
88
  end
90
89
  end
91
90
 
92
- def termdef_cleanup(xmldoc)
93
- Asciidoctor::ISO::TermLookupCleanup.new(xmldoc, @log).call
94
- super
95
- end
96
-
97
91
  # TODO sort by authors
98
92
  # sort by: doc class (ISO, IEC, other standard (not DOI &c), other
99
93
  # then standard class (docid class other than DOI &c)
@@ -246,6 +246,9 @@
246
246
  <data type="boolean"/>
247
247
  </attribute>
248
248
  </optional>
249
+ <optional>
250
+ <ref name="colgroup"/>
251
+ </optional>
249
252
  <optional>
250
253
  <ref name="tname"/>
251
254
  </optional>
@@ -764,6 +767,18 @@
764
767
  </define>
765
768
  </include>
766
769
  <!-- end overrides -->
770
+ <define name="colgroup">
771
+ <element name="colgroup">
772
+ <oneOrMore>
773
+ <ref name="col"/>
774
+ </oneOrMore>
775
+ </element>
776
+ </define>
777
+ <define name="col">
778
+ <element name="col">
779
+ <attribute name="width"/>
780
+ </element>
781
+ </define>
767
782
  <define name="TextElement" combine="choice">
768
783
  <ref name="concept"/>
769
784
  </define>
@@ -382,6 +382,9 @@
382
382
  <data type="anyURI"/>
383
383
  </attribute>
384
384
  </optional>
385
+ <optional>
386
+ <ref name="colgroup"/>
387
+ </optional>
385
388
  <optional>
386
389
  <ref name="tname"/>
387
390
  </optional>
@@ -1363,10 +1363,10 @@
1363
1363
  <xsl:otherwise> <!-- for ordered lists -->
1364
1364
  <xsl:choose>
1365
1365
  <xsl:when test="../@type = 'arabic'">
1366
- <xsl:number format="a)"/>
1366
+ <xsl:number format="a)" lang="en"/>
1367
1367
  </xsl:when>
1368
1368
  <xsl:when test="../@type = 'alphabet'">
1369
- <xsl:number format="a)"/>
1369
+ <xsl:number format="a)" lang="en"/>
1370
1370
  </xsl:when>
1371
1371
  <xsl:otherwise>
1372
1372
  <xsl:number format="1."/>
@@ -2702,10 +2702,12 @@
2702
2702
 
2703
2703
 
2704
2704
  <xsl:variable name="colwidths">
2705
- <xsl:call-template name="calculate-column-widths">
2706
- <xsl:with-param name="cols-count" select="$cols-count"/>
2707
- <xsl:with-param name="table" select="$simple-table"/>
2708
- </xsl:call-template>
2705
+ <xsl:if test="not(*[local-name()='colgroup']/*[local-name()='col'])">
2706
+ <xsl:call-template name="calculate-column-widths">
2707
+ <xsl:with-param name="cols-count" select="$cols-count"/>
2708
+ <xsl:with-param name="table" select="$simple-table"/>
2709
+ </xsl:call-template>
2710
+ </xsl:if>
2709
2711
  </xsl:variable>
2710
2712
  <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
2711
2713
 
@@ -2788,16 +2790,25 @@
2788
2790
  <xsl:attribute name="border-bottom">0pt solid black</xsl:attribute> <!-- set 0pt border, because there is a separete table below for footer -->
2789
2791
  </xsl:if>
2790
2792
 
2791
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
2792
- <xsl:choose>
2793
- <xsl:when test=". = 1 or . = 0">
2794
- <fo:table-column column-width="proportional-column-width(2)"/>
2795
- </xsl:when>
2796
- <xsl:otherwise>
2797
- <fo:table-column column-width="proportional-column-width({.})"/>
2798
- </xsl:otherwise>
2799
- </xsl:choose>
2800
- </xsl:for-each>
2793
+ <xsl:choose>
2794
+ <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
2795
+ <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
2796
+ <fo:table-column column-width="{@width}"/>
2797
+ </xsl:for-each>
2798
+ </xsl:when>
2799
+ <xsl:otherwise>
2800
+ <xsl:for-each select="xalan:nodeset($colwidths)//column">
2801
+ <xsl:choose>
2802
+ <xsl:when test=". = 1 or . = 0">
2803
+ <fo:table-column column-width="proportional-column-width(2)"/>
2804
+ </xsl:when>
2805
+ <xsl:otherwise>
2806
+ <fo:table-column column-width="proportional-column-width({.})"/>
2807
+ </xsl:otherwise>
2808
+ </xsl:choose>
2809
+ </xsl:for-each>
2810
+ </xsl:otherwise>
2811
+ </xsl:choose>
2801
2812
 
2802
2813
  <xsl:choose>
2803
2814
  <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
@@ -2810,10 +2821,12 @@
2810
2821
 
2811
2822
  </fo:table>
2812
2823
 
2824
+ <xsl:variable name="colgroup" select="*[local-name()='colgroup']"/>
2813
2825
  <xsl:for-each select="*[local-name()='tbody']"><!-- select context to tbody -->
2814
2826
  <xsl:call-template name="insertTableFooterInSeparateTable">
2815
2827
  <xsl:with-param name="table_attributes" select="$table_attributes"/>
2816
2828
  <xsl:with-param name="colwidths" select="$colwidths"/>
2829
+ <xsl:with-param name="colgroup" select="$colgroup"/>
2817
2830
  </xsl:call-template>
2818
2831
  </xsl:for-each>
2819
2832
 
@@ -3075,12 +3088,22 @@
3075
3088
  </xsl:template><xsl:template name="insertTableFooterInSeparateTable">
3076
3089
  <xsl:param name="table_attributes"/>
3077
3090
  <xsl:param name="colwidths"/>
3091
+ <xsl:param name="colgroup"/>
3078
3092
 
3079
3093
  <xsl:variable name="isNoteOrFnExist" select="../*[local-name()='note'] or ..//*[local-name()='fn'][local-name(..) != 'name']"/>
3080
3094
 
3081
3095
  <xsl:if test="$isNoteOrFnExist = 'true'">
3082
3096
 
3083
- <xsl:variable name="cols-count" select="count(xalan:nodeset($colwidths)//column)"/>
3097
+ <xsl:variable name="cols-count">
3098
+ <xsl:choose>
3099
+ <xsl:when test="xalan:nodeset($colgroup)//*[local-name()='col']">
3100
+ <xsl:value-of select="count(xalan:nodeset($colgroup)//*[local-name()='col'])"/>
3101
+ </xsl:when>
3102
+ <xsl:otherwise>
3103
+ <xsl:value-of select="count(xalan:nodeset($colwidths)//column)"/>
3104
+ </xsl:otherwise>
3105
+ </xsl:choose>
3106
+ </xsl:variable>
3084
3107
 
3085
3108
  <fo:table keep-with-previous="always">
3086
3109
  <xsl:for-each select="xalan:nodeset($table_attributes)/attribute">
@@ -3098,16 +3121,25 @@
3098
3121
  </xsl:choose>
3099
3122
  </xsl:for-each>
3100
3123
 
3101
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
3102
- <xsl:choose>
3103
- <xsl:when test=". = 1 or . = 0">
3104
- <fo:table-column column-width="proportional-column-width(2)"/>
3105
- </xsl:when>
3106
- <xsl:otherwise>
3107
- <fo:table-column column-width="proportional-column-width({.})"/>
3108
- </xsl:otherwise>
3109
- </xsl:choose>
3110
- </xsl:for-each>
3124
+ <xsl:choose>
3125
+ <xsl:when test="xalan:nodeset($colgroup)//*[local-name()='col']">
3126
+ <xsl:for-each select="xalan:nodeset($colgroup)//*[local-name()='col']">
3127
+ <fo:table-column column-width="{@width}"/>
3128
+ </xsl:for-each>
3129
+ </xsl:when>
3130
+ <xsl:otherwise>
3131
+ <xsl:for-each select="xalan:nodeset($colwidths)//column">
3132
+ <xsl:choose>
3133
+ <xsl:when test=". = 1 or . = 0">
3134
+ <fo:table-column column-width="proportional-column-width(2)"/>
3135
+ </xsl:when>
3136
+ <xsl:otherwise>
3137
+ <fo:table-column column-width="proportional-column-width({.})"/>
3138
+ </xsl:otherwise>
3139
+ </xsl:choose>
3140
+ </xsl:for-each>
3141
+ </xsl:otherwise>
3142
+ </xsl:choose>
3111
3143
 
3112
3144
  <fo:table-body>
3113
3145
  <fo:table-row>
@@ -5378,7 +5410,8 @@
5378
5410
  <fo:table-column column-width="107mm"/>
5379
5411
  <fo:table-column column-width="15mm"/>
5380
5412
  <fo:table-body>
5381
- <fo:table-row font-family="Arial" text-align="center" font-weight="bold" background-color="black" color="white">
5413
+ <fo:table-row text-align="center" font-weight="bold" background-color="black" color="white">
5414
+
5382
5415
  <fo:table-cell border="1pt solid black"><fo:block>Date</fo:block></fo:table-cell>
5383
5416
  <fo:table-cell border="1pt solid black"><fo:block>Type</fo:block></fo:table-cell>
5384
5417
  <fo:table-cell border="1pt solid black"><fo:block>Change</fo:block></fo:table-cell>
@@ -5396,6 +5429,10 @@
5396
5429
  <fo:block><xsl:apply-templates/></fo:block>
5397
5430
  </fo:table-cell>
5398
5431
  </xsl:template><xsl:template name="processBibitem">
5432
+
5433
+
5434
+ <!-- end BIPM bibitem processing-->
5435
+
5399
5436
 
5400
5437
 
5401
5438
 
@@ -1363,10 +1363,10 @@
1363
1363
  <xsl:otherwise> <!-- for ordered lists -->
1364
1364
  <xsl:choose>
1365
1365
  <xsl:when test="../@type = 'arabic'">
1366
- <xsl:number format="a)"/>
1366
+ <xsl:number format="a)" lang="en"/>
1367
1367
  </xsl:when>
1368
1368
  <xsl:when test="../@type = 'alphabet'">
1369
- <xsl:number format="a)"/>
1369
+ <xsl:number format="a)" lang="en"/>
1370
1370
  </xsl:when>
1371
1371
  <xsl:otherwise>
1372
1372
  <xsl:number format="1."/>
@@ -2702,10 +2702,12 @@
2702
2702
 
2703
2703
 
2704
2704
  <xsl:variable name="colwidths">
2705
- <xsl:call-template name="calculate-column-widths">
2706
- <xsl:with-param name="cols-count" select="$cols-count"/>
2707
- <xsl:with-param name="table" select="$simple-table"/>
2708
- </xsl:call-template>
2705
+ <xsl:if test="not(*[local-name()='colgroup']/*[local-name()='col'])">
2706
+ <xsl:call-template name="calculate-column-widths">
2707
+ <xsl:with-param name="cols-count" select="$cols-count"/>
2708
+ <xsl:with-param name="table" select="$simple-table"/>
2709
+ </xsl:call-template>
2710
+ </xsl:if>
2709
2711
  </xsl:variable>
2710
2712
  <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
2711
2713
 
@@ -2788,16 +2790,25 @@
2788
2790
  <xsl:attribute name="border-bottom">0pt solid black</xsl:attribute> <!-- set 0pt border, because there is a separete table below for footer -->
2789
2791
  </xsl:if>
2790
2792
 
2791
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
2792
- <xsl:choose>
2793
- <xsl:when test=". = 1 or . = 0">
2794
- <fo:table-column column-width="proportional-column-width(2)"/>
2795
- </xsl:when>
2796
- <xsl:otherwise>
2797
- <fo:table-column column-width="proportional-column-width({.})"/>
2798
- </xsl:otherwise>
2799
- </xsl:choose>
2800
- </xsl:for-each>
2793
+ <xsl:choose>
2794
+ <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
2795
+ <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
2796
+ <fo:table-column column-width="{@width}"/>
2797
+ </xsl:for-each>
2798
+ </xsl:when>
2799
+ <xsl:otherwise>
2800
+ <xsl:for-each select="xalan:nodeset($colwidths)//column">
2801
+ <xsl:choose>
2802
+ <xsl:when test=". = 1 or . = 0">
2803
+ <fo:table-column column-width="proportional-column-width(2)"/>
2804
+ </xsl:when>
2805
+ <xsl:otherwise>
2806
+ <fo:table-column column-width="proportional-column-width({.})"/>
2807
+ </xsl:otherwise>
2808
+ </xsl:choose>
2809
+ </xsl:for-each>
2810
+ </xsl:otherwise>
2811
+ </xsl:choose>
2801
2812
 
2802
2813
  <xsl:choose>
2803
2814
  <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
@@ -2810,10 +2821,12 @@
2810
2821
 
2811
2822
  </fo:table>
2812
2823
 
2824
+ <xsl:variable name="colgroup" select="*[local-name()='colgroup']"/>
2813
2825
  <xsl:for-each select="*[local-name()='tbody']"><!-- select context to tbody -->
2814
2826
  <xsl:call-template name="insertTableFooterInSeparateTable">
2815
2827
  <xsl:with-param name="table_attributes" select="$table_attributes"/>
2816
2828
  <xsl:with-param name="colwidths" select="$colwidths"/>
2829
+ <xsl:with-param name="colgroup" select="$colgroup"/>
2817
2830
  </xsl:call-template>
2818
2831
  </xsl:for-each>
2819
2832
 
@@ -3075,12 +3088,22 @@
3075
3088
  </xsl:template><xsl:template name="insertTableFooterInSeparateTable">
3076
3089
  <xsl:param name="table_attributes"/>
3077
3090
  <xsl:param name="colwidths"/>
3091
+ <xsl:param name="colgroup"/>
3078
3092
 
3079
3093
  <xsl:variable name="isNoteOrFnExist" select="../*[local-name()='note'] or ..//*[local-name()='fn'][local-name(..) != 'name']"/>
3080
3094
 
3081
3095
  <xsl:if test="$isNoteOrFnExist = 'true'">
3082
3096
 
3083
- <xsl:variable name="cols-count" select="count(xalan:nodeset($colwidths)//column)"/>
3097
+ <xsl:variable name="cols-count">
3098
+ <xsl:choose>
3099
+ <xsl:when test="xalan:nodeset($colgroup)//*[local-name()='col']">
3100
+ <xsl:value-of select="count(xalan:nodeset($colgroup)//*[local-name()='col'])"/>
3101
+ </xsl:when>
3102
+ <xsl:otherwise>
3103
+ <xsl:value-of select="count(xalan:nodeset($colwidths)//column)"/>
3104
+ </xsl:otherwise>
3105
+ </xsl:choose>
3106
+ </xsl:variable>
3084
3107
 
3085
3108
  <fo:table keep-with-previous="always">
3086
3109
  <xsl:for-each select="xalan:nodeset($table_attributes)/attribute">
@@ -3098,16 +3121,25 @@
3098
3121
  </xsl:choose>
3099
3122
  </xsl:for-each>
3100
3123
 
3101
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
3102
- <xsl:choose>
3103
- <xsl:when test=". = 1 or . = 0">
3104
- <fo:table-column column-width="proportional-column-width(2)"/>
3105
- </xsl:when>
3106
- <xsl:otherwise>
3107
- <fo:table-column column-width="proportional-column-width({.})"/>
3108
- </xsl:otherwise>
3109
- </xsl:choose>
3110
- </xsl:for-each>
3124
+ <xsl:choose>
3125
+ <xsl:when test="xalan:nodeset($colgroup)//*[local-name()='col']">
3126
+ <xsl:for-each select="xalan:nodeset($colgroup)//*[local-name()='col']">
3127
+ <fo:table-column column-width="{@width}"/>
3128
+ </xsl:for-each>
3129
+ </xsl:when>
3130
+ <xsl:otherwise>
3131
+ <xsl:for-each select="xalan:nodeset($colwidths)//column">
3132
+ <xsl:choose>
3133
+ <xsl:when test=". = 1 or . = 0">
3134
+ <fo:table-column column-width="proportional-column-width(2)"/>
3135
+ </xsl:when>
3136
+ <xsl:otherwise>
3137
+ <fo:table-column column-width="proportional-column-width({.})"/>
3138
+ </xsl:otherwise>
3139
+ </xsl:choose>
3140
+ </xsl:for-each>
3141
+ </xsl:otherwise>
3142
+ </xsl:choose>
3111
3143
 
3112
3144
  <fo:table-body>
3113
3145
  <fo:table-row>
@@ -5378,7 +5410,8 @@
5378
5410
  <fo:table-column column-width="107mm"/>
5379
5411
  <fo:table-column column-width="15mm"/>
5380
5412
  <fo:table-body>
5381
- <fo:table-row font-family="Arial" text-align="center" font-weight="bold" background-color="black" color="white">
5413
+ <fo:table-row text-align="center" font-weight="bold" background-color="black" color="white">
5414
+
5382
5415
  <fo:table-cell border="1pt solid black"><fo:block>Date</fo:block></fo:table-cell>
5383
5416
  <fo:table-cell border="1pt solid black"><fo:block>Type</fo:block></fo:table-cell>
5384
5417
  <fo:table-cell border="1pt solid black"><fo:block>Change</fo:block></fo:table-cell>
@@ -5396,6 +5429,10 @@
5396
5429
  <fo:block><xsl:apply-templates/></fo:block>
5397
5430
  </fo:table-cell>
5398
5431
  </xsl:template><xsl:template name="processBibitem">
5432
+
5433
+
5434
+ <!-- end BIPM bibitem processing-->
5435
+
5399
5436
 
5400
5437
 
5401
5438
 
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module ISO
3
- VERSION = "1.5.13".freeze
3
+ VERSION = "1.5.14".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-iso
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.13
4
+ version: 1.5.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-30 00:00:00.000000000 Z
11
+ date: 2020-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-jing
@@ -292,10 +292,8 @@ files:
292
292
  - lib/asciidoctor/iso/isostandard-amd.rng
293
293
  - lib/asciidoctor/iso/isostandard.rnc
294
294
  - lib/asciidoctor/iso/isostandard.rng
295
- - lib/asciidoctor/iso/macros.rb
296
295
  - lib/asciidoctor/iso/reqt.rng
297
296
  - lib/asciidoctor/iso/section.rb
298
- - lib/asciidoctor/iso/term_lookup_cleanup.rb
299
297
  - lib/asciidoctor/iso/validate.rb
300
298
  - lib/asciidoctor/iso/validate_requirements.rb
301
299
  - lib/asciidoctor/iso/validate_section.rb
@@ -346,7 +344,6 @@ files:
346
344
  - spec/asciidoctor-iso/cleanup_spec.rb
347
345
  - spec/asciidoctor-iso/inline_spec.rb
348
346
  - spec/asciidoctor-iso/lists_spec.rb
349
- - spec/asciidoctor-iso/macros_spec.rb
350
347
  - spec/asciidoctor-iso/refs_spec.rb
351
348
  - spec/asciidoctor-iso/section_spec.rb
352
349
  - spec/asciidoctor-iso/table_spec.rb
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'asciidoctor/extensions'
4
-
5
- module Asciidoctor
6
- module Iso
7
- # Macro to transform `term[X,Y]` into em, termxref xml
8
- class TermRefInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
9
- use_dsl
10
-
11
- named :term
12
- name_positional_attributes 'name', 'termxref'
13
- using_format :short
14
-
15
- def process(_parent, _target, attrs)
16
- termref = attrs['termxref'] || attrs['name']
17
- "<em>#{attrs['name']}</em> (<termxref>#{termref}</termxref>)"
18
- end
19
- end
20
- end
21
- end
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: true.
2
-
3
- module Asciidoctor
4
- module ISO
5
- # Intelligent term lookup xml modifier
6
- # Lookup all `term` and `calause` tags and replace `termxref` tags with
7
- # `xref`:target tag
8
- class TermLookupCleanup
9
- AUTOMATIC_GENERATED_ID_REGEXP = /\A_/
10
- EXISTING_TERM_REGEXP = /\Aterm-/
11
-
12
- attr_reader :xmldoc, :termlookup, :log
13
-
14
- def initialize(xmldoc, log)
15
- @xmldoc = xmldoc
16
- @log = log
17
- @termlookup = {}
18
- end
19
-
20
- def call
21
- @termlookup = replace_automatic_generated_ids_terms
22
- set_termxref_tags_target
23
- end
24
-
25
- private
26
-
27
- def set_termxref_tags_target
28
- xmldoc.xpath('//termxref').each do |node|
29
- target = normalize_ref_id(node.text)
30
- if termlookup[target].nil?
31
- remove_missing_ref(node, target)
32
- next
33
- end
34
- modify_ref_node(node, target)
35
- end
36
- end
37
-
38
- def remove_missing_ref(node, target)
39
- log.add('AsciiDoc Input', node,
40
- %(Error: Term reference in `term[#{target}]` missing: \
41
- "#{target}" is not defined in document))
42
- term_name_node = node.previous.previous
43
- term_name_node.remove
44
- term_name_node.name = "strong"
45
- term_name_node.children.first.content =
46
- %(term "#{term_name_node.text}" not resolved)
47
- node.add_previous_sibling(term_name_node)
48
- node.remove
49
- end
50
-
51
- def modify_ref_node(node, target)
52
- node.name = 'xref'
53
- node['target'] = termlookup[target]
54
- node.children.remove
55
- node.remove_attribute('defaultref')
56
- end
57
-
58
- def replace_automatic_generated_ids_terms
59
- xmldoc.xpath('//term').each.with_object({}) do |term_node, res|
60
- normalize_id_and_memorize(term_node, res, './preferred')
61
- end
62
- end
63
-
64
- def normalize_id_and_memorize(term_node, res_table, text_selector)
65
- term_text = normalize_ref_id(term_node.at(text_selector).text)
66
- unless AUTOMATIC_GENERATED_ID_REGEXP.match(term_node['id']).nil?
67
- term_node['id'] = unique_text_id(term_text)
68
- end
69
- res_table[term_text] = term_node['id']
70
- end
71
-
72
- def normalize_ref_id(text)
73
- text.downcase.gsub(/[[:space:]]/, '-')
74
- end
75
-
76
- def unique_text_id(text)
77
- return "term-#{text}" if xmldoc.at("//*[@id = 'term-#{text}']").nil?
78
- (1..Float::INFINITY).lazy.each do |index|
79
- if xmldoc.at("//*[@id = 'term-#{text}-#{index}']").nil?
80
- break("term-#{text}-#{index}")
81
- end
82
- end
83
- end
84
- end
85
- end
86
- end
@@ -1,310 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe Asciidoctor::ISO do
4
- it "processes the Asciidoctor::ISO inline macros" do
5
- expect(xmlpp(Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true))).to be_equivalent_to xmlpp(<<~"OUTPUT")
6
- #{ASCIIDOC_BLANK_HDR}
7
- alt:[term1]
8
- deprecated:[term1]
9
- domain:[term1]
10
- INPUT
11
- #{BLANK_HDR}
12
- <sections>
13
- <admitted>term1</admitted>
14
- <deprecates>term1</deprecates>
15
- <domain>term1</domain>
16
- </sections>
17
- </iso-standard>
18
- OUTPUT
19
- end
20
-
21
- describe 'term inline macros' do
22
- subject(:convert) do
23
- xmlpp(
24
- strip_guid(
25
- Asciidoctor.convert(
26
- input, backend: :iso, header_footer: true)))
27
- end
28
- let(:input) do
29
- <<~XML
30
- #{ASCIIDOC_BLANK_HDR}
31
- == Terms and Definitions
32
-
33
- === name2
34
-
35
- == Main
36
-
37
- term:[name,name2] is a term
38
- XML
39
- end
40
- let(:output) do
41
- <<~XML
42
- #{BLANK_HDR}
43
- <sections>
44
- <terms id='_' obligation='normative'>
45
- <title>Terms and definitions</title>
46
- <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
47
- <p id='_'>
48
- ISO and IEC maintain terminological databases for use in standardization
49
- at the following addresses:
50
- </p>
51
- <ul id='_'>
52
- <li>
53
- <p id='_'>
54
- ISO Online browsing platform: available at
55
- <link target='http://www.iso.org/obp'/>
56
- </p>
57
- </li>
58
- <li>
59
- <p id='_'>
60
- IEC Electropedia: available at
61
- <link target='http://www.electropedia.org'/>
62
- </p>
63
- </li>
64
- </ul>
65
- <term id='term-name2'>
66
- <preferred>name2</preferred>
67
- </term>
68
- </terms>
69
- <clause id='_' inline-header='false' obligation='normative'>
70
- <title>Main</title>
71
- <p id='_'>
72
- <em>name</em>
73
- (
74
- <xref target='term-name2'/>
75
- ) is a term
76
- </p>
77
- </clause>
78
- </sections>
79
- </iso-standard>
80
- XML
81
- end
82
-
83
- it 'converts macro into the correct xml' do
84
- expect(convert).to(be_equivalent_to(xmlpp(output)))
85
- end
86
-
87
- context 'default params' do
88
- let(:input) do
89
- <<~XML
90
- #{ASCIIDOC_BLANK_HDR}
91
-
92
- == Terms and Definitions
93
-
94
- === name
95
-
96
- == Main
97
-
98
- term:[name] is a term
99
- XML
100
- end
101
- let(:output) do
102
- <<~XML
103
- #{BLANK_HDR}
104
- <sections>
105
- <terms id='_' obligation='normative'>
106
- <title>Terms and definitions</title>
107
- <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
108
- <p id='_'>
109
- ISO and IEC maintain terminological databases for use in standardization
110
- at the following addresses:
111
- </p>
112
- <ul id='_'>
113
- <li>
114
- <p id='_'>
115
- ISO Online browsing platform: available at
116
- <link target='http://www.iso.org/obp' />
117
- </p>
118
- </li>
119
- <li>
120
- <p id='_'>
121
- IEC Electropedia: available at
122
- <link target='http://www.electropedia.org' />
123
- </p>
124
- </li>
125
- </ul>
126
- <term id='term-name'>
127
- <preferred>name</preferred>
128
- </term>
129
- </terms>
130
- <clause id='_' inline-header='false' obligation='normative'>
131
- <title>Main</title>
132
- <p id='_'>
133
- <em>name</em>
134
- (
135
- <xref target='term-name' />
136
- ) is a term
137
- </p>
138
- </clause>
139
- </sections>
140
- </iso-standard>
141
- XML
142
- end
143
-
144
- it 'uses `name` as termref name' do
145
- expect(convert).to(be_equivalent_to(xmlpp(output)))
146
- end
147
- end
148
-
149
- context 'multiply exising ids in document' do
150
- let(:input) do
151
- <<~XML
152
- #{ASCIIDOC_BLANK_HDR}
153
-
154
- == Terms and Definitions
155
-
156
- === name
157
- === name2
158
-
159
- [[term-name]]
160
- == Main
161
-
162
- paragraph
163
-
164
- [[term-name2]]
165
- == Second
166
-
167
- term:[name] is a term
168
- term:[name2] is a term
169
- XML
170
- end
171
- let(:output) do
172
- <<~XML
173
- #{BLANK_HDR}
174
- <sections>
175
- <terms id='_' obligation='normative'>
176
- <title>Terms and definitions</title>
177
- <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
178
- <p id='_'>
179
- ISO and IEC maintain terminological databases for use in standardization
180
- at the following addresses:
181
- </p>
182
- <ul id='_'>
183
- <li>
184
- <p id='_'>
185
- ISO Online browsing platform: available at
186
- <link target='http://www.iso.org/obp' />
187
- </p>
188
- </li>
189
- <li>
190
- <p id='_'>
191
- IEC Electropedia: available at
192
- <link target='http://www.electropedia.org' />
193
- </p>
194
- </li>
195
- </ul>
196
- <term id='term-name-1'>
197
- <preferred>name</preferred>
198
- </term>
199
- <term id='term-name2-1'>
200
- <preferred>name2</preferred>
201
- </term>
202
- </terms>
203
- <clause id='term-name' inline-header='false' obligation='normative'>
204
- <title>Main</title>
205
- <p id='_'>paragraph</p>
206
- </clause>
207
- <clause id='term-name2' inline-header='false' obligation='normative'>
208
- <title>Second</title>
209
- <p id='_'>
210
- <em>name</em>
211
- (
212
- <xref target='term-name-1' />
213
- ) is a term
214
- <em>name2</em>
215
- (
216
- <xref target='term-name2-1' />
217
- ) is a term
218
- </p>
219
- </clause>
220
- </sections>
221
- </iso-standard>
222
- XML
223
- end
224
-
225
- it 'generates unique ids which dont match existing ids' do
226
- expect(convert).to(be_equivalent_to(xmlpp(output)))
227
- end
228
- end
229
-
230
- context 'when missing actual ref' do
231
- let(:input) do
232
- <<~XML
233
- #{ASCIIDOC_BLANK_HDR}
234
-
235
- == Terms and Definitions
236
-
237
- === name identity
238
-
239
- [[name-check]]
240
- === name check
241
-
242
- paragraph
243
-
244
- term:[name check] is a term
245
-
246
- term:[name identity] is a term
247
-
248
- Moreover, term:[missing] is a term
249
- XML
250
- end
251
- let(:output) do
252
- <<~XML
253
- #{BLANK_HDR}
254
- <sections>
255
- <terms id='_' obligation='normative'>
256
- <title>Terms and definitions</title>
257
- <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
258
- <p id='_'>
259
- ISO and IEC maintain terminological databases for use in standardization
260
- at the following addresses:
261
- </p>
262
- <ul id='_'>
263
- <li>
264
- <p id='_'>
265
- ISO Online browsing platform: available at
266
- <link target='http://www.iso.org/obp'/>
267
- </p>
268
- </li>
269
- <li>
270
- <p id='_'>
271
- IEC Electropedia: available at
272
- <link target='http://www.electropedia.org'/>
273
- </p>
274
- </li>
275
- </ul>
276
- <term id='term-name-identity'>
277
- <preferred>name identity</preferred>
278
- </term>
279
- <term id='name-check'>
280
- <preferred>name check</preferred>
281
- <definition>
282
- <p id='_'>paragraph</p>
283
- <p id='_'>
284
- <em>name check</em>
285
- (
286
- <xref target='name-check'/>
287
- ) is a term
288
- </p>
289
- <p id='_'>
290
- <em>name identity</em>
291
- (
292
- <xref target='term-name-identity'/>
293
- ) is a term
294
- </p>
295
- <p id="_">Moreover, (<strong>term “missing” not resolved</strong>) is a term
296
- </p>
297
- </definition>
298
- </term>
299
- </terms>
300
- </sections>
301
- </iso-standard>
302
- XML
303
- end
304
-
305
- it 'generates unique ids which dont match existing ids' do
306
- expect(convert).to(be_equivalent_to(xmlpp(output)))
307
- end
308
- end
309
- end
310
- end