metanorma-standoc 2.1.4 → 2.2.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/lib/metanorma/standoc/base.rb +1 -0
  3. data/lib/metanorma/standoc/blocks.rb +3 -7
  4. data/lib/metanorma/standoc/cleanup.rb +4 -2
  5. data/lib/metanorma/standoc/cleanup_biblio.rb +204 -0
  6. data/lib/metanorma/standoc/cleanup_block.rb +46 -4
  7. data/lib/metanorma/standoc/cleanup_maths.rb +2 -15
  8. data/lib/metanorma/standoc/cleanup_ref.rb +22 -13
  9. data/lib/metanorma/standoc/cleanup_reqt.rb +37 -4
  10. data/lib/metanorma/standoc/cleanup_symbols.rb +1 -1
  11. data/lib/metanorma/standoc/cleanup_terms.rb +6 -2
  12. data/lib/metanorma/standoc/cleanup_text.rb +10 -8
  13. data/lib/metanorma/standoc/cleanup_xref.rb +1 -2
  14. data/lib/metanorma/standoc/converter.rb +2 -0
  15. data/lib/metanorma/standoc/front.rb +1 -1
  16. data/lib/metanorma/standoc/inline.rb +8 -4
  17. data/lib/metanorma/standoc/isodoc.rng +16 -1
  18. data/lib/metanorma/standoc/macros.rb +1 -180
  19. data/lib/metanorma/standoc/macros_inline.rb +194 -0
  20. data/lib/metanorma/standoc/ref_sect.rb +2 -2
  21. data/lib/metanorma/standoc/ref_utility.rb +5 -6
  22. data/lib/metanorma/standoc/reqt.rb +5 -5
  23. data/lib/metanorma/standoc/reqt.rng +1 -1
  24. data/lib/metanorma/standoc/section.rb +2 -0
  25. data/lib/metanorma/standoc/term_lookup_cleanup.rb +1 -1
  26. data/lib/metanorma/standoc/utils.rb +1 -1
  27. data/lib/metanorma/standoc/validate.rb +1 -69
  28. data/lib/metanorma/standoc/validate_table.rb +91 -0
  29. data/lib/metanorma/standoc/version.rb +1 -1
  30. data/metanorma-standoc.gemspec +2 -3
  31. data/spec/metanorma/{refs_dl_spec.rb → biblio_spec.rb} +84 -1
  32. data/spec/metanorma/blocks_spec.rb +68 -8
  33. data/spec/metanorma/cleanup_blocks_spec.rb +107 -27
  34. data/spec/metanorma/inline_spec.rb +4 -0
  35. data/spec/metanorma/isobib_cache_spec.rb +6 -4
  36. data/spec/metanorma/macros_spec.rb +6 -2
  37. data/spec/metanorma/refs_spec.rb +261 -232
  38. data/spec/metanorma/validate_spec.rb +106 -7
  39. data/spec/vcr_cassettes/bsi16341.yml +63 -51
  40. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +62 -62
  41. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
  42. data/spec/vcr_cassettes/hide_refs.yml +58 -58
  43. data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
  44. data/spec/vcr_cassettes/isobib_get_123_1.yml +22 -22
  45. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +33 -33
  46. data/spec/vcr_cassettes/isobib_get_123_2.yml +295 -0
  47. data/spec/vcr_cassettes/isobib_get_123_2001.yml +11 -11
  48. data/spec/vcr_cassettes/isobib_get_124.yml +12 -12
  49. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +24 -30
  50. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
  51. data/spec/vcr_cassettes/std-link.yml +14 -72
  52. metadata +9 -6
  53. data/lib/metanorma/standoc/cleanup_ref_dl.rb +0 -113
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: 2.1.4
4
+ version: 2.2.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: 2022-07-04 00:00:00.000000000 Z
11
+ date: 2022-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.1.0
47
+ version: 2.2.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.1.0
54
+ version: 2.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: metanorma-plugin-datastruct
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -477,6 +477,7 @@ files:
477
477
  - lib/metanorma/standoc/blocks_notes.rb
