metanorma-standoc 1.11.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +3 -31
  3. data/.gitignore +23 -0
  4. data/Gemfile +2 -0
  5. data/lib/asciidoctor/standoc/base.rb +2 -241
  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 -207
  9. data/lib/asciidoctor/standoc/cleanup_amend.rb +2 -53
  10. data/lib/asciidoctor/standoc/cleanup_block.rb +2 -173
  11. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +2 -204
  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 -179
  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 -93
  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 -113
  24. data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +2 -161
  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 -219
  34. data/lib/asciidoctor/standoc/front_contributor.rb +2 -191
  35. data/lib/asciidoctor/standoc/inline.rb +2 -229
  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 -225
  43. data/lib/asciidoctor/standoc/ref_sect.rb +2 -143
  44. data/lib/asciidoctor/standoc/ref_utility.rb +2 -0
  45. data/lib/asciidoctor/standoc/render.rb +3 -0
  46. data/lib/asciidoctor/standoc/reqt.rb +2 -89
  47. data/lib/asciidoctor/standoc/section.rb +2 -190
  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 -153
  51. data/lib/asciidoctor/standoc/utils.rb +2 -116
  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 +20 -11
  55. data/lib/isodoc/html/htmlstyle.scss +11 -11
  56. data/lib/metanorma/standoc/base.rb +149 -0
  57. data/lib/{asciidoctor → metanorma}/standoc/basicdoc.rng +0 -0
  58. data/lib/{asciidoctor → metanorma}/standoc/biblio.rng +0 -0
  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 +146 -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 +70 -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 +96 -0
  79. data/lib/metanorma/standoc/cleanup_toc.rb +98 -0
  80. data/lib/metanorma/standoc/cleanup_xref.rb +107 -0
  81. data/lib/metanorma/standoc/converter.rb +124 -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 +90 -18
  89. data/lib/metanorma/standoc/lists.rb +120 -0
  90. data/lib/metanorma/standoc/macros.rb +204 -0
  91. data/lib/metanorma/standoc/macros_form.rb +63 -0
  92. data/lib/metanorma/standoc/macros_note.rb +45 -0
  93. data/lib/metanorma/standoc/macros_plantuml.rb +113 -0
  94. data/lib/metanorma/standoc/macros_terms.rb +181 -0
  95. data/lib/metanorma/standoc/ref.rb +243 -0
  96. data/lib/metanorma/standoc/ref_sect.rb +153 -0
  97. data/lib/metanorma/standoc/ref_utility.rb +129 -0
  98. data/lib/metanorma/standoc/render.rb +115 -0
  99. data/lib/metanorma/standoc/reqt.rb +90 -0
  100. data/lib/{asciidoctor → metanorma}/standoc/reqt.rng +0 -0
  101. data/lib/metanorma/standoc/section.rb +209 -0
  102. data/lib/metanorma/standoc/table.rb +85 -0
  103. data/lib/metanorma/standoc/term_lookup_cleanup.rb +179 -0
  104. data/lib/metanorma/standoc/terms.rb +160 -0
  105. data/lib/metanorma/standoc/utils.rb +101 -0
  106. data/lib/metanorma/standoc/validate.rb +158 -0
  107. data/lib/metanorma/standoc/validate_section.rb +55 -0
  108. data/lib/metanorma/standoc/version.rb +1 -1
  109. data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/model_representation.adoc.erb +0 -0
  110. data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/plantuml_representation.adoc.erb +0 -0
  111. data/lib/metanorma-standoc.rb +1 -1
  112. data/metanorma-standoc.gemspec +4 -4
  113. data/spec/{asciidoctor → metanorma}/base_spec.rb +73 -8
  114. data/spec/{asciidoctor → metanorma}/blank_spec.rb +1 -1
  115. data/spec/{asciidoctor → metanorma}/blocks_spec.rb +49 -20
  116. data/spec/{asciidoctor → metanorma}/cleanup_blocks_spec.rb +25 -1
  117. data/spec/{asciidoctor → metanorma}/cleanup_sections_spec.rb +2 -2
  118. data/spec/{asciidoctor → metanorma}/cleanup_spec.rb +9 -9
  119. data/spec/{asciidoctor → metanorma}/cleanup_terms_spec.rb +528 -91
  120. data/spec/{asciidoctor → metanorma}/datamodel/attributes_table_preprocessor_spec.rb +22 -22
  121. data/spec/{asciidoctor → metanorma}/datamodel/diagram_preprocessor_spec.rb +17 -17
  122. data/spec/{asciidoctor → metanorma}/inline_spec.rb +175 -6
  123. data/spec/{asciidoctor → metanorma}/isobib_cache_spec.rb +5 -9
  124. data/spec/{asciidoctor → metanorma}/lists_spec.rb +1 -1
  125. data/spec/{asciidoctor → metanorma}/macros_json2text_spec.rb +0 -0
  126. data/spec/{asciidoctor → metanorma}/macros_plantuml_spec.rb +3 -3
  127. data/spec/{asciidoctor → metanorma}/macros_spec.rb +8 -8
  128. data/spec/{asciidoctor → metanorma}/macros_yaml2text_spec.rb +0 -0
  129. data/spec/metanorma/refs_dl_spec.rb +863 -0
  130. data/spec/{asciidoctor → metanorma}/refs_spec.rb +1277 -687
  131. data/spec/{asciidoctor → metanorma}/section_spec.rb +90 -3
  132. data/spec/{asciidoctor → metanorma}/table_spec.rb +1 -1
  133. data/spec/{asciidoctor → metanorma}/validate_spec.rb +2 -2
  134. data/spec/spec_helper.rb +0 -1
  135. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +179 -179
  136. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
  137. data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
  138. data/spec/vcr_cassettes/isobib_get_123_1.yml +98 -98
  139. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +111 -111
  140. data/spec/vcr_cassettes/isobib_get_123_2001.yml +13 -13
  141. data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
  142. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
  143. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
  144. metadata +89 -38
  145. data/lib/asciidoctor/standoc/ref_date_id.rb +0 -62
  146. data/spec/asciidoctor/refs_dl_spec.rb +0 -864
