metanorma-standoc 2.2.5 → 2.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/automerge.yml +31 -0
  3. data/lib/isodoc/html/htmlstyle.css +1 -1
  4. data/lib/metanorma/standoc/base.rb +1 -0
  5. data/lib/metanorma/standoc/basicdoc.rng +0 -27
  6. data/lib/metanorma/standoc/biblio-standoc.rng +164 -0
  7. data/lib/metanorma/standoc/biblio.rng +45 -18
  8. data/lib/metanorma/standoc/cleanup.rb +1 -0
  9. data/lib/metanorma/standoc/cleanup_asciibib.rb +110 -0
  10. data/lib/metanorma/standoc/cleanup_biblio.rb +5 -111
  11. data/lib/metanorma/standoc/cleanup_block.rb +7 -6
  12. data/lib/metanorma/standoc/cleanup_boilerplate.rb +6 -6
  13. data/lib/metanorma/standoc/cleanup_inline.rb +2 -2
  14. data/lib/metanorma/standoc/cleanup_text.rb +10 -3
  15. data/lib/metanorma/standoc/inline.rb +3 -1
  16. data/lib/metanorma/standoc/isodoc-compile.rng +7 -0
  17. data/lib/metanorma/standoc/isodoc.rng +23 -195
  18. data/lib/metanorma/standoc/validate.rb +8 -8
  19. data/lib/metanorma/standoc/version.rb +1 -1
  20. data/metanorma-standoc.gemspec +0 -1
  21. data/spec/metanorma/biblio_spec.rb +152 -144
  22. data/spec/metanorma/cleanup_sections_spec.rb +1 -2
  23. data/spec/metanorma/cleanup_spec.rb +11 -0
  24. data/spec/metanorma/inline_spec.rb +63 -2
  25. data/spec/metanorma/macros_plantuml_spec.rb +4 -4
  26. data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +3 -3
  27. data/spec/vcr_cassettes/bsi16341.yml +70 -72
  28. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +82 -82
  29. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
  30. data/spec/vcr_cassettes/hide_refs.yml +58 -58
  31. data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
  32. data/spec/vcr_cassettes/isobib_get_123_1.yml +22 -22
  33. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +33 -33
  34. data/spec/vcr_cassettes/isobib_get_123_2.yml +25 -25
  35. data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
  36. data/spec/vcr_cassettes/isobib_get_124.yml +12 -12
  37. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +37 -21
  38. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +45 -45
  39. data/spec/vcr_cassettes/std-link.yml +12 -12
  40. metadata +6 -16
@@ -53,11 +53,11 @@ module Metanorma
53
53
  end
54
54
  end
55
55
 
56
- TERM_CLAUSE = "//sections/terms | "\
56
+ TERM_CLAUSE = "//sections/terms | " \
57
57
  "//sections/clause[descendant::terms]".freeze
58
58
 
59
59
  NORM_REF =
60
- "//bibliography/references[@normative = 'true'][not(@hidden)] | "\
60
+ "//bibliography/references[@normative = 'true'][not(@hidden)] | " \
61
61
  "//bibliography/clause[.//references[@normative = 'true']]".freeze
62
62
 
63
63
  def boilerplate_isodoc(xmldoc)
@@ -79,7 +79,7 @@ module Metanorma
79
79
 
80
80
  def unwrap_boilerplate_clauses(xmldoc, xpath)
81
81
  xmldoc.xpath(xpath).each do |f|
