metanorma-standoc 1.11.4 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +3 -31
  3. data/.gitignore +23 -0
  4. data/Gemfile +0 -1
  5. data/lib/asciidoctor/standoc/base.rb +2 -145
  6. data/lib/asciidoctor/standoc/blocks.rb +2 -238
  7. data/lib/asciidoctor/standoc/blocks_notes.rb +2 -100
  8. data/lib/asciidoctor/standoc/cleanup.rb +2 -208
  9. data/lib/asciidoctor/standoc/cleanup_amend.rb +2 -53
  10. data/lib/asciidoctor/standoc/cleanup_block.rb +2 -172
  11. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +2 -212
  12. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +2 -108
  13. data/lib/asciidoctor/standoc/cleanup_image.rb +2 -69
  14. data/lib/asciidoctor/standoc/cleanup_inline.rb +2 -189
  15. data/lib/asciidoctor/standoc/cleanup_maths.rb +2 -221
  16. data/lib/asciidoctor/standoc/cleanup_ref.rb +2 -169
  17. data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +2 -103
  18. data/lib/asciidoctor/standoc/cleanup_reqt.rb +2 -110
  19. data/lib/asciidoctor/standoc/cleanup_section.rb +2 -184
  20. data/lib/asciidoctor/standoc/cleanup_section_names.rb +2 -91
  21. data/lib/asciidoctor/standoc/cleanup_symbols.rb +2 -47
  22. data/lib/asciidoctor/standoc/cleanup_table.rb +2 -67
  23. data/lib/asciidoctor/standoc/cleanup_terms.rb +2 -139
  24. data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +2 -198
  25. data/lib/asciidoctor/standoc/cleanup_text.rb +2 -95
  26. data/lib/asciidoctor/standoc/cleanup_toc.rb +3 -0
  27. data/lib/asciidoctor/standoc/cleanup_xref.rb +2 -106
  28. data/lib/asciidoctor/standoc/converter.rb +2 -123
  29. data/lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb +2 -56
  30. data/lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb +2 -102
  31. data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +3 -404
  32. data/lib/asciidoctor/standoc/deprecated.rb +5 -0
  33. data/lib/asciidoctor/standoc/front.rb +2 -223
  34. data/lib/asciidoctor/standoc/front_contributor.rb +2 -191
  35. data/lib/asciidoctor/standoc/inline.rb +2 -231
  36. data/lib/asciidoctor/standoc/lists.rb +2 -119
  37. data/lib/asciidoctor/standoc/macros.rb +2 -203
  38. data/lib/asciidoctor/standoc/macros_form.rb +2 -62
  39. data/lib/asciidoctor/standoc/macros_note.rb +2 -44
  40. data/lib/asciidoctor/standoc/macros_plantuml.rb +2 -112
  41. data/lib/asciidoctor/standoc/macros_terms.rb +2 -180
  42. data/lib/asciidoctor/standoc/ref.rb +2 -251
  43. data/lib/asciidoctor/standoc/ref_sect.rb +2 -153
  44. data/lib/asciidoctor/standoc/ref_utility.rb +2 -0
  45. data/lib/asciidoctor/standoc/render.rb +2 -114
  46. data/lib/asciidoctor/standoc/reqt.rb +2 -89
  47. data/lib/asciidoctor/standoc/section.rb +2 -207
  48. data/lib/asciidoctor/standoc/table.rb +2 -84
  49. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +2 -178
  50. data/lib/asciidoctor/standoc/terms.rb +2 -159
  51. data/lib/asciidoctor/standoc/utils.rb +2 -100
  52. data/lib/asciidoctor/standoc/validate.rb +2 -157
  53. data/lib/asciidoctor/standoc/validate_section.rb +2 -54
  54. data/lib/isodoc/html/htmlstyle.css +25 -19
  55. data/lib/isodoc/html/htmlstyle.scss +7 -2
  56. data/lib/metanorma/standoc/base.rb +163 -0
  57. data/lib/{asciidoctor → metanorma}/standoc/basicdoc.rng +5 -3
  58. data/lib/{asciidoctor → metanorma}/standoc/biblio.rng +7 -5
  59. data/lib/metanorma/standoc/blocks.rb +239 -0
  60. data/lib/metanorma/standoc/blocks_notes.rb +101 -0
  61. data/lib/metanorma/standoc/cleanup.rb +157 -0
  62. data/lib/metanorma/standoc/cleanup_amend.rb +54 -0
  63. data/lib/metanorma/standoc/cleanup_block.rb +173 -0
  64. data/lib/metanorma/standoc/cleanup_boilerplate.rb +213 -0
  65. data/lib/metanorma/standoc/cleanup_footnotes.rb +109 -0
  66. data/lib/metanorma/standoc/cleanup_image.rb +184 -0
  67. data/lib/metanorma/standoc/cleanup_inline.rb +190 -0
  68. data/lib/metanorma/standoc/cleanup_maths.rb +222 -0
  69. data/lib/metanorma/standoc/cleanup_ref.rb +170 -0
  70. data/lib/metanorma/standoc/cleanup_ref_dl.rb +104 -0
  71. data/lib/metanorma/standoc/cleanup_reqt.rb +111 -0
  72. data/lib/metanorma/standoc/cleanup_section.rb +212 -0
  73. data/lib/metanorma/standoc/cleanup_section_names.rb +92 -0
  74. data/lib/metanorma/standoc/cleanup_symbols.rb +48 -0
  75. data/lib/metanorma/standoc/cleanup_table.rb +68 -0
  76. data/lib/metanorma/standoc/cleanup_terms.rb +140 -0
  77. data/lib/metanorma/standoc/cleanup_terms_designations.rb +199 -0
  78. data/lib/metanorma/standoc/cleanup_text.rb +74 -0
  79. data/lib/metanorma/standoc/cleanup_toc.rb +98 -0
  80. data/lib/metanorma/standoc/cleanup_xref.rb +114 -0
  81. data/lib/metanorma/standoc/converter.rb +126 -0
  82. data/lib/metanorma/standoc/datamodel/attributes_table_preprocessor.rb +57 -0
  83. data/lib/metanorma/standoc/datamodel/diagram_preprocessor.rb +103 -0
  84. data/lib/metanorma/standoc/datamodel/plantuml_renderer.rb +409 -0
  85. data/lib/metanorma/standoc/front.rb +224 -0
  86. data/lib/metanorma/standoc/front_contributor.rb +192 -0
  87. data/lib/metanorma/standoc/inline.rb +232 -0
  88. data/lib/{asciidoctor → metanorma}/standoc/isodoc.rng +108 -1
  89. data/lib/metanorma/standoc/lists.rb +120 -0
  90. data/lib/metanorma/standoc/macros.rb +205 -0
  91. data/lib/metanorma/standoc/macros_embed.rb +72 -0
  92. data/lib/metanorma/standoc/macros_form.rb +63 -0
  93. data/lib/metanorma/standoc/macros_note.rb +45 -0
  94. data/lib/metanorma/standoc/macros_plantuml.rb +113 -0
  95. data/lib/metanorma/standoc/macros_terms.rb +194 -0
  96. data/lib/metanorma/standoc/ref.rb +248 -0
  97. data/lib/metanorma/standoc/ref_sect.rb +153 -0
  98. data/lib/{asciidoctor/standoc/ref_date_id.rb → metanorma/standoc/ref_utility.rb} +45 -6
  99. data/lib/metanorma/standoc/render.rb +115 -0
  100. data/lib/metanorma/standoc/reqt.rb +90 -0
  101. data/lib/{asciidoctor → metanorma}/standoc/reqt.rng +0 -0
  102. data/lib/metanorma/standoc/section.rb +209 -0
  103. data/lib/metanorma/standoc/table.rb +85 -0
  104. data/lib/metanorma/standoc/term_lookup_cleanup.rb +181 -0
  105. data/lib/metanorma/standoc/terms.rb +163 -0
  106. data/lib/metanorma/standoc/utils.rb +101 -0
  107. data/lib/metanorma/standoc/validate.rb +163 -0
  108. data/lib/metanorma/standoc/validate_section.rb +55 -0
  109. data/lib/metanorma/standoc/version.rb +1 -1
  110. data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/model_representation.adoc.erb +0 -0
  111. data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/plantuml_representation.adoc.erb +0 -0
  112. data/lib/metanorma-standoc.rb +1 -1
  113. data/metanorma-standoc.gemspec +1 -1
  114. data/spec/assets/a1.adoc +8 -0
  115. data/spec/assets/a2.adoc +8 -0
  116. data/spec/assets/a3.adoc +9 -0
  117. data/spec/assets/a4.adoc +4 -0
  118. data/spec/{asciidoctor → metanorma}/base_spec.rb +453 -409
  119. data/spec/{asciidoctor → metanorma}/blank_spec.rb +1 -1
  120. data/spec/{asciidoctor → metanorma}/blocks_spec.rb +1 -1
  121. data/spec/{asciidoctor → metanorma}/cleanup_blocks_spec.rb +137 -1
  122. data/spec/{asciidoctor → metanorma}/cleanup_sections_spec.rb +1 -1
  123. data/spec/{asciidoctor → metanorma}/cleanup_spec.rb +8 -8
  124. data/spec/{asciidoctor → metanorma}/cleanup_terms_spec.rb +204 -204
  125. data/spec/{asciidoctor → metanorma}/datamodel/attributes_table_preprocessor_spec.rb +1 -1
  126. data/spec/{asciidoctor → metanorma}/datamodel/diagram_preprocessor_spec.rb +1 -1
  127. data/spec/{asciidoctor → metanorma}/inline_spec.rb +1 -1
  128. data/spec/{asciidoctor → metanorma}/isobib_cache_spec.rb +3 -3
  129. data/spec/{asciidoctor → metanorma}/lists_spec.rb +1 -1
  130. data/spec/{asciidoctor → metanorma}/macros_json2text_spec.rb +0 -0
  131. data/spec/{asciidoctor → metanorma}/macros_plantuml_spec.rb +3 -3
  132. data/spec/{asciidoctor → metanorma}/macros_spec.rb +158 -6
  133. data/spec/{asciidoctor → metanorma}/macros_yaml2text_spec.rb +0 -0
  134. data/spec/metanorma/refs_dl_spec.rb +863 -0
  135. data/spec/{asciidoctor → metanorma}/refs_spec.rb +580 -66
  136. data/spec/{asciidoctor → metanorma}/section_spec.rb +42 -17
  137. data/spec/{asciidoctor → metanorma}/table_spec.rb +1 -1
  138. data/spec/{asciidoctor → metanorma}/validate_spec.rb +2 -2
  139. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +46 -46
  140. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +10 -10
  141. data/spec/vcr_cassettes/hide_refs.yml +599 -0
  142. data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
  143. data/spec/vcr_cassettes/isobib_get_123_1.yml +23 -23
  144. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +85 -85
  145. data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
  146. data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
  147. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
  148. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +60 -50
  149. metadata +88 -32
  150. data/spec/asciidoctor/refs_dl_spec.rb +0 -864