@@ -1,191 +1,3 @@
1
- require "uri"
2
- require_relative "ref_sect"
3
- require_relative "terms"
1
+ require "asciidoctor/standoc/deprecated"
2
+ require "metanorma/standoc/section"
4
3
 
5
- module Asciidoctor
6
- module Standoc
7
- module Section
8
- @biblio = false
9
- @term_def = false
10
- @norm_ref = false
11
-
12
- def sectiontype1(node)
13
- node&.attr("heading")&.downcase ||
14
- node.title.gsub(%r{<index>.*?</index>}m, "").gsub(/<[^>]+>/, "")
15
- .strip.downcase
16
- end
17
-
18
- def sectiontype(node, level = true)
19
- ret = sectiontype1(node)
20
- ret1 = sectiontype_streamline(ret)
21
- return ret1 if ret1 == "symbols and abbreviated terms"
22
- return nil unless !level || node.level == 1
23
- return nil if @seen_headers.include? ret
24
-
25
- @seen_headers << ret
26
- ret1
27
- end
28
-
29
- def sectiontype_streamline(ret)
30
- case ret
31
- when "terms and definitions",
32
- "terms, definitions, symbols and abbreviated terms",
33
- "terms, definitions, symbols and abbreviations",
34
- "terms, definitions and symbols",
35
- "terms, definitions and abbreviations",
36
- "terms, definitions and abbreviated terms"
37
- "terms and definitions"
38
- when "symbols and abbreviated terms",
39
- "symbols", "abbreviated terms", "abbreviations"
40
- "symbols and abbreviated terms"
41
- else
42
- ret
43
- end
44
- end
45
-
46
- def section_attributes(node)
47
- ret = { id: Metanorma::Utils::anchor_or_uuid(node),
48
- language: node.attributes["language"],
49
- script: node.attributes["script"],
50
- number: node.attributes["number"],
51
- type: node.attributes["type"],
52
- annex: (if (node.attr("style") == "appendix" ||
53
- node.role == "appendix") &&
54
- node.level == 1
55
- true
56
- end),
57
- preface: (
58
- node.role == "preface" || node.attr("style") == "preface" ? true : nil) }
59
- return ret unless node.attributes["change"]
60
-
61
- ret.merge(change: node.attributes["change"],
62
- path: node.attributes["path"],
63
- path_end: node.attributes["path_end"],
64
- title: node.attributes["title"])
65
- end
66
-
67
- def section(node)
68
- a = section_attributes(node)
69
- noko do |xml|
70
- case sectiontype(node)
71
- when "introduction" then introduction_parse(a, xml, node)
72
- when "foreword" then foreword_parse(a, xml, node)
73
- when "scope" then scope_parse(a, xml, node)
74
- when "normative references" then norm_ref_parse(a, xml, node)
75
- when "terms and definitions"
76
- @term_def = true
77
- term_def_parse(a, xml, node, true)
78
- @term_def = false
79
- when "symbols and abbreviated terms"
80
- symbols_parse(symbols_attrs(node, a), xml, node)
81
- when "acknowledgements"
82
- acknowledgements_parse(a, xml, node)
83
- when "bibliography"
84
- bibliography_parse(a, xml, node)
85
- else
86
- if @term_def then term_def_subclause_parse(a, xml, node)
87
- elsif @definitions then symbols_parse(a, xml, node)
88
- elsif @norm_ref ||
89
- (node.attr("style") == "bibliography" &&
90
- sectiontype(node, false) == "normative references")
91
- norm_ref_parse(a, xml, node)
92
- elsif @biblio || node.attr("style") == "bibliography"
93
- bibliography_parse(a, xml, node)
94
- elsif node.attr("style") == "abstract"
95
- abstract_parse(a, xml, node)
96
- elsif node.attr("style") == "index"
97
- indexsect_parse(a, xml, node)
98
- elsif node.attr("style") == "appendix" && node.level == 1
99
- annex_parse(a, xml, node)
100
- else
101
- clause_parse(a, xml, node)
102
- end
103
- end
104
- end.join("\n")
105
- end
106
-
107
- def set_obligation(attrs, node)
108
- attrs[:obligation] = if node.attributes.has_key?("obligation")
109
- node.attr("obligation")
110
- elsif node.parent.attributes.has_key?("obligation")
111
- node.parent.attr("obligation")
112
- else
113
- "normative"
114
- end
115
- end
116
-
117
- def preamble(node)
118
- noko do |xml|
119
- xml.foreword **attr_code(section_attributes(node)) do |xml_abstract|
120
- xml_abstract.title do |t|
121
- t << (node.blocks[0].title || @i18n.foreword)
122
- end
123
- content = node.content
124
- xml_abstract << content
125
- end
126
- end.join("\n")
127
- end
128
-
129
- def indexsect_parse(attrs, xml, node)
130
- xml.indexsect **attr_code(attrs) do |xml_section|
131
- xml_section.title { |name| name << node.title }
132
- xml_section << node.content
133
- end
134
- end
135
-
136
- def abstract_parse(attrs, xml, node)
137
- xml.abstract **attr_code(attrs) do |xml_section|
138
- xml_section << node.content
139
- end
140
- end
141
-
142
- def scope_parse(attrs, xml, node)
143
- clause_parse(attrs.merge(type: "scope"), xml, node)
144
- end
145
-
146
- def clause_parse(attrs, xml, node)
147
- attrs[:"inline-header"] = node.option? "inline-header"
148
- attrs[:bibitem] = true if node.option? "bibitem"
149
- attrs[:level] = node.attr("level")
150
- set_obligation(attrs, node)
151
- xml.send "clause", **attr_code(attrs) do |xml_section|
152
- xml_section.title { |n| n << node.title } unless node.title.nil?
153
- xml_section << node.content
154
- end
155
- end
156
-
157
- def annex_parse(attrs, xml, node)
158
- attrs[:"inline-header"] = node.option? "inline-header"
159
- set_obligation(attrs, node)
160
- xml.annex **attr_code(attrs) do |xml_section|
161
- xml_section.title { |name| name << node.title }
162
- xml_section << node.content
163
- end
164
- end
165
-
166
- def introduction_parse(attrs, xml, node)
167
- xml.introduction **attr_code(attrs) do |xml_section|
168
- xml_section.title { |t| t << @i18n.introduction }
169
- content = node.content
170
- xml_section << content
171
- end
172
- end
173
-
174
- def foreword_parse(attrs, xml, node)
175
- xml.foreword **attr_code(attrs) do |xml_section|
176
- xml_section.title { |t| t << node.title }
177
- content = node.content
178
- xml_section << content
179
- end
180
- end
181
-
182
- def acknowledgements_parse(attrs, xml, node)
183
- xml.acknowledgements **attr_code(attrs) do |xml_section|
184
- xml_section.title { |t| (t << node.title) || @i18n.acknowledgements }
185
- content = node.content
186
- xml_section << content
187
- end
188
- end
189
- end
190
- end
191
- end
@@ -1,85 +1,3 @@
1
- module Asciidoctor
2
- module Standoc
3
- module Table
4
- def table_attrs(node)
5
- keep_attrs(node)
6
- .merge(id: Metanorma::Utils::anchor_or_uuid(node),
7
- headerrows: node.attr("headerrows"),
8
- unnumbered: node.option?("unnumbered") ? "true" : nil,
9
- number: node.attr("number"),
10
- subsequence: node.attr("subsequence"),
11
- alt: node.attr("alt"),
12
- summary: node.attr("summary"),
13
- width: node.attr("width"))
14
- end
1
+ require "asciidoctor/standoc/deprecated"
2
+ require "metanorma/standoc/table"
15
3
 