478
478
  - lib/metanorma/standoc/cleanup.rb
479
479
  - lib/metanorma/standoc/cleanup_amend.rb
480
+ - lib/metanorma/standoc/cleanup_biblio.rb
480
481
  - lib/metanorma/standoc/cleanup_block.rb
481
482
  - lib/metanorma/standoc/cleanup_boilerplate.rb
482
483
  - lib/metanorma/standoc/cleanup_footnotes.rb
@@ -484,7 +485,6 @@ files:
484
485
  - lib/metanorma/standoc/cleanup_inline.rb
485
486
  - lib/metanorma/standoc/cleanup_maths.rb
486
487
  - lib/metanorma/standoc/cleanup_ref.rb
487
- - lib/metanorma/standoc/cleanup_ref_dl.rb
488
488
  - lib/metanorma/standoc/cleanup_reqt.rb
489
489
  - lib/metanorma/standoc/cleanup_section.rb
490
490
  - lib/metanorma/standoc/cleanup_section_names.rb
@@ -507,6 +507,7 @@ files:
507
507
  - lib/metanorma/standoc/macros.rb
508
508
  - lib/metanorma/standoc/macros_embed.rb
509
509
  - lib/metanorma/standoc/macros_form.rb
510
+ - lib/metanorma/standoc/macros_inline.rb
510
511
  - lib/metanorma/standoc/macros_note.rb
511
512
  - lib/metanorma/standoc/macros_plantuml.rb
512
513
  - lib/metanorma/standoc/macros_terms.rb
@@ -524,6 +525,7 @@ files:
524
525
  - lib/metanorma/standoc/utils.rb
525
526
  - lib/metanorma/standoc/validate.rb
526
527
  - lib/metanorma/standoc/validate_section.rb
528
+ - lib/metanorma/standoc/validate_table.rb
527
529
  - lib/metanorma/standoc/version.rb
528
530
  - lib/metanorma/standoc/views/datamodel/model_representation.adoc.erb
529
531
  - lib/metanorma/standoc/views/datamodel/plantuml_representation.adoc.erb
@@ -607,6 +609,7 @@ files:
607
609
  - spec/fixtures/test.exp
608
610
  - spec/fixtures/test.xmi
609
611
  - spec/metanorma/base_spec.rb
612
+ - spec/metanorma/biblio_spec.rb
610
613
  - spec/metanorma/blank_spec.rb
611
614
  - spec/metanorma/blocks_spec.rb
612
615
  - spec/metanorma/cleanup_blocks_spec.rb
@@ -623,7 +626,6 @@ files:
623
626
  - spec/metanorma/macros_spec.rb
624
627
  - spec/metanorma/macros_yaml2text_spec.rb
625
628
  - spec/metanorma/processor_spec.rb
626
- - spec/metanorma/refs_dl_spec.rb
627
629
  - spec/metanorma/refs_spec.rb
628
630
  - spec/metanorma/section_spec.rb
629
631
  - spec/metanorma/table_spec.rb
@@ -637,6 +639,7 @@ files:
637
639
  - spec/vcr_cassettes/isobib_get_123.yml
638
640
  - spec/vcr_cassettes/isobib_get_123_1.yml
639
641
  - spec/vcr_cassettes/isobib_get_123_1_fr.yml
642
+ - spec/vcr_cassettes/isobib_get_123_2.yml
640
643
  - spec/vcr_cassettes/isobib_get_123_2001.yml
641
644
  - spec/vcr_cassettes/isobib_get_124.yml
642
645
  - spec/vcr_cassettes/rfcbib_get_rfc8341.yml