@@ -0,0 +1,248 @@
1
+ require_relative "ref_utility"
2
+
3
+ module Metanorma
4
+ module Standoc
5
+ module Refs
6
+ def iso_publisher(bib, code)
7
+ code.sub(/ .*$/, "").split("/").each do |abbrev|
8
+ bib.contributor do |c|
9
+ c.role **{ type: "publisher" }
10
+ c.organization do |org|
11
+ organization(org, abbrev, true)
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ def isorefrender1(bib, match, year, allp = "")
18
+ bib.title(**plaintxt) { |i| i << ref_normalise(match[:text]) }
19
+ docid(bib, match[:usrlbl]) if match[:usrlbl]
20
+ docid(bib, id_and_year(match[:code], year) + allp)
21
+ docnumber(bib, match[:code])
22
+ end
23
+
24
+ def isorefmatchescode(match)
25
+ yr = norm_year(match[:year])
26
+ { code: match[:code], year: yr, match: match,
27
+ title: match[:text], usrlbl: match[:usrlbl],
28
+ lang: (@lang || :all) }
29
+ end
30
+
31
+ def isorefmatchesout(item, xml)
32
+ if item[:doc] then use_retrieved_relaton(item, xml)
33
+ else
34
+ xml.bibitem **attr_code(ref_attributes(item[:ref][:match])) do |t|
35
+ isorefrender1(t, item[:ref][:match], item[:ref][:year])
36
+ item[:ref][:year] and t.date **{ type: "published" } do |d|
37
+ set_date_range(d, item[:ref][:year])
38
+ end
39
+ iso_publisher(t, item[:ref][:match][:code])
40
+ end
41
+ end
42
+ end
43
+
44
+ def isorefmatches2code(match)
45
+ { code: match[:code], no_year: true,
46
+ note: match[:fn], year: nil, match: match,
47
+ title: match[:text], usrlbl: match[:usrlbl],
48
+ lang: (@lang || :all) }
49
+ end
50
+
51
+ def isorefmatches2out(item, xml)
52
+ if item[:doc] then use_retrieved_relaton(item, xml)
53
+ else isorefmatches2_1(xml, item[:ref][:match])
54
+ end
55
+ end
56
+
57
+ def isorefmatches2_1(xml, match)
58
+ xml.bibitem **attr_code(ref_attributes(match)) do |t|
59
+ isorefrender1(t, match, "--")
60
+ t.date **{ type: "published" } do |d|
61
+ d.on "--"
62
+ end
63
+ iso_publisher(t, match[:code])
64
+ unless match[:fn].nil?
65
+ t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
66
+ p << (match[:fn]).to_s
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ def isorefmatches3code(match)
73
+ yr = norm_year(match[:year])
74
+ hasyr = !yr.nil? && yr != "--"
75
+ { code: match[:code], match: match, yr: yr, hasyr: hasyr,
76
+ year: hasyr ? yr : nil,
77
+ all_parts: true, no_year: yr == "--",
78
+ text: match[:text], usrlbl: match[:usrlbl],
79
+ lang: (@lang || :all) }
80
+ end
81
+
82
+ def isorefmatches3out(item, xml)
83
+ if item[:doc] then use_retrieved_relaton(item, xml)
84
+ else
85
+ isorefmatches3_1(xml, item[:ref][:match], item[:ref][:yr],
86
+ item[:ref][:hasyr], item[:doc])
87
+ end
88
+ end
89
+
90
+ def isorefmatches3_1(xml, match, yr, _hasyr, _ref)
91
+ xml.bibitem(**attr_code(ref_attributes(match))) do |t|
92
+ isorefrender1(t, match, yr, " (all parts)")
93
+ conditional_date(t, match, yr == "--")
94
+ iso_publisher(t, match[:code])
95
+ if match.names.include?("fn") && match[:fn]
96
+ t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
97
+ p << (match[:fn]).to_s
98
+ end
99
+ end
100
+ t.extent **{ type: "part" } do |e|
101
+ e.referenceFrom "all"
102
+ end
103
+ end
104
+ end
105
+
106
+ def refitem_render1(match, code, bib)
107
+ if code[:type] == "path"
108
+ bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "URI" }
109
+ bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "citation" }
110
+ end
111
+ code[:id].sub!(/[:-](19|20)[0-9][0-9]$/, "")
112
+ docid(bib, match[:usrlbl]) if match[:usrlbl]
113
+ docid(bib, /^\d+$/.match?(code[:id]) ? "[#{code[:id]}]" : code[:id])
114
+ code[:type] == "repo" and
115
+ bib.docidentifier code[:key], **{ type: "repository" }
116
+ end
117
+
118
+ def refitem_render(xml, match, code)
119
+ xml.bibitem **attr_code(id: match[:anchor],
120
+ hidden: code[:hidden]) do |t|
121
+ t.formattedref **{ format: "application/x-isodoc+xml" } do |i|
122
+ i << ref_normalise_no_format(match[:text])
123
+ end
124
+ yr_match = /[:-](?<year>(19|20)[0-9][0-9])\b/.match(code[:id])
125
+ refitem_render1(match, code, t)
126
+ docnumber(t, code[:id]) unless /^\d+$|^\(.+\)$/.match?(code[:id])
127
+ conditional_date(t, yr_match || match, false)
128
+ end
129
+ end
130
+
131
+ # TODO: alternative where only title is available
132
+ def refitemcode(item, node)
133
+ m = NON_ISO_REF.match(item) and return refitem1code(item, m).compact
134
+ m = NON_ISO_REF1.match(item) and return refitem1code(item, m).compact
135
+ @log.add("AsciiDoc Input", node, "#{MALFORMED_REF}: #{item}")
136
+ {}
137
+ end
138
+
139
+ def refitem1code(_item, match)
140
+ code = analyse_ref_code(match[:code])
141
+ ((code[:id] && code[:numeric]) || code[:nofetch]) and
142
+ return { code: nil, match: match, analyse_code: code,
143
+ hidden: code[:hidden] }
144
+ year = refitem1yr(code[:id])
145
+ { code: code[:id], analyse_code: code,
146
+ year: year,
147
+ title: match[:text], match: match, hidden: code[:hidden],
148
+ usrlbl: match[:usrlbl], lang: (@lang || :all) }
149
+ end
150
+
151
+ def refitem1yr(code)
152
+ yr_match = /[:-](?<year>(19|20)[0-9][0-9])\b/.match(code)
153
+ yr_match ? yr_match[:year] : nil
154
+ end
155
+
156
+ def refitemout(item, xml)
157
+ return nil if item[:ref][:match].nil?
158
+
159
+ item[:doc] or return refitem_render(xml, item[:ref][:match],
160
+ item[:ref][:analyse_code])
161
+ use_retrieved_relaton(item, xml)
162
+ end
163
+
164
+ ISO_REF =
165
+ %r{^<ref\sid="(?<anchor>[^"]+)">
166
+ \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
167
+ (:(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm.freeze
168
+
169
+ ISO_REF_NO_YEAR =
170
+ %r{^<ref\sid="(?<anchor>[^"]+)">
171
+ \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):
172
+ (--|&\#821[12];)\]</ref>,?\s*
173
+ (<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
174
+ .freeze
175
+
176
+ ISO_REF_ALL_PARTS =
177
+ %r{^<ref\sid="(?<anchor>[^"]+)">
178
+ \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)
179
+ (:(?<year>--|&\#821[12];|[0-9][0-9-]+))?\s
180
+ \(all\sparts\)\]</ref>,?\s*
181
+ (<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm.freeze
182
+
183
+ NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
184
+ \[(?<usrlbl>\([^)]+\))?(?<code>.+?)\]</ref>,?\s*(?<text>.*)$}xm
185
+ .freeze
186
+
187
+ NON_ISO_REF1 = %r{^<ref\sid="(?<anchor>[^"]+)">
188
+ (?<usrlbl>\([^)]+\))?(?<code>.+?)</ref>,?\s*(?<text>.*)$}xm
189
+ .freeze
190
+
191
+ def reference1_matches(item)
192
+ matched = ISO_REF.match item
193
+ matched2 = ISO_REF_NO_YEAR.match item
194
+ matched3 = ISO_REF_ALL_PARTS.match item
195
+ [matched, matched2, matched3]
196
+ end
197
+
198
+ def reference1code(item, node)
199
+ matched, matched2, matched3 = reference1_matches(item)
200
+ if matched3.nil? && matched2.nil? && matched.nil?
201
+ refitemcode(item, node).merge(process: 0)
202
+ elsif !matched.nil? then isorefmatchescode(matched).merge(process: 1)
203
+ elsif !matched2.nil? then isorefmatches2code(matched2).merge(process: 2)
204
+ elsif !matched3.nil? then isorefmatches3code(matched3).merge(process: 3)
205
+ end
206
+ end
207
+
208
+ def reference1out(item, xml)
209
+ case item[:ref][:process]
210
+ when 0 then refitemout(item, xml)
211
+ when 1 then isorefmatchesout(item, xml)
212
+ when 2 then isorefmatches2out(item, xml)
213
+ when 3 then isorefmatches3out(item, xml)
214
+ end
215
+ end
216
+
217
+ def reference_preproc(node)
218
+ refs = node.items.each_with_object([]) do |b, m|
219
+ m << reference1code(b.text, node)
220
+ end
221
+ results = refs.each_with_index.with_object(Queue.new) do |(ref, i), res|
222
+ fetch_ref_async(ref.merge(ord: i), i, res)
223
+ end
224
+ [refs, results]
225
+ end
226
+
227
+ def reference(node)
228
+ refs, results = reference_preproc(node)
229
+ ret = reference_queue(refs, results)
230
+ noko do |xml|
231
+ ret.each { |b| reference1out(b, xml) }
232
+ end.join
233
+ end
234
+
235
+ def reference_queue(refs, results)
236
+ refs.each.with_object([]) do |_, m|
237
+ ref, i, doc = results.pop
238
+ m[i.to_i] = { ref: ref }
239
+ if doc.is_a?(RelatonBib::RequestError)
240
+ @log.add("Bibliography", nil, "Could not retrieve #{ref[:code]}: "\
241
+ "no access to online site")
242
+ else m[i.to_i][:doc] = doc
243
+ end
244
+ end
245
+ end
246
+ end
247
+ end
248
+ end
@@ -0,0 +1,153 @@
1
+ module Metanorma
2
+ module Standoc
3
+ module Section
4
+ def in_biblio?
5
+ @biblio
6
+ end
7
+
8
+ def in_norm_ref?
9
+ @norm_ref
10
+ end
11
+
12
+ def bibliography_parse(attrs, xml, node)
13
+ x = biblio_prep(attrs, xml, node) and return x
14
+ @biblio = true
15
+ attrs = attrs.merge(normative: node.attr("normative") || false)
16
+ xml.references **attr_code(attrs) do |xml_section|
17
+ xml_section.title { |t| t << node.title }
18
+ xml_section << node.content
19
+ end
20
+ @biblio = false
21
+ end
22
+
23
+ def bibitem_parse(attrs, xml, node)
24
+ norm_ref = @norm_ref
25
+ biblio = @biblio
26
+ @biblio = false
27
+ @norm_ref = false
28
+ ret = clause_parse(attrs, xml, node)
29
+ @biblio = biblio
30
+ @norm_ref = norm_ref
31
+ ret
32
+ end
33
+
34
+ def norm_ref_parse(attrs, xml, node)
35
+ x = biblio_prep(attrs, xml, node) and return x
36
+ @norm_ref = true
37
+ attrs = attrs.merge(normative: node.attr("normative") || true)
38
+ xml.references **attr_code(attrs) do |xml_section|
39
+ xml_section.title { |t| t << node.title }
40
+ xml_section << node.content
41
+ end
42
+ @norm_ref = false
43
+ end
44
+
45
+ def biblio_prep(attrs, xml, node)
46
+ if node.option? "bibitem"
47
+ bibitem_parse(attrs, xml, node)
48
+ else
49
+ node.attr("style") == "bibliography" or
50
+ @log.add("AsciiDoc Input", node,
51
+ "Section not marked up as [bibliography]!")
52
+ nil
53
+ end
54
+ end
55
+
56
+ def global_ievcache_name
57
+ "#{Dir.home}/.iev/cache"
58
+ end
59
+
60
+ def local_ievcache_name(cachename)
61
+ return nil if cachename.nil?
62
+
63
+ cachename += "_iev" unless cachename.empty?
64
+ cachename = "iev" if cachename.empty?
65
+ "#{cachename}/cache"
66
+ end
67
+
68
+ def fetch_ref(xml, code, year, **opts)
69
+ return nil if opts[:no_year]
70
+
71
+ code = code.sub(/^\([^)]+\)/, "")
72
+ hit = @bibdb&.fetch(code, year, opts)
73
+ return nil if hit.nil?
74
+
75
+ xml.parent.add_child(smart_render_xml(hit, code, opts))
76
+ xml
77
+ rescue RelatonBib::RequestError
78
+ @log.add("Bibliography", nil, "Could not retrieve #{code}: "\
79
+ "no access to online site")
80
+ nil
81
+ end
82
+
83
+ def fetch_ref_async(ref, idx, res)
84
+ if ref[:code].nil? || ref[:no_year] || @bibdb.nil?
85
+ res << [ref, idx, nil]
86
+ else
87
+ @bibdb.fetch_async(ref[:code], ref[:year], ref) do |doc|
88
+ res << [ref, idx, doc]
89
+ end
90
+ end
91
+ end
92
+
93
+ def emend_biblio(xml, code, title, usrlbl)
94
+ unless xml.at("/bibitem/docidentifier[not(@type = 'DOI')][text()]")
95
+ @log.add("Bibliography", nil,
96
+ "ERROR: No document identifier retrieved for #{code}")
97
+ xml.root << "<docidentifier>#{code}</docidentifier>"
98
+ end
99
+ unless xml.at("/bibitem/title[text()]")
100
+ @log.add("Bibliography", nil,
101
+ "ERROR: No title retrieved for #{code}")
102
+ xml.root << "<title>#{title || '(MISSING TITLE)'}</title>"
103
+ end
104
+ usrlbl and xml.at("/bibitem/docidentifier").next =
105
+ "<docidentifier type='metanorma'>#{mn_code(usrlbl)}</docidentifier>"
106
+ end
107
+
108
+ def smart_render_xml(xml, code, opts)
109
+ xml.respond_to? :to_xml or return nil
110
+ xml = Nokogiri::XML(xml.to_xml(lang: opts[:lang]))
111
+ emend_biblio(xml, code, opts[:title], opts[:usrlbl])
112
+ xml.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
113
+ xml.traverse do |n|
114
+ n.text? and n.replace(Metanorma::Utils::smartformat(n.text))
115
+ end
116
+ xml.to_xml.sub(/<\?[^>]+>/, "")
117
+ end
118
+
119
+ def use_retrieved_relaton(item, xml)
120
+ xml.parent.add_child(smart_render_xml(item[:doc], item[:ref][:code],
121
+ item[:ref]))
122
+ use_my_anchor(xml, item[:ref][:match][:anchor], item.dig(:ref, :analyse_code, :hidden))
123
+ end
124
+
125
+ def init_bib_caches(node)
126
+ return if @no_isobib
127
+
128
+ global = !@no_isobib_cache && !node.attr("local-cache-only")
129
+ local = node.attr("local-cache") || node.attr("local-cache-only")
130
+ local = nil if @no_isobib_cache
131
+ @bibdb = Relaton::DbCache.init_bib_caches(
132
+ local_cache: local,
133
+ flush_caches: node.attr("flush-caches"),
134
+ global_cache: global,
135
+ )
136
+ end
137
+
138
+ def init_iev_caches(node)
139
+ unless @no_isobib_cache || @no_isobib
140
+ node.attr("local-cache-only") or
141
+ @iev_globalname = global_ievcache_name
142
+ @iev_localname = local_ievcache_name(node.attr("local-cache") ||
143
+ node.attr("local-cache-only"))
144
+ if node.attr("flush-caches")
145
+ FileUtils.rm_f @iev_globalname unless @iev_globalname.nil?
146
+ FileUtils.rm_f @iev_localname unless @iev_localname.nil?
147
+ end
148
+ end
149
+ # @iev = Iev::Db.new(globalname, localname) unless @no_isobib
150
+ end
151
+ end
152
+ end
153
+ end
@@ -1,4 +1,4 @@
1
- module Asciidoctor
1
+ module Metanorma
2
2
  module Standoc