82
- f.xpath(".//clause[@type = 'boilerplate'] | "\
82
+ f.xpath(".//clause[@type = 'boilerplate'] | " \
83
83
  ".//note[@type = 'boilerplate']").each do |c|
84
84
  c&.at("./title")&.remove
85
85
  c.replace(c.children)
@@ -175,9 +175,9 @@ module Metanorma
175
175
  end
176
176
 
177
177
  def indirect_eref_to_xref(eref, ident)
178
- loc = eref&.at("./localityStack[locality[@type = 'anchor']]")
178
+ loc = eref.at("./localityStack[locality[@type = 'anchor']]")
179
179
  &.remove&.text ||
180
- eref&.at("./locality[@type = 'anchor']")&.remove&.text || ident
180
+ eref.at("./locality[@type = 'anchor']")&.remove&.text || ident
181
181
  eref.name = "xref"
182
182
  eref.delete("bibitemid")
183
183
  eref.delete("citeas")
@@ -213,7 +213,7 @@ module Metanorma
213
213
  def bibdata_embed_hdr_cleanup(xmldoc)
214
214
  return if @embed_hdr.nil? || @embed_hdr.empty?
215
215
 
216
- xmldoc.at("//bibdata") << "<relation type='derivedFrom'>"\
216
+ xmldoc.at("//bibdata") << "<relation type='derivedFrom'>" \
217
217
  "#{hdr2bibitem(@embed_hdr.first)}</relation>"
218
218
  end
219
219
 
@@ -35,7 +35,7 @@ module Metanorma
35
35
 
36
36
  def li_bookmark_cleanup(xmldoc)
37
37
  xmldoc.xpath("//li[descendant::bookmark]").each do |x|
38
- if x.at("./*[1][local-name() = 'p']/"\
38
+ if x.at("./*[1][local-name() = 'p']/" \
39
39
  "*[1][local-name() = 'bookmark']") &&
40
40
  empty_text_before_first_element(x.elements[0])
41
41
  bookmark_to_id(x, x.elements[0].elements[0])
@@ -45,7 +45,7 @@ module Metanorma
45
45
 
46
46
  def dt_bookmark_cleanup(xmldoc)
47
47
  xmldoc.xpath("//dt[descendant::bookmark]").each do |x|
48
- if x.at("./*[1][local-name() = 'p']/"\
48
+ if x.at("./*[1][local-name() = 'p']/" \
49
49
  "*[1][local-name() = 'bookmark']") &&
50
50
  empty_text_before_first_element(x.elements[0])
51
51
  bookmark_to_id(x, x.elements[0].elements[0])
@@ -43,7 +43,7 @@ module Metanorma
43
43
  .intersection(IGNORE_QUOTES_ELEMENTS).empty? &&
44
44
  ((elem.previous.text.strip.empty? &&
45
45
  !empty_tag_with_text_content?(elem.previous)) ||
46
- elem.previous.name == "index"))
46
+ ignoretext?(elem.previous)))
47
47
  end
48
48
 
49
49
  def uninterrupt_quotes_around_xml1(elem)
@@ -56,13 +56,20 @@ module Metanorma
56
56
  prev.content = "#{prev.text}#{m[1]}"
57
57
  end
58
58
 
59
+ IGNORE_TEXT_ELEMENTS =
60
+ %w(index fn).freeze
61
+
62
+ def ignoretext?(elem)
63
+ IGNORE_TEXT_ELEMENTS.include? elem.name
64
+ end
65
+
59
66
  def block?(elem)
60
67
  %w(title name variant-title clause figure annex example introduction
61
68
  foreword acknowledgements note li th td dt dd p quote label
62
69
  abstract preferred admitted related deprecates field-of-application
63
70
  usage-info expression pronunciation grammar-value domain
64
71
  definition termnote termexample modification description
65
- newcontent floating-title).include? elem.name
72
+ newcontent floating-title tab).include? elem.name
66
73
  end
67
74
 
68
75
  def empty_tag_with_text_content?(elem)
@@ -79,7 +86,7 @@ module Metanorma
79
86
  ancestors = x.path.split(%r{/})[1..-2]
80
87
  ancestors.intersection(IGNORE_QUOTES_ELEMENTS).empty? and
81
88
  dumb2smart_quotes1(x, prev)
82
- prev = x.text unless ancestors.include?("index")
89
+ prev = x.text if ancestors.intersection(IGNORE_TEXT_ELEMENTS).empty?
83
90
  end
84
91
  end
85
92
 
@@ -45,6 +45,7 @@ module Metanorma
45
45
  m.nil? and return { target: t, type: "inline", text: node.text }
46
46
  { target: t, type: m[:fn].nil? ? "inline" : "footnote",
47
47
  case: m[:case]&.sub(/%$/, ""),
48
+ style: m[:style]&.sub(/^style=/, "")&.sub(/%$/, "") || @xrefstyle,
48
49
  droploc: m[:drop].nil? && m[:drop2].nil? ? nil : true,
49
50
  text: inline_anchor_xref_text(m, node),
50
51
  hidden: m[:hidden] }
@@ -52,12 +53,13 @@ module Metanorma
52
53
 
53
54
  def inline_anchor_xref_match(node)
54
55
  /^(?:hidden%(?<hidden>[^,]+),?)?
56
+ (?<style>style=[^%]+%)?
55
57
  (?<drop>droploc%)?(?<case>capital%|lowercase%)?(?<drop2>droploc%)?