@@ -1,113 +0,0 @@
1
- require "set"
2
- require "relaton_bib"
3
-
4
- module Metanorma
5
- module Standoc
6
- module Cleanup
7
- def ref_dl_cleanup(xmldoc)
8
- xmldoc.xpath("//clause[@bibitem = 'true']").each do |c|
9
- bib = dl_bib_extract(c) or next
10
- validate_ref_dl(bib, c)
11
- bibitemxml = RelatonBib::BibliographicItem.from_hash(bib).to_xml or next
12
- bibitem = Nokogiri::XML(bibitemxml)
13
- bibitem.root["id"] = c["id"] if c["id"] && !/^_/.match(c["id"])
14
- c.replace(bibitem.root)
15
- end
16
- end
17
-
18
- # do not accept implicit id
19
- def validate_ref_dl(bib, clause)
20
- id = bib["id"]
21
- id ||= clause["id"] unless /^_/.match?(clause["id"])
22
- unless id
23
- @log.add("Anchors", clause,
24
- "The following reference is missing an anchor:\n"\
25
- "#{clause.to_xml}")
26
- return
27
- end
28
- @refids << id
29
- validate_ref_dl1(bib, id, clause)
30
- end
31
-
32
- def validate_ref_dl1(bib, id, clause)
33
- bib["title"] or
34
- @log.add("Bibliography", clause, "Reference #{id} is missing a title")
35
- bib["docid"] or
36
- @log.add("Bibliography", clause,
37
- "Reference #{id} is missing a document identifier (docid)")
38
- end
39
-
40
- def extract_from_p(tag, bib, key)
41
- return unless bib[tag]
42
-
43
- "<#{key}>#{bib[tag].at('p').children}</#{key}>"
44
- end
45
-
46
- # if the content is a single paragraph, replace it with its children
47
- # single links replaced with uri
48
- def p_unwrap(para)
49
- elems = para.elements
50
- if elems.size == 1 && elems[0].name == "p"
51
- link_unwrap(elems[0]).children.to_xml.strip
52
- else
53
- para.to_xml.strip
54
- end
55
- end
56
-
57
- def link_unwrap(para)
58
- elems = para.elements
59
- if elems.size == 1 && elems[0].name == "link"
60
- para.at("./link").replace(elems[0]["target"].strip)
61
- end
62
- para
63
- end
64
-
65
- def dd_bib_extract(dtd)
66
- return nil if dtd.children.empty?
67
-
68
- dtd.at("./dl") and return dl_bib_extract(dtd)
69
- elems = dtd.remove.elements
70
- return p_unwrap(dtd) unless elems.size == 1 &&
71
- %w(ol ul).include?(elems[0].name)
72
-
73
- ret = []
74
- elems[0].xpath("./li").each do |li|
75
- ret << p_unwrap(li)
76
- end
77
- ret
78
- end
79
-
80
- def add_to_hash(bib, key, val)
81
- Metanorma::Utils::set_nested_value(bib, key.split("."), val)
82
- end
83
-
84
- # definition list, with at most one level of unordered lists
85
- def dl_bib_extract(clause, nested = false)
86
- dl = clause.at("./dl") or return
87
- bib = {}
88
- key = ""
89
- dl.xpath("./dt | ./dd").each do |dtd|
90
- (dtd.name == "dt" and key = dtd.text.sub(/:+$/, "")) or
91
- add_to_hash(bib, key, dd_bib_extract(dtd))
92
- end
93
- clause.xpath("./clause").each do |c1|
94
- key = c1&.at("./title")&.text&.downcase&.strip
95
- next unless %w(contributor relation series).include? key
96
-
97
- add_to_hash(bib, key, dl_bib_extract(c1, true))
98
- end
99
- dl_bib_extract_title(bib, clause, nested)
100
- end
101
-
102
- def dl_bib_extract_title(bib, clause, nested)
103
- (!nested && clause.at("./title")) or return bib
104
- title = clause.at("./title").remove.children.to_xml
105
- bib["title"] = [bib["title"]] if bib["title"].is_a?(Hash) ||
106
- bib["title"].is_a?(String)
107
- bib["title"] = [] unless bib["title"]
108
- bib["title"] << title if !title.empty?
109
- bib
110
- end
111
- end
112
- end
113
- end