3
3
  module Refs
4
4
  def set_date_range(date, text)
@@ -31,8 +31,9 @@ module Asciidoctor
31
31
  end
32
32
  end
33
33
 
34
- def use_my_anchor(ref, id)
34
+ def use_my_anchor(ref, id, hidden)
35
35
  ref.parent.elements.last["id"] = id
36
+ hidden and ref.parent.elements.last["hidden"] = hidden
36
37
  ref
37
38
  end
38
39
 
@@ -55,7 +56,9 @@ module Asciidoctor
55
56
  end
56
57
 
57
58
  def mn_code(code)
58
- code.sub(/^\(/, "[").sub(/\).*$/, "]").sub(/^nofetch\((.+)\)$/, "\\1")
59
+ code.sub(/^\(/, "[").sub(/\).*$/, "]")
60
+ .sub(/^hidden\((.+)\)$/, "\\1")
61
+ .sub(/^nofetch\((.+)\)$/, "\\1")
59
62
  end
60
63
 
61
64
  def analyse_ref_nofetch(ret)
@@ -64,9 +67,16 @@ module Asciidoctor
64
67
  ret.merge(id: m[:id], nofetch: true)
65
68
  end
66
69
 
70
+ def analyse_ref_hidden(ret)
71
+ return ret unless m = /^hidden\((?<id>.+)\)$/.match(ret[:id])
72
+
73
+ ret.merge(id: m[:id], hidden: true)
74
+ end
75
+
67
76
  def analyse_ref_repo_path(ret)