56
58
  (?<fn>fn:?\s*)?(?<text>.*)$/x.match node.text
57
59
  end
58
60
 
59
61
  def inline_anchor_xref_text(match, node)
60
- if %i[case fn drop drop2 hidden].any? do |x|
62
+ if %i[case fn drop drop2 hidden style].any? do |x|
61
63
  !match[x].nil?
62
64
  end
63
65
  match[:text]
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <grammar ns="https://www.metanorma.org/ns/standoc" xmlns="http://relaxng.org/ns/structure/1.0">
3
+ <!-- default namespace isostandard = "https://www.metanorma.com/ns/iso" -->
4
+ <include href="biblio-standoc.rng"/>
5
+ <include href="isodoc.rng"/>
6
+ </grammar>
7
+ <!-- end overrides -->
@@ -17,21 +17,9 @@
17
17
  these elements; we just want one namespace for any child grammars
18
18
  of this.
19
19
  -->
20
- <grammar ns="https://www.metanorma.org/ns/standoc" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
20
+ <grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
21
21
  <include href="reqt.rng"/>
22
- <!-- include "biblio.rnc" { } -->
23
22
  <include href="basicdoc.rng">
24
- <start>
25
- <ref name="standard-document"/>
26
- </start>
27
- <define name="doctype">
28
- <element name="doctype">
29
- <optional>
30
- <attribute name="abbreviation"/>
31
- </optional>
32
- <ref name="DocumentType"/>
33
- </element>
34
- </define>
35
23
  <define name="admonition">
36
24
  <element name="admonition">
37
25
  <attribute name="type">
@@ -117,24 +105,6 @@
117
105
  </optional>
118
106
  </element>
119
107
  </define>
120
- <define name="bibitem">
121
- <element name="bibitem">
122
- <attribute name="id">
123
- <data type="ID"/>
124
- </attribute>
125
- <optional>
126
- <attribute name="hidden">
127
- <data type="boolean"/>
128
- </attribute>
129
- </optional>
130
- <optional>
131
- <attribute name="suppress_identifier">
132
- <data type="boolean"/>
133
- </attribute>
134
- </optional>
135
- <ref name="BibliographicItem"/>
136
- </element>
137
- </define>
138
108
  <define name="section-title">
139
109
  <element name="title">
140
110
  <zeroOrMore>
@@ -248,42 +218,6 @@
248
218
  <ref name="PureTextElement"/>
249
219
  </oneOrMore>
250
220
  </define>
251
- <define name="localityStack">
252
- <element name="localityStack">
253
- <optional>
254
- <attribute name="connective">
255
- <choice>
256
- <value>and</value>
257
- <value>or</value>
258
- <value>from</value>
259
- <value>to</value>
260
- <value/>
261
- </choice>
262
- </attribute>
263
- </optional>
264
- <zeroOrMore>
265
- <ref name="locality"/>
266
- </zeroOrMore>
267
- </element>
268
- </define>
269
- <define name="sourceLocalityStack">
270
- <element name="sourceLocalityStack">
271
- <optional>
272
- <attribute name="connective">
273
- <choice>
274
- <value>and</value>
275
- <value>or</value>
276
- <value>from</value>
277
- <value>to</value>
278
- <value/>
279
- </choice>
280
- </attribute>
281
- </optional>
282
- <zeroOrMore>
283
- <ref name="sourceLocality"/>
284
- </zeroOrMore>
285
- </element>
286
- </define>
287
221
  <define name="ul">
288
222
  <element name="ul">
289
223
  <attribute name="id">
@@ -827,21 +761,6 @@
827
761
  </zeroOrMore>
828
762
  </element>
829
763
  </define>
830
- <define name="BibDataExtensionType">
831
- <ref name="doctype"/>
832
- <optional>
833
- <ref name="docsubtype"/>
834
- </optional>
835
- <optional>
836
- <ref name="editorialgroup"/>
837
- </optional>
838
- <zeroOrMore>
839
- <ref name="ics"/>
840
- </zeroOrMore>
841
- <zeroOrMore>
842
- <ref name="structuredidentifier"/>
843
- </zeroOrMore>
844
- </define>
845
764
  <!-- TitleType = text -->
846
765
  <define name="sections">
847
766
  <element name="sections">
@@ -881,7 +800,7 @@
881
800
  <ref name="BasicBlock"/>
882
801
  </zeroOrMore>
883
802
  <zeroOrMore>
884
- <ref name="bibitem"/>
803
+ <ref name="doc_bibitem"/>
885
804
  <zeroOrMore>