16
- def table(node)
17
- @table_fn_number = "a"
18
- noko do |xml|
19
- xml.table **attr_code(table_attrs(node)) do |xml_table|
20
- colgroup(node, xml_table)
21
- table_name(node, xml_table)
22
- %i(head body foot).reject do |tblsec|
23
- node.rows[tblsec].empty?
24
- end
25
- table_head_body_and_foot node, xml_table
26
- end
27
- end
28
- end
29
-
30
- private
31
-
32
- def colgroup(node, xml_table)
33
- return if node.option? "autowidth"
34
-
35
- cols = node&.attr("cols")&.split(/,/) or return
36
- return unless (cols.size > 1) && cols.all? { |c| /\d/.match(c) }
37
-
38
- xml_table.colgroup do |cg|
39
- node.columns.each do |col|
40
- cg.col **{ width: "#{col.attr 'colpcwidth'}%" }
41
- end
42
- end
43
- end
44
-
45
- def table_name(node, xml_table)
46
- if node.title?
47
- xml_table.name do |n|
48
- n << node.title
49
- end
50
- end
51
- end
52
-
53
- def table_cell1(cell, thd)
54
- thd << if cell.style == :asciidoc
55
- cell.content
56
- else
57
- cell.text
58
- end
59
- end
60
-
61
- def table_cell(node, xml_tr, tblsec)
62
- cell_attributes =
63
- { id: node.id, colspan: node.colspan, valign: node.attr("valign"),
64
- rowspan: node.rowspan, align: node.attr("halign") }
65
- cell_tag = "td"
66
- cell_tag = "th" if tblsec == :head || node.style == :header
67
- xml_tr.send cell_tag, **attr_code(cell_attributes) do |thd|
68
- table_cell1(node, thd)
69
- end
70
- end
71
-
72
- def table_head_body_and_foot(node, xml)
73
- %i(head body foot).reject { |s| node.rows[s].empty? }.each do |s|
74
- xml.send "t#{s}" do |xml_tblsec|
75
- node.rows[s].each do |row|
76
- xml_tblsec.tr do |xml_tr|
77
- row.each { |cell| table_cell(cell, xml_tr, s) }
78
- end
79
- end
80
- end
81
- end
82
- end
83
- end
84
- end
85
- end
@@ -1,179 +1,3 @@
1
- # frozen_string_literal: true.
2
- require "asciidoctor/standoc/utils"
1
+ require "asciidoctor/standoc/deprecated"
2
+ require "metanorma/standoc/term_lookup_cleanup"
3
3
 