68
77
  return ret unless m =
69
- /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
78
+ /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/
79
+ .match(ret[:id])
70
80
 
71
81
  id = m[:id].empty? ? m[:key].sub(%r{^[^/]+/}, "") : m[:id]
72
82
  ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true)
@@ -79,12 +89,41 @@ module Asciidoctor
79
89
  end
80
90
 
81
91
  # ref id = (usrlbl)code[:-]year
82
- # code = nofetch(code) | (repo|path):(key,code) | \[? number \]? | ident
92
+ # code = nofetch(code) | hidden(code) | (repo|path):(key,code) |
93
+ # \[? number \]? | ident
83
94
  def analyse_ref_code(code)
84
95
  ret = { id: code }
85
96
  return ret if code.blank?
86
97
 
87
- analyse_ref_nofetch(analyse_ref_repo_path(analyse_ref_numeric(ret)))
98
+ analyse_ref_nofetch(
99
+ analyse_ref_hidden(analyse_ref_repo_path(analyse_ref_numeric(ret))),
100
+ )
101
+ end
102
+
103
+ # if no year is supplied, interpret as no_year reference
104
+ def no_year_generic_ref(code)
105
+ /^(BSI|BS)\b/.match?(code)
106
+ end
107
+
108
+ def plaintxt
109
+ { format: "text/plain" }
110
+ end
111
+
112
+ def ref_attributes(match)
113
+ { id: match[:anchor], type: "standard" }
114
+ end
115
+
116
+ MALFORMED_REF =
117
+ "no anchor on reference, markup may be malformed: see "\
118
+ "https://www.metanorma.com/author/topics/document-format/bibliography/ , "\
119
+ "https://www.metanorma.com/author/iso/topics/markup/#bibliographies".freeze
120
+
121
+ def ref_normalise(ref)
122
+ ref.gsub(/&amp;amp;/, "&amp;").gsub(%r{^<em>(.*)</em>}, "\\1")
123
+ end
124
+
125
+ def ref_normalise_no_format(ref)
126
+ ref.gsub(/&amp;amp;/, "&amp;")
88
127
  end