886
805
  <ref name="note"/>
887
806
  </zeroOrMore>
@@ -1219,6 +1138,24 @@
1219
1138
  </define>
1220
1139
  </include>
1221
1140
  <!-- end overrides -->
1141
+ <define name="doc_bibitem">
1142
+ <element name="bibitem">
1143
+ <attribute name="id">
1144
+ <data type="ID"/>
1145
+ </attribute>
1146
+ <optional>
1147
+ <attribute name="hidden">
1148
+ <data type="boolean"/>
1149
+ </attribute>
1150
+ </optional>
1151
+ <optional>
1152
+ <attribute name="suppress_identifier">
1153
+ <data type="boolean"/>
1154
+ </attribute>
1155
+ </optional>
1156
+ <ref name="BibliographicItem"/>
1157
+ </element>
1158
+ </define>
1222
1159
  <define name="image" combine="choice">
1223
1160
  <element name="svg">
1224
1161
  <oneOrMore>
@@ -1237,14 +1174,6 @@
1237
1174
  <value>tag</value>
1238
1175
  </choice>
1239
1176
  </define>
1240
- <define name="docsubtype">
1241
- <element name="subdoctype">
1242
- <ref name="DocumentSubtype"/>
1243
- </element>
1244
- </define>
1245
- <define name="DocumentSubtype">
1246
- <text/>
1247
- </define>
1248
1177
  <define name="colgroup">
1249
1178
  <element name="colgroup">
1250
1179
  <oneOrMore>
@@ -1606,45 +1535,6 @@
1606
1535
  </choice>
1607
1536
  </element>
1608
1537
  </define>
1609
- <define name="editorialgroup">
1610
- <element name="editorialgroup">
1611
- <oneOrMore>
1612
- <ref name="technical-committee"/>
1613
- </oneOrMore>
1614
- </element>
1615
- </define>
1616
- <define name="technical-committee">
1617
- <element name="technical-committee">
1618
- <ref name="IsoWorkgroup"/>
1619
- </element>
1620
- </define>
1621
- <define name="IsoWorkgroup">
1622
- <optional>
1623
- <attribute name="number"/>
1624
- </optional>
1625
- <optional>
1626
- <attribute name="type"/>
1627
- </optional>
1628
- <optional>
1629
- <attribute name="identifier"/>
1630
- </optional>
1631
- <optional>
1632
- <attribute name="prefix"/>
1633
- </optional>
1634
- <text/>
1635
- </define>
1636
- <define name="ics">
1637
- <element name="ics">
1638
- <element name="code">
1639
- <text/>
1640
- </element>
1641
- <optional>
1642
- <element name="text">
1643
- <text/>
1644
- </element>
1645
- </optional>
1646
- </element>
1647
- </define>
1648
1538
  <define name="standard-document">
1649
1539
  <element name="standard-document">
1650
1540
  <attribute name="version"/>
@@ -2475,71 +2365,6 @@
2475
2365
  </optional>
2476
2366
  </element>
2477
2367
  </define>
2478
- <define name="structuredidentifier">
2479
- <element name="structuredidentifier">
2480
- <optional>
2481
- <attribute name="type"/>
2482
- </optional>
2483
- <oneOrMore>
2484
- <element name="agency">
2485
- <text/>
2486
- </element>
2487
- </oneOrMore>
2488
- <optional>
2489
- <element name="class">
2490
- <text/>
2491
- </element>
2492
- </optional>
2493
- <element name="docnumber">
2494
- <text/>
2495
- </element>
2496
- <optional>
2497
- <element name="partnumber">
2498
- <text/>
2499
- </element>
2500
- </optional>
2501
- <optional>
2502
- <element name="edition">
2503
- <text/>
2504
- </element>
2505
- </optional>
2506
- <optional>
2507
- <element name="version">
2508
- <text/>
2509
- </element>
2510
- </optional>
2511
- <optional>
2512
- <element name="supplementtype">
2513
- <text/>
2514
- </element>
2515
- </optional>
2516
- <optional>
2517
- <element name="supplementnumber">
2518
- <text/>
2519
- </element>
2520
- </optional>
2521
- <optional>
2522
- <element name="amendment">
2523
- <text/>
2524
- </element>
2525
- </optional>
2526
- <optional>
2527
- <element name="corrigendum">
2528
- <text/>
2529
- </element>
2530
- </optional>
2531
- <optional>
2532
- <element name="language">
2533
- <text/>
2534
- </element>
2535
- </optional>
2536
- <optional>
2537
- <element name="year">
2538
- <text/>
2539
- </element>
2540
- </optional>
2541
- </element>
2542
- </define>
2543
2368
  <define name="term-clause">
