metanorma-standoc 2.1.5 → 2.2.0

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/metanorma/standoc/base.rb +1 -0
  3. data/lib/metanorma/standoc/blocks.rb +1 -2
  4. data/lib/metanorma/standoc/cleanup.rb +1 -1
  5. data/lib/metanorma/standoc/cleanup_biblio.rb +204 -0
  6. data/lib/metanorma/standoc/cleanup_block.rb +6 -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_text.rb +10 -8
  12. data/lib/metanorma/standoc/cleanup_xref.rb +1 -2
  13. data/lib/metanorma/standoc/converter.rb +2 -0
  14. data/lib/metanorma/standoc/front.rb +1 -1
  15. data/lib/metanorma/standoc/inline.rb +8 -4
  16. data/lib/metanorma/standoc/isodoc.rng +6 -1
  17. data/lib/metanorma/standoc/macros.rb +1 -180
  18. data/lib/metanorma/standoc/macros_inline.rb +194 -0
  19. data/lib/metanorma/standoc/ref_sect.rb +2 -2
  20. data/lib/metanorma/standoc/ref_utility.rb +1 -1
  21. data/lib/metanorma/standoc/reqt.rb +5 -5
  22. data/lib/metanorma/standoc/reqt.rng +1 -1
  23. data/lib/metanorma/standoc/version.rb +1 -1
  24. data/metanorma-standoc.gemspec +2 -3
  25. data/spec/metanorma/{refs_dl_spec.rb → biblio_spec.rb} +84 -1
  26. data/spec/metanorma/blocks_spec.rb +18 -8
  27. data/spec/metanorma/cleanup_blocks_spec.rb +24 -27
  28. data/spec/metanorma/inline_spec.rb +4 -0
  29. data/spec/metanorma/macros_spec.rb +2 -0
  30. data/spec/vcr_cassettes/bsi16341.yml +55 -55
  31. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +45 -45
  32. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
  33. data/spec/vcr_cassettes/hide_refs.yml +59 -59
  34. data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
  35. data/spec/vcr_cassettes/isobib_get_123_1.yml +25 -25
  36. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +32 -32
  37. data/spec/vcr_cassettes/isobib_get_123_2.yml +22 -22
  38. data/spec/vcr_cassettes/isobib_get_123_2001.yml +13 -13
  39. data/spec/vcr_cassettes/isobib_get_124.yml +12 -12
  40. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +24 -24
  41. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +45 -45
  42. data/spec/vcr_cassettes/std-link.yml +11 -11
  43. metadata +7 -6
  44. 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.5
4
+ version: 2.2.0
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-18 00:00:00.000000000 Z
11
+ date: 2022-08-08 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
@@ -607,6 +608,7 @@ files:
607
608
  - spec/fixtures/test.exp
608
609
  - spec/fixtures/test.xmi
609
610
  - spec/metanorma/base_spec.rb
611
+ - spec/metanorma/biblio_spec.rb
610
612
  - spec/metanorma/blank_spec.rb
611
613
  - spec/metanorma/blocks_spec.rb
612
614
  - spec/metanorma/cleanup_blocks_spec.rb
@@ -623,7 +625,6 @@ files:
623
625
  - spec/metanorma/macros_spec.rb
624
626
  - spec/metanorma/macros_yaml2text_spec.rb
625
627
  - spec/metanorma/processor_spec.rb
626
- - spec/metanorma/refs_dl_spec.rb
627
628
  - spec/metanorma/refs_spec.rb
628
629
  - spec/metanorma/section_spec.rb
629
630
  - spec/metanorma/table_spec.rb
@@ -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