4
-
5
- module Asciidoctor
6
- module Standoc
7
- # Intelligent term lookup xml modifier
8
- class TermLookupCleanup
9
- AUTOMATIC_GENERATED_ID_REGEXP = /\A_/.freeze
10
- EXISTING_TERM_REGEXP = /\Aterm-/.freeze
11
- EXISTING_SYMBOL_REGEXP = /\Asymbol-/.freeze
12
-
13
- attr_reader :xmldoc, :termlookup, :log
14
-
15
- def initialize(xmldoc, log)
16
- @xmldoc = xmldoc
17
- @log = log
18
- @termlookup = { term: {}, symbol: {}, secondary2primary: {} }
19
- @idhash = {}
20
- end
21
-
22
- def call
23
- @idhash = populate_idhash
24
- @termlookup = replace_automatic_generated_ids_terms
25
- set_termxref_tags_target
26
- concept_cleanup
27
- related_cleanup
28
- end
29
-
30
- private
31
-
32
- def concept_cleanup
33
- xmldoc.xpath("//concept").each do |n|
34
- n.delete("type")
35
- refterm = n.at("./refterm") or next
36
- p = @termlookup[:secondary2primary][refterm.text] and
37
- refterm.children = p
38
- end
39
- end
40
-
41
- def related_cleanup
42
- xmldoc.xpath("//related").each do |n|
43
- refterm = n.at("./refterm") or next
44
- p = @termlookup[:secondary2primary][refterm.text] and
45
- refterm.children = p
46
- refterm.replace("<preferred><expression><name>#{refterm.children.to_xml}"\
47
- "</name></expression></preferred>")
48
- end
49
- end
50
-
51
- def populate_idhash
52
- xmldoc.xpath("//*[@id]").each_with_object({}) do |n, mem|
53
- next unless /^(term|symbol)-/.match?(n["id"])
54
-
55
- mem[n["id"]] = true
56
- end
57
- end
58
-
59
- def set_termxref_tags_target
60
- xmldoc.xpath("//termxref").each do |node|
61
- target = normalize_ref_id(node.text)
62
- if termlookup[:term][target].nil? && termlookup[:symbol][target].nil?
63
- remove_missing_ref(node, target)
64
- next
65
- end
66
- x = node.at("../xrefrender") and modify_ref_node(x, target)
67
- node.name = "refterm"
68
- end
69
- end
70
-
71
- def remove_missing_ref(node, target)
72
- if node.at("../concept[@type = 'symbol']")
73
- remove_missing_ref_symbol(node, target)
74
- else
75
- remove_missing_ref_term(node, target)
76
- end
77
- end
78
-
79
- def remove_missing_ref_term(node, target)
80
- log.add("AsciiDoc Input", node,
81
- %(Error: Term reference in `term[#{target}]` missing: \
82
- "#{target}" is not defined in document))
83
- node.name = "strong"
84
- node&.at("../xrefrender")&.remove
85
- display = node&.at("../renderterm")&.remove&.children
86
- display = [] if display.nil? || display&.to_xml == node.text
87
- d = display.empty? ? "" : ", display <tt>#{display.to_xml}</tt>"
88
- node.children = "term <tt>#{node.text}</tt>#{d} "\
89
- "not resolved via ID <tt>#{target}</tt>"
90
- end
91
-
92
- def remove_missing_ref_symbol(node, target)
93
- log.add("AsciiDoc Input", node,
94
- %(Error: Symbol reference in `symbol[#{target}]` missing: \
95
- "#{target}" is not defined in document))
96
- node.name = "strong"
97
- node&.at("../xrefrender")&.remove
98
- display = node&.at("../renderterm")&.remove&.children
99
- display = [] if display.nil? || display&.to_xml == node.text
100
- d = display.empty? ? "" : ", display <tt>#{display.to_xml}</tt>"
101
- node.children = "symbol <tt>#{node.text}</tt>#{d} "\
102
- "not resolved via ID <tt>#{target}</tt>"
103
- end
104
-
105
- def modify_ref_node(node, target)
106
- node.name = "xref"
107
- s = termlookup[:symbol][target]
108
- t = termlookup[:term][target]
109
- type = node.parent["type"]
110
- if type == "term" || ((!type || node.parent.name == "related") && t)
111
- node["target"] = t
112
- elsif type == "symbol" ||
113
- ((!type || node.parent.name == "related") && s)
114
- node["target"] = s
115
- end
116
- end
117
-
118
- def replace_automatic_generated_ids_terms
119
- r = xmldoc.xpath("//term").each.with_object({}) do |n, res|
120
- normalize_id_and_memorize(n, res, "./preferred//name",
121
- "term")
122
- end
123
- s = xmldoc.xpath("//definitions//dt").each.with_object({}) do |n, res|
124
- normalize_id_and_memorize(n, res, ".", "symbol")
125
- end
126
- { term: r, symbol: s, secondary2primary: pref_secondary2primary }
127
- end
128
-
129
- def pref_secondary2primary
130
- xmldoc.xpath("//term").each.with_object({}) do |n, res|
131
- n.xpath("./preferred//name").each_with_index do |p, i|
132
- i.zero? and term = p.text
133
- i.positive? and res[p.text] = term
134
- end
135
- end
136
- end
137
-
138
- def normalize_id_and_memorize(node, res_table, text_selector, prefix)
139
- normalize_id_and_memorize_init(node, res_table, text_selector, prefix)
140
- memorize_other_pref_terms(node, res_table, text_selector)
141
- end
142
-
143
- def normalize_id_and_memorize_init(node, res_table, text_selector, prefix)
144
- term_text = normalize_ref_id(node.at(text_selector).text)
145
- unless AUTOMATIC_GENERATED_ID_REGEXP.match(node["id"]).nil? &&
146
- !node["id"].nil?
147
- id = unique_text_id(term_text, prefix)
148
- node["id"] = id
149
- @idhash[id] = true
150
- end
151
- res_table[term_text] = node["id"]
152
- end
153
-
154
- def memorize_other_pref_terms(node, res_table, text_selector)
155
- node.xpath(text_selector).each_with_index do |p, i|
156
- next unless i.positive?
157
-
158
- res_table[normalize_ref_id(p.text)] = node["id"]
159
- end
160
- end
161
-
162
- def normalize_ref_id(text)
163
- Metanorma::Utils::to_ncname(text.downcase.gsub(/[[:space:]]/, "-"))
164
- end
165
-
166
- def unique_text_id(text, prefix)
167
- unless @idhash["#{prefix}-#{text}"]
168
- return "#{prefix}-#{text}"
169
- end
170
-
171
- (1..Float::INFINITY).lazy.each do |index|
172
- unless @idhash["#{prefix}-#{text}-#{index}"]
173
- break("#{prefix}-#{text}-#{index}")
174
- end
175
- end
176
- end
177
- end
178
- end
179
- end
@@ -1,154 +1,3 @@
1
- module Asciidoctor
2
- module Standoc
3
- module Section
4
- def in_terms?
5
- @term_def
6
- end
1
+ require "asciidoctor/standoc/deprecated"
2
+ require "metanorma/standoc/terms"
7
3
 
8
- def nonterm_symbols_parse(attrs, xml, node)
9
- defs = @definitions
10
- @definitions = false
11
- clause_parse(attrs, xml, node)
12
- @definitions = defs
13
- end
14
-
15
- def symbols_attrs(node, attr)
16
- case sectiontype1(node)
17
- when "symbols" then attr.merge(type: "symbols")
18
- when "abbreviated terms", "abbreviations"
19
- attr.merge(type: "abbreviated_terms")
20
- else
21
- attr
22
- end
23
- end
24
-
25
- def symbols_parse(attr, xml, node)
26
- node.role == "nonterm" and return nonterm_symbols_parse(attr, xml, node)
27
- xml.definitions **attr_code(attr) do |xml_section|
28
- xml_section.title { |t| t << node.title }
29
- defs = @definitions
30
- termdefs = @term_def
31
- @definitions = true
32
- @term_def = false
33
- xml_section << node.content
34
- @definitions = defs
35
- @term_def = termdefs
36
- end
37
- end
38
-
39
- def nonterm_term_def_subclause_parse(attrs, xml, node)
40
- defs = @term_def
41
- @term_def = false
42
- clause_parse(attrs, xml, node)
43
- @term_def = defs
44
- end
45
-
46
- def terms_boilerplate_parse(attrs, xml, node)
47
- defs = @term_def
48
- @term_def = false
49
- clause_parse(attrs.merge(type: "boilerplate"), xml, node)
50
- @term_def = defs
51
- end
52
-
53
- # subclause contains subclauses
54
- def term_def_subclause_parse(attrs, xml, node)
55
- node.role == "nonterm" and
56
- return nonterm_term_def_subclause_parse(attrs, xml, node)
57
- node.role == "boilerplate" and
58
- return terms_boilerplate_parse(attrs, xml, node)
59
- st = sectiontype(node, false)
60
- return symbols_parse(attrs, xml, node) if @definitions
61
-
62
- sub = node.find_by(context: :section) { |s| s.level == node.level + 1 }
63
- sub.empty? || (return term_def_parse(attrs, xml, node, false))
64
- st == "symbols and abbreviated terms" and
65
- return symbols_parse(attrs, xml, node)
66
- st == "terms and definitions" and return clause_parse(attrs, xml, node)
67
- term_def_subclause_parse1(attrs, xml, node)
68
- end
69
-
70
- def term_def_subclause_parse1(attrs, xml, node)
71
- xml.term **attr_code(attrs) do |xml_section|
72
- term_designation(xml_section, node, "preferred", node.title)
73
- xml_section << node.content
74
- end
75
- end
76
-
77
- def term_def_parse(attrs, xml, node, _toplevel)
78
- xml.terms **attr_code(attrs) do |section|
79
- section.title { |t| t << node.title }
80
- (s = node.attr("source")) && s.split(",").each do |s1|
81
- section.termdocsource(nil, **attr_code(bibitemid: s1))
82
- end
83
- section << node.content
84
- end
85
- end
86
-
87
- def term_designation(xml, _node, tag, text)
88
- xml.send tag do |p|
89
- p.expression do |e|
90
- e.name { |name| name << text }
91
- end
92
- end
93
- end
94
-
95
- def term_source_attrs(_node, seen_xref)
96
- { case: seen_xref.children[0]["case"],
97
- droploc: seen_xref.children[0]["droploc"],
98
- bibitemid: seen_xref.children[0]["target"],
99
- format: seen_xref.children[0]["format"], type: "inline" }
100
- end
101
-
102
- def add_term_source(node, xml_t, seen_xref, match)
103
- if seen_xref.children[0].name == "concept"
104
- xml_t.origin { |o| o << seen_xref.children[0].to_xml }
105
- else
106
- attrs = term_source_attrs(node, seen_xref)
107
- attrs.delete(:text)
108
- xml_t.origin seen_xref.children[0].content, **attr_code(attrs)
109
- end
110
- match[:text] && xml_t.modification do |mod|
111
- mod.p { |p| p << match[:text].sub(/^\s+/, "") }
112
- end
113
- end
114
-
115
- TERM_REFERENCE_RE_STR = <<~REGEXP.freeze
116
- ^(?<xref><(xref|concept)[^>]+>(.*?</(xref|concept)>)?)
117
- (,\s(?<text>.*))?
118
- $
119
- REGEXP
120
- TERM_REFERENCE_RE =
121
- Regexp.new(TERM_REFERENCE_RE_STR.gsub(/\s/, "").gsub(/_/, "\\s"),
122
- Regexp::IGNORECASE | Regexp::MULTILINE)
123
-
124
- def extract_termsource_refs(text, node)
125
- matched = TERM_REFERENCE_RE.match text
126
- matched.nil? and @log.add("AsciiDoc Input", node,
127
- "term reference not in expected format:"\
128
- "#{text}")
129
- matched
130
- end
131
-
132
- def termsource(node)
133
- matched = extract_termsource_refs(node.content, node) || return
134
- noko do |xml|
135
- status = node.attr("status") ||
136
- (matched[:text] ? "modified" : "identical")
137
- attrs = { status: status, type: node.attr("type") || "authoritative" }
138
- xml.termsource **attrs do |xml_t|
139
- seen_xref = Nokogiri::XML.fragment(matched[:xref])
140
- add_term_source(node, xml_t, seen_xref, matched)
141
- end
142
- end.join("\n")
143
- end
144
-
145
- def termdefinition(node)
146
- noko do |xml|
147
- xml.definition do |d|
148
- d << node.content
149
- end
150
- end.join("\n")
151
- end
152
- end
153
- end
154
- end