2544
2369
  <element name="clause">
2545
2370
  <optional>
@@ -2813,4 +2638,7 @@
2813
2638
  </attribute>
2814
2639
  </element>
2815
2640
  </define>
2641
+ <start>
2642
+ <ref name="standard-document"/>
2643
+ </start>
2816
2644
  </grammar>
@@ -9,7 +9,7 @@ require "pngcheck"
9
9
  module Metanorma
10
10
  module Standoc
11
11
  module Validate
12
- SOURCELOCALITY = "./origin//locality[@type = 'clause']/"\
12
+ SOURCELOCALITY = "./origin//locality[@type = 'clause']/" \
13
13
  "referenceFrom".freeze
14
14
 
15
15
  def init_iev
@@ -24,7 +24,7 @@ module Metanorma
24
24
  @iev = init_iev or return
25
25
  xmldoc.xpath("//term").each do |t|
26
26
  t.xpath(".//termsource").each do |src|
27
- (/^IEC 60050-/.match(src&.at("./origin/@citeas")&.text) &&
27
+ (/^IEC 60050-/.match(src.at("./origin/@citeas")&.text) &&
28
28
  loc = src.xpath(SOURCELOCALITY)&.text) or next
29
29
  iev_validate1(t, loc, xmldoc)
30
30
  end
@@ -33,9 +33,9 @@ module Metanorma
33
33
 
34
34
  def iev_validate1(term, loc, xmldoc)
35
35
  iev = @iev.fetch(loc,
36
- xmldoc&.at("//language")&.text || "en") or return
36
+ xmldoc.at("//language")&.text || "en") or return
37
37
  pref = term.xpath("./preferred//name").inject([]) do |m, x|
38
- m << x&.text&.downcase
38
+ m << x.text&.downcase
39
39
  end
40
40
  pref.include?(iev.downcase) or
41
41
  @log.add("Bibliography", term, %(Term "#{pref[0]}" does not match ) +
@@ -97,7 +97,7 @@ module Metanorma
97
97
 
98
98
  def repeat_id_validate1(ids, elem)
99
99
  if ids[elem["id"]]
100
- @log.add("Anchors", elem, "Anchor #{elem['id']} has already been "\
100
+ @log.add("Anchors", elem, "Anchor #{elem['id']} has already been " \
101
101
  "used at line #{ids[elem['id']]}")
102
102
  @fatalerror << "Multiple instances of same ID: #{elem['id']}"
103
103
  else
@@ -137,8 +137,8 @@ module Metanorma
137
137
  SVG_NS = "http://www.w3.org/2000/svg".freeze
138
138
 
139
139
  WILDCARD_ATTRS =
140
- "//*[@format] | //stem | //bibdata//description | "\
141
- "//formattedref | //bibdata//note | //bibdata/abstract | "\
140
+ "//*[@format] | //stem | //bibdata//description | " \
141
+ "//formattedref | //bibdata//note | //bibdata/abstract | " \
142
142
  "//bibitem/abstract | //bibitem/note | //misc-container".freeze
143
143
 
144
144
  # RelaxNG cannot cope well with wildcard attributes. So we strip
@@ -213,7 +213,7 @@ module Metanorma
213
213
  def validate(doc)
214
214
  content_validate(doc)
215
215
  schema_validate(formattedstr_strip(doc.dup),
216
- File.join(File.dirname(__FILE__), "isodoc.rng"))
216
+ File.join(File.dirname(__FILE__), "isodoc-compile.rng"))
217
217
  end
218
218
  end
219
219
  end
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "2.2.5".freeze
22
+ VERSION = "2.2.6".freeze
23
23
  end
24
24
  end
@@ -37,7 +37,6 @@ Gem::Specification.new do |spec|
37
37
  spec.add_dependency "concurrent-ruby"
38
38
  spec.add_dependency "latexmath"
39
39
  spec.add_dependency "mathml2asciimath"
40
- spec.add_dependency "mn-requirements", "~> 0.1.4"
41
40
  spec.add_dependency "pngcheck"
42
41
  spec.add_dependency "relaton-cli", "~> 1.13.0"
43
42
  spec.add_dependency "relaton-iev", "~> 1.1.0"