89
128
  end
90
129
  end
@@ -0,0 +1,115 @@
1
+ module Metanorma
2
+ module Standoc
3
+ module Base
4
+ def html_extract_attributes(node)
5
+ {
6
+ script: node.attr("script"),
7
+ bodyfont: node.attr("body-font"),
8
+ headerfont: node.attr("header-font"),
9
+ monospacefont: node.attr("monospace-font"),
10
+ i18nyaml: node.attr("i18nyaml"),
11
+ scope: node.attr("scope"),
12
+ htmlstylesheet: node.attr("htmlstylesheet"),
13
+ htmlstylesheet_override: node.attr("htmlstylesheet-override"),
14
+ htmlcoverpage: node.attr("htmlcoverpage"),
15
+ htmlintropage: node.attr("htmlintropage"),
16
+ scripts: node.attr("scripts"),
17
+ scripts_override: node.attr("scripts-override"),
18
+ scripts_pdf: node.attr("scripts-pdf"),
19
+ datauriimage: node.attr("data-uri-image") != "false",
20
+ htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
21
+ doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
22
+ break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
23
+ suppressasciimathdup: node.attr("suppress-asciimath-dup"),
24
+ bare: node.attr("bare"),
25
+ sectionsplit: node.attr("sectionsplit"),
26
+ baseassetpath: node.attr("base-asset-path"),
27
+ aligncrosselements: node.attr("align-cross-elements"),
28
+ }
29
+ end
30
+
31
+ def html_converter(node)
32
+ IsoDoc::HtmlConvert.new(html_extract_attributes(node))
33
+ end
34
+
35
+ def pdf_converter(node)
36
+ return nil if node.attr("no-pdf")
37
+
38
+ IsoDoc::Standoc::PdfConvert.new(pdf_extract_attributes(node))
39
+ end
40
+
41
+ def doc_extract_attributes(node)
42
+ attrs = {
43
+ script: node.attr("script"),
44
+ bodyfont: node.attr("body-font"),
45
+ headerfont: node.attr("header-font"),
46
+ monospacefont: node.attr("monospace-font"),
47
+ i18nyaml: node.attr("i18nyaml"),
48
+ scope: node.attr("scope"),
49
+ wordstylesheet: node.attr("wordstylesheet"),
50
+ wordstylesheet_override: node.attr("wordstylesheet-override"),
51
+ standardstylesheet: node.attr("standardstylesheet"),
52
+ header: node.attr("header"),
53
+ wordcoverpage: node.attr("wordcoverpage"),
54
+ wordintropage: node.attr("wordintropage"),
55
+ ulstyle: node.attr("ulstyle"),
56
+ olstyle: node.attr("olstyle"),
57
+ htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
58
+ doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
59
+ break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
60
+ suppressasciimathdup: node.attr("suppress-asciimath-dup"),
61
+ bare: node.attr("bare"),
62
+ baseassetpath: node.attr("base-asset-path"),
63
+ aligncrosselements: node.attr("align-cross-elements"),
64
+ }
65
+
66
+ if fonts_manifest = node.attr(FONTS_MANIFEST)
67
+ attrs[IsoDoc::XslfoPdfConvert::MN2PDF_OPTIONS] = {
68
+ IsoDoc::XslfoPdfConvert::MN2PDF_FONT_MANIFEST => fonts_manifest,
69
+ }
70
+ end
71
+
72
+ attrs
73
+ end
74
+
75
+ def pdf_extract_attributes(node)
76
+ %w(pdf-encrypt pdf-encryption-length pdf-user-password
77
+ pdf-owner-password pdf-allow-copy-content pdf-allow-edit-content
78
+ pdf-allow-assemble-document pdf-allow-edit-annotations
79
+ pdf-allow-print pdf-allow-print-hq pdf-allow-fill-in-forms
80
+ pdf-allow-access-content pdf-encrypt-metadata)
81
+ .each_with_object({}) do |x, m|
82
+ m[x.gsub(/-/, "").to_i] = node.attr(x)
83
+ end
84
+ end
85
+
86
+ def doc_converter(node)
87
+ IsoDoc::WordConvert.new(doc_extract_attributes(node))
88
+ end
89
+
90
+ def presentation_xml_converter(node)
91
+ IsoDoc::PresentationXMLConvert.new(html_extract_attributes(node))
92
+ end
93
+
94
+ def default_fonts(node)
95
+ b = node.attr("body-font") ||
96
+ (node.attr("script") == "Hans" ? '"Source Han Sans",serif' : '"Cambria",serif')
97
+ h = node.attr("header-font") ||
98
+ (node.attr("script") == "Hans" ? '"Source Han Sans",sans-serif' : '"Cambria",serif')
99
+ m = node.attr("monospace-font") || '"Courier New",monospace'
100
+ "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
101
+ end
102
+
103
+ def outputs(node, ret)
104
+ File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) }
105
+ presentation_xml_converter(node).convert("#{@filename}.xml")
106
+ html_converter(node).convert("#{@filename}.presentation.xml",
107
+ nil, false, "#{@filename}.html")
108
+ doc_converter(node).convert("#{@filename}.presentation.xml",
109
+ nil, false, "#{@filename}.doc")
110
+ pdf_converter(node)&.convert("#{@filename}.presentation.xml",
111
+ nil, false, "#{@filename}.pdf")
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,90 @@
1
+ require "htmlentities"
2
+ require "uri" if /^2\./.match?(RUBY_VERSION)
3
+ require "mime/types"
4
+ require "base64"
5
+
6
+ module Metanorma
7
+ module Standoc
8
+ module Blocks
9
+ def reqt_subpart(name)
10
+ %w(specification measurement-target verification import label title
11
+ description component subject inherit classification).include? name
12
+ end
13
+
14
+ def reqt_subpart_attrs(node, name)
15
+ klass = node.attr("class") || "component"
16
+ attr_code(keep_attrs(node)
17
+ .merge(exclude: node.option?("exclude"),
18
+ type: node.attr("type"),
19
+ class: name == "component" ? klass : nil))
20
+ end
21
+
22
+ def requirement_subpart(node)
23
+ name = node.role || node.attr("style")
24
+ noko do |xml|
25
+ xml.send name, **reqt_subpart_attrs(node, name) do |o|
26
+ o << node.content
27
+ end
28
+ end
29
+ end
30
+
31
+ def req_classif_parse(classif)
32
+ ret = []
33
+ HTMLEntities.new.decode(classif).split(/;\s*/).each do |c|
34
+ c1 = c.split(/:\s*/)
35
+ next unless c1.size == 2
36
+
37
+ c1[1].split(/,\s*/).each { |v| ret << [c1[0], v] }
38
+ end
39
+ ret
40
+ end
41
+
42
+ def requirement_classification(classif, out)
43
+ req_classif_parse(classif).each do |r|
44
+ out.classification do |c|
45
+ c.tag { |t| t << r[0] }
46
+ c.value { |v| v << r[1] }
47
+ end
48
+ end
49
+ end
50
+
51
+ def reqt_attrs(node)
52
+ attr_code(keep_attrs(node).merge(id_unnum_attrs(node)).merge(
53
+ id: Metanorma::Utils::anchor_or_uuid(node),
54
+ unnumbered: node.option?("unnumbered") ? "true" : nil,
55
+ number: node.attr("number"),
56
+ subsequence: node.attr("subsequence"),
57
+ obligation: node.attr("obligation"),
58
+ filename: node.attr("filename"),
59
+ type: node.attr("type"),
60
+ model: node.attr("model"),
61
+ ))
62
+ end
63
+
64
+ def requirement_elems(node, out)
65
+ node.title and out.title { |t| t << node.title }
66
+ a = node.attr("label") and out.label do |l|
67
+ l << a
68
+ end
69
+ a = node.attr("subject") and csv_split(a)&.each do |subj|
70
+ out.subject { |s| s << subj }
71
+ end
72
+ a = HTMLEntities.new.decode(node.attr("inherit")) and
73
+ csv_split(a)&.each do |i|
74
+ out.inherit { |inh| inh << i }
75
+ end
76
+ classif = node.attr("classification") and
77
+ requirement_classification(classif, out)
78
+ end
79
+
80
+ def requirement(node, obligation)
81
+ noko do |xml|
82
+ xml.send obligation, **reqt_attrs(node) do |ex|
83
+ requirement_elems(node, ex)
84
+ wrap_in_para(node, ex)
85
+ end
86
+ end.join("\n")
87
+ end
88
+ end
89
+ end
90
+ end
File without changes