metanorma-standoc 1.10.0 → 1.10.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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asciidoctor/standoc/base.rb +0 -1
  3. data/lib/asciidoctor/standoc/blocks.rb +1 -1
  4. data/lib/asciidoctor/standoc/cleanup.rb +1 -2
  5. data/lib/asciidoctor/standoc/cleanup_block.rb +0 -1
  6. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +2 -2
  7. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +0 -1
  8. data/lib/asciidoctor/standoc/cleanup_maths.rb +0 -1
  9. data/lib/asciidoctor/standoc/cleanup_section.rb +0 -1
  10. data/lib/asciidoctor/standoc/converter.rb +1 -0
  11. data/lib/asciidoctor/standoc/front.rb +0 -1
  12. data/lib/asciidoctor/standoc/front_contributor.rb +0 -1
  13. data/lib/asciidoctor/standoc/isodoc.rng +32 -7
  14. data/lib/asciidoctor/standoc/macros.rb +7 -5
  15. data/lib/asciidoctor/standoc/macros_plantuml.rb +3 -3
  16. data/lib/asciidoctor/standoc/macros_terms.rb +34 -7
  17. data/lib/asciidoctor/standoc/section.rb +19 -12
  18. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +58 -17
  19. data/lib/asciidoctor/standoc/utils.rb +0 -1
  20. data/lib/asciidoctor/standoc/validate.rb +4 -3
  21. data/lib/isodoc/html/html_titlepage.html +81 -0
  22. data/lib/isodoc/html/htmlstyle.css +983 -0
  23. data/lib/isodoc/html/htmlstyle.scss +714 -0
  24. data/lib/isodoc/html/scripts.html +71 -0
  25. data/lib/metanorma/standoc/processor.rb +16 -7
  26. data/lib/metanorma/standoc/version.rb +1 -1
  27. data/spec/asciidoctor/cleanup_spec.rb +12 -12
  28. data/spec/asciidoctor/macros_json2text_spec.rb +1 -1
  29. data/spec/asciidoctor/macros_spec.rb +228 -75
  30. data/spec/asciidoctor/validate_spec.rb +12 -2
  31. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +50 -50
  32. data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
  33. data/spec/vcr_cassettes/isobib_get_123_1.yml +23 -23
  34. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +34 -34
  35. data/spec/vcr_cassettes/isobib_get_123_2001.yml +13 -13
  36. data/spec/vcr_cassettes/isobib_get_124.yml +12 -12
  37. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
  38. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
  39. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f802ef3bf91b1b1af85aa22ca72569b6a6d74b29ed4389373e6b42e7d364b016
4
- data.tar.gz: 55bd7031c2f7a2623955c9d1778b48a5a1666d15a0fe160a8058b544ffe60f92
3
+ metadata.gz: f5a985aefd39dadc19549ad39c23e0849bac873ea5883e50762ca911c8bd3aad
4
+ data.tar.gz: b7560f906a1e50fc4032f3261a44d1edcb2e691872b3e85d14a0363d7668b575
5
5
  SHA512:
6
- metadata.gz: 59462520c525758884fdeac23103756b75908daf58707c25ed1420c3e7184e6c3cfaaa7ecd3770619cb3f5d7d9eedc9778b96980b5a33fcdedbea015da9e2684
7
- data.tar.gz: ad562abbf62b1217ab40c933a1f32fe7dbbc474561c47ff0ed91c7de9e9262e3b0612393d8354eccacf30b034316635f5c84aa80f24cc2d5e6e5650bd918e485
6
+ metadata.gz: 437c04558d97c828a200ca21668a0e74e7e9fe5b5581ab759955f9ada241a0a87ccfddf114b7bd616430107e5869ce785c547715d627a08b87e35a30237b0516
7
+ data.tar.gz: 11d70602d2bd7733e9daab869ec22e3bf58ff6397378b38734711d46cb8f6e04b25e5b5fbcd3b5cd1e36b8e58a1061c92a87502fab945ea8a8c573205e25b126
@@ -3,7 +3,6 @@ require "nokogiri"
3
3
  require "htmlentities"
4
4
  require "json"
5
5
  require "pathname"
6
- require "open-uri"
7
6
  require "isodoc"
8
7
  require "relaton"
9
8
  require "fileutils"
@@ -41,7 +41,7 @@ module Asciidoctor
41
41
  def form(node)
42
42
  noko do |xml|
43
43
  xml.form **attr_code(
44
- id: Metanorma::Utils::anchor_or_uuid,
44
+ id: Metanorma::Utils::anchor_or_uuid, class: node.attr("class"),
45
45
  name: node.attr("name"), action: node.attr("action")
46
46
  ) do |f|
47
47
  f << node.content
@@ -1,6 +1,5 @@
1
1
  require "nokogiri"
2
2
  require "pathname"
3
- require "open-uri"
4
3
  require "html2doc"
5
4
  require_relative "./cleanup_block"
6
5
  require_relative "./cleanup_footnotes"
@@ -48,6 +47,7 @@ module Asciidoctor
48
47
  xref_cleanup(xmldoc)
49
48
  concept_cleanup(xmldoc)
50
49
  origin_cleanup(xmldoc)
50
+ bookmark_cleanup(xmldoc)
51
51
  termdef_cleanup(xmldoc)
52
52
  RelatonIev::iev_cleanup(xmldoc, @bibdb)
53
53
  element_name_cleanup(xmldoc)
@@ -58,7 +58,6 @@ module Asciidoctor
58
58
  mathml_cleanup(xmldoc)
59
59
  script_cleanup(xmldoc)
60
60
  docidentifier_cleanup(xmldoc)
61
- bookmark_cleanup(xmldoc)
62
61
  requirement_cleanup(xmldoc)
63
62
  bibdata_cleanup(xmldoc)
64
63
  svgmap_cleanup(xmldoc)
@@ -1,6 +1,5 @@
1
1
  require "date"
2
2
  require "htmlentities"
3
- require "open-uri"
4
3
 
5
4
  module Asciidoctor
6
5
  module Standoc
@@ -158,11 +158,11 @@ module Asciidoctor
158
158
  xmldoc.root << "<bibliography/>" and ins = xmldoc.at("bibliography")
159
159
  ins = ins.add_child("<references hidden='true' normative='false'/>").first
160
160
  refs.each do |x|
161
- ins << <<~END
161
+ ins << <<~BIB
162
162
  <bibitem id="#{x}" type="internal">
163
163
  <docidentifier type="repository">#{x.sub(/^#{prefix}_/, "#{prefix}/")}</docidentifier>
164
164
  </bibitem>
165
- END
165
+ BIB
166
166
  end
167
167
  end
168
168
 
@@ -1,7 +1,6 @@
1
1
  require "date"
2
2
  require "htmlentities"
3
3
  require "json"
4
- require "open-uri"
5
4
 
6
5
  module Asciidoctor
7
6
  module Standoc
@@ -1,6 +1,5 @@
1
1
  require "nokogiri"
2
2
  require "pathname"
3
- require "open-uri"
4
3
  require "html2doc"
5
4
  require "asciimath2unitsml"
6
5
  require_relative "./cleanup_block"
@@ -1,7 +1,6 @@
1
1
  require "date"
2
2
  require "htmlentities"
3
3
  require "json"
4
- require "open-uri"
5
4
  require "mathml2asciimath"
6
5
  require_relative "cleanup_section_names"
7
6
 
@@ -37,6 +37,7 @@ module Asciidoctor
37
37
  inline_macro Asciidoctor::Standoc::VariantInlineMacro
38
38
  inline_macro Asciidoctor::Standoc::FootnoteBlockInlineMacro
39
39
  inline_macro Asciidoctor::Standoc::TermRefInlineMacro
40
+ inline_macro Asciidoctor::Standoc::SymbolRefInlineMacro
40
41
  inline_macro Asciidoctor::Standoc::IndexXrefInlineMacro
41
42
  inline_macro Asciidoctor::Standoc::IndexRangeInlineMacro
42
43
  inline_macro Asciidoctor::Standoc::AddMacro
@@ -2,7 +2,6 @@ require "date"
2
2
  require "nokogiri"
3
3
  require "htmlentities"
4
4
  require "pathname"
5
- require "open-uri"
6
5
  require_relative "./front_contributor"
7
6
 
8
7
  module Asciidoctor
@@ -2,7 +2,6 @@ require "date"
2
2
  require "nokogiri"
3
3
  require "htmlentities"
4
4
  require "pathname"
5
- require "open-uri"
6
5
  require "csv"
7
6
 
8
7
  module Asciidoctor
@@ -204,6 +204,18 @@
204
204
  </zeroOrMore>
205
205
  </element>
206
206
  </define>
207
+ <define name="dt">
208
+ <element name="dt">
209
+ <optional>
210
+ <attribute name="id">
211
+ <data type="ID"/>
212
+ </attribute>
213
+ </optional>
214
+ <zeroOrMore>
215
+ <ref name="TextElement"/>
216
+ </zeroOrMore>
217
+ </element>
218
+ </define>
207
219
  <define name="example">
208
220
  <element name="example">
209
221
  <attribute name="id">
@@ -899,7 +911,7 @@
899
911
  </include>
900
912
  <!-- end overrides -->
901
913
  <define name="docsubtype">
902
- <element name="docsubtype">
914
+ <element name="subdoctype">
903
915
  <ref name="DocumentSubtype"/>
904
916
  </element>
905
917
  </define>
@@ -954,6 +966,16 @@
954
966
  </define>
955
967
  <define name="concept">
956
968
  <element name="concept">
969
+ <optional>
970
+ <attribute name="ital">
971
+ <data type="boolean"/>
972
+ </attribute>
973
+ </optional>
974
+ <optional>
975
+ <attribute name="ref">
976
+ <data type="boolean"/>
977
+ </attribute>
978
+ </optional>
957
979
  <optional>
958
980
  <element name="refterm">
959
981
  <zeroOrMore>
@@ -998,6 +1020,9 @@
998
1020
  </attribute>
999
1021
  <attribute name="name"/>
1000
1022
  <attribute name="action"/>
1023
+ <optional>
1024
+ <attribute name="class"/>
1025
+ </optional>
1001
1026
  <zeroOrMore>
1002
1027
  <choice>
1003
1028
  <ref name="TextElement"/>
@@ -1490,26 +1515,26 @@
1490
1515
  <optional>
1491
1516
  <ref name="section-title"/>
1492
1517
  </optional>
1493
- <group>
1518
+ <choice>
1494
1519
  <choice>
1495
1520
  <group>
1496
- <zeroOrMore>
1521
+ <oneOrMore>
1497
1522
  <ref name="BasicBlock"/>
1498
- </zeroOrMore>
1523
+ </oneOrMore>
1499
1524
  <zeroOrMore>
1500
1525
  <ref name="note"/>
1501
1526
  </zeroOrMore>
1502
1527
  </group>
1503
1528
  <ref name="amend"/>
1504
1529
  </choice>
1505
- <zeroOrMore>
1530
+ <oneOrMore>
1506
1531
  <choice>
1507
1532
  <ref name="clause-subsection"/>
1508
1533
  <ref name="terms"/>
1509
1534
  <ref name="definitions"/>
1510
1535
  </choice>
1511
- </zeroOrMore>
1512
- </group>
1536
+ </oneOrMore>
1537
+ </choice>
1513
1538
  </define>
1514
1539
  <define name="Annex-Section">
1515
1540
  <optional>
@@ -75,7 +75,7 @@ module Asciidoctor
75
75
  def supply_br(lines)
76
76
  ignore = false
77
77
  lines.each_with_index do |l, i|
78
- /^(--+|====+|\|===|\.\.\.\.+|\*\*\*\*+|\+\+\+\++|\`\`\`\`+|____\+)$/
78
+ /^(--+|====+|\|===|\.\.\.\.+|\*\*\*\*+|\+\+\+\++|````+|____\+)$/
79
79
  .match(l) && (ignore = !ignore)
80
80
  next if l.empty? || l.match(/ \+$/) || /^\[.*\]$/.match?(l) || ignore
81
81
  next if i == lines.size - 1 ||
@@ -107,7 +107,7 @@ module Asciidoctor
107
107
  if (attributes.size == 1) && attributes.key?("text")
108
108
  rt = attributes["text"]
109
109
  elsif (attributes.size == 2) && attributes.key?(1) &&
110
- attributes.key?("rpbegin")
110
+ attributes.key?("rpbegin")
111
111
  rt = attributes[1] || ""
112
112
  else
113
113
  rpbegin = attributes["rpbegin"]
@@ -143,7 +143,7 @@ module Asciidoctor
143
143
  para.set_attr("caption", "TODO")
144
144
  para.lines[0].sub!(/^TODO: /, "")
145
145
  todo = Block.new(parent, :admonition, attributes: para.attributes,
146
- source: para.lines, content_model: :compound)
146
+ source: para.lines, content_model: :compound)
147
147
  parent.blocks[parent.blocks.index(para)] = todo
148
148
  end
149
149
  end
@@ -168,9 +168,11 @@ module Asciidoctor
168
168
  def process(parent, target, attrs)
169
169
  /^(?<lang>[^-]*)(-(?<script>.*))?$/ =~ target
170
170
  out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
171
- script ?
172
- %{<variant lang=#{lang} script=#{script}>#{out}</variant>} :
171
+ if script
172
+ %{<variant lang=#{lang} script=#{script}>#{out}</variant>}
173
+ else
173
174
  %{<variant lang=#{lang}>#{out}</variant>}
175
+ end
174
176
  end
175
177
  end
176
178
 
@@ -12,7 +12,6 @@ module Asciidoctor
12
12
  end
13
13
  end
14
14
  raise "PlantUML not installed"
15
- nil
16
15
  end
17
16
 
18
17
  def self.run(umlfile, outfile)
@@ -59,7 +58,7 @@ module Asciidoctor
59
58
  Tempfile.open(["plantuml", ".pml"], encoding: "utf-8") do |f|
60
59
  f.write(src)
61
60
  [f, File.join(File.dirname(f.path),
62
- (fn || File.basename(f.path, ".pml")) + ".png")]
61
+ "#{fn || File.basename(f.path, '.pml')}.png")]
63
62
  end
64
63
  end
65
64
 
@@ -81,7 +80,8 @@ module Asciidoctor
81
80
  def abort(parent, reader, attrs, msg)
82
81
  warn msg
83
82
  attrs["language"] = "plantuml"
84
- create_listing_block parent, reader.source, attrs.reject { |k, _v| k == 1 }
83
+ create_listing_block parent, reader.source,
84
+ (attrs.reject { |k, _v| k == 1 })
85
85
  end
86
86
 
87
87
  def process(parent, reader, attrs)
@@ -46,7 +46,20 @@ module Asciidoctor
46
46
 
47
47
  def process(_parent, _target, attrs)
48
48
  termref = attrs["termxref"] || attrs["name"]
49
- "<concept><termxref>#{attrs['name']}</termxref>"\
49
+ "<concept type='term'><termxref>#{attrs['name']}</termxref>"\
50
+ "<renderterm>#{termref}</renderterm><xrefrender/></concept>"
51
+ end
52
+ end
53
+
54
+ class SymbolRefInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
55
+ use_dsl
56
+ named :symbol
57
+ name_positional_attributes "name", "termxref"
58
+ using_format :short
59
+
60
+ def process(_parent, _target, attrs)
61
+ termref = attrs["termxref"] || attrs["name"]
62
+ "<concept type='symbol'><termxref>#{attrs['name']}</termxref>"\
50
63
  "<renderterm>#{termref}</renderterm><xrefrender/></concept>"
51
64
  end
52
65
  end
@@ -68,24 +81,38 @@ module Asciidoctor
68
81
  def preprocess_attrs(target)
69
82
  m = /^(?<id>&lt;&lt;.+?&gt;&gt;)?(?<rest>.*)$/.match(target)
70
83
  ret = { id: m[:id]&.sub(/^&lt;&lt;/, "")&.sub(/&gt;&gt;$/, "") }
71
- m2 = /^(?<rest>.*)(?<opt>,option=.+)?$/.match(m[:rest].sub(/^,/, ""))
72
- ret[:opt] = m2[:opt]&.sub(/^,option=/, "")
73
- attrs = CSV.parse_line(m2[:rest]) || []
84
+ if m2 = /^(?<rest>.*?)(?<opt>,option=.+)$/.match(m[:rest].sub(/^,/, ""))
85
+ ret[:opt] = CSV.parse_line(m2[:opt].sub(/^,option=/, "")
86
+ .sub(/^"(.+)"$/, "\\1").sub(/^'(.+)'$/, "\\1"))
87
+ attrs = CSV.parse_line(m2[:rest]) || []
88
+ else
89
+ attrs = CSV.parse_line(m[:rest].sub(/^,/, "")) || []
90
+ end
74
91
  ret.merge(term: attrs[0], word: attrs[1] || attrs[0],
75
92
  xrefrender: attrs[2])
76
93
  end
77
94
 
95
+ def generate_attrs(opts)
96
+ ret = ""
97
+ opts.include?("noital") and ret += " ital='false'"
98
+ opts.include?("noref") and ret += " ref='false'"
99
+ opts.include?("ital") and ret += " ital='true'"
100
+ opts.include?("ref") and ret += " ref='true'"
101
+ ret
102
+ end
103
+
78
104
  def process(parent, target, _attrs)
79
105
  attrs = preprocess_attrs(target)
80
106
  termout = Asciidoctor::Inline.new(parent, :quoted, attrs[:term]).convert
81
107
  wordout = Asciidoctor::Inline.new(parent, :quoted, attrs[:word]).convert
82
108
  xrefout = Asciidoctor::Inline.new(parent, :quoted,
83
109
  attrs[:xrefrender]).convert
84
- attrs[:id] and return "<concept key='#{attrs[:id]}'><refterm>"\
110
+ optout = generate_attrs(attrs[:opt] || [])
111
+ attrs[:id] and return "<concept#{optout} key='#{attrs[:id]}'><refterm>"\
85
112
  "#{termout}</refterm><renderterm>#{wordout}</renderterm>"\
86
113
  "<xrefrender>#{xrefout}</xrefrender></concept>"
87
- "<concept><termxref>#{termout}</termxref><renderterm>#{wordout}"\
88
- "</renderterm><xrefrender>#{xrefout}</xrefrender></concept>"
114
+ "<concept#{optout}><termxref>#{termout}</termxref><renderterm>"\
115
+ "#{wordout}</renderterm><xrefrender>#{xrefout}</xrefrender></concept>"
89
116
  end
90
117
  end
91
118
  end
@@ -12,7 +12,7 @@ module Asciidoctor
12
12
  def sectiontype1(node)
13
13
  node&.attr("heading")&.downcase ||
14
14
  node.title.gsub(%r{<index>.*?</index>}m, "").gsub(/<[^>]+>/, "")
15
- .strip.downcase
15
+ .strip.downcase
16
16
  end
17
17
 
18
18
  def sectiontype(node, level = true)
@@ -21,6 +21,7 @@ module Asciidoctor
21
21
  return ret1 if "symbols and abbreviated terms" == ret1
22
22
  return nil unless !level || node.level == 1
23
23
  return nil if @seen_headers.include? ret
24
+
24
25
  @seen_headers << ret
25
26
  ret1
26
27
  end
@@ -48,11 +49,14 @@ module Asciidoctor
48
49
  script: node.attributes["script"],
49
50
  number: node.attributes["number"],
50
51
  type: node.attributes["type"],
51
- annex: ( ((node.attr("style") == "appendix" || node.role == "appendix") &&
52
- node.level == 1) ? true : nil),
53
- preface: (
54
- (node.role == "preface" || node.attr("style") == "preface") ? true : nil) }
52
+ annex: (if (node.attr("style") == "appendix" || node.role == "appendix") &&
53
+ node.level == 1
54
+ true
55
+ end),
56
+ preface: (
57
+ node.role == "preface" || node.attr("style") == "preface" ? true : nil) }
55
58
  return ret unless node.attributes["change"]
59
+
56
60
  ret.merge(change: node.attributes["change"],
57
61
  path: node.attributes["path"],
58
62
  path_end: node.attributes["path_end"],
@@ -75,7 +79,7 @@ module Asciidoctor
75
79
  symbols_parse(symbols_attrs(node, a), xml, node)
76
80
  when "acknowledgements"
77
81
  acknowledgements_parse(a, xml, node)
78
- when "bibliography"
82
+ when "bibliography"
79
83
  bibliography_parse(a, xml, node)
80
84
  else
81
85
  if @term_def then term_def_subclause_parse(a, xml, node)
@@ -88,9 +92,9 @@ module Asciidoctor
88
92
  bibliography_parse(a, xml, node)
89
93
  elsif node.attr("style") == "bibliography"
90
94
  bibliography_parse(a, xml, node)
91
- elsif node.attr("style") == "abstract"
95
+ elsif node.attr("style") == "abstract"
92
96
  abstract_parse(a, xml, node)
93
- elsif node.attr("style") == "index"
97
+ elsif node.attr("style") == "index"
94
98
  indexsect_parse(a, xml, node)
95
99
  elsif node.attr("style") == "appendix" && node.level == 1
96
100
  annex_parse(a, xml, node)
@@ -102,10 +106,13 @@ module Asciidoctor
102
106
  end
103
107
 
104
108
  def set_obligation(attrs, node)
105
- attrs[:obligation] = node.attributes.has_key?("obligation") ?
106
- node.attr("obligation") :
107
- node.parent.attributes.has_key?("obligation") ?
108
- node.parent.attr("obligation") : "normative"
109
+ attrs[:obligation] = if node.attributes.has_key?("obligation")
110
+ node.attr("obligation")
111
+ elsif node.parent.attributes.has_key?("obligation")
112
+ node.parent.attr("obligation")
113
+ else
114
+ "normative"
115
+ end
109
116
  end
110
117
 
111
118
  def preamble(node)
@@ -6,13 +6,14 @@ module Asciidoctor
6
6
  class TermLookupCleanup
7
7
  AUTOMATIC_GENERATED_ID_REGEXP = /\A_/.freeze
8
8
  EXISTING_TERM_REGEXP = /\Aterm-/.freeze
9
+ EXISTING_SYMBOL_REGEXP = /\Asymbol-/.freeze
9
10
 
10
11
  attr_reader :xmldoc, :termlookup, :log
11
12
 
12
13
  def initialize(xmldoc, log)
13
14
  @xmldoc = xmldoc
14
15
  @log = log
15
- @termlookup = {}
16
+ @termlookup = { term: {}, symbol: {} }
16
17
  @idhash = {}
17
18
  end
18
19
 
@@ -20,13 +21,20 @@ module Asciidoctor
20
21
  @idhash = populate_idhash
21
22
  @termlookup = replace_automatic_generated_ids_terms
22
23
  set_termxref_tags_target
24
+ concept_cleanup
23
25
  end
24
26
 
25
27
  private
26
28
 
29
+ def concept_cleanup
30
+ xmldoc.xpath("//concept").each do |n|
31
+ n.delete("type")
32
+ end
33
+ end
34
+
27
35
  def populate_idhash
28
36
  xmldoc.xpath("//*[@id]").each_with_object({}) do |n, mem|
29
- next unless /^term-/.match?(n["id"])
37
+ next unless /^(term|symbol)-/.match?(n["id"])
30
38
 
31
39
  mem[n["id"]] = true
32
40
  end
@@ -35,7 +43,7 @@ module Asciidoctor
35
43
  def set_termxref_tags_target
36
44
  xmldoc.xpath("//termxref").each do |node|
37
45
  target = normalize_ref_id(node.text)
38
- if termlookup[target].nil?
46
+ if termlookup[:term][target].nil? && termlookup[:symbol][target].nil?
39
47
  remove_missing_ref(node, target)
40
48
  next
41
49
  end
@@ -46,6 +54,14 @@ module Asciidoctor
46
54
  end
47
55
 
48
56
  def remove_missing_ref(node, target)
57
+ if node.at("../concept[@type = 'symbol']")
58
+ remove_missing_ref_symbol(node, target)
59
+ else
60
+ remove_missing_ref_term(node, target)
61
+ end
62
+ end
63
+
64
+ def remove_missing_ref_term(node, target)
49
65
  log.add("AsciiDoc Input", node,
50
66
  %(Error: Term reference in `term[#{target}]` missing: \
51
67
  "#{target}" is not defined in document))
@@ -58,39 +74,64 @@ module Asciidoctor
58
74
  "not resolved via ID <tt>#{target}</tt>"
59
75
  end
60
76
 
77
+ def remove_missing_ref_symbol(node, target)
78
+ log.add("AsciiDoc Input", node,
79
+ %(Error: Symbol reference in `symbol[#{target}]` missing: \
80
+ "#{target}" is not defined in document))
81
+ node.name = "strong"
82
+ node.at("../xrefrender").remove
83
+ display = node&.at("../renderterm")&.remove&.children
84
+ display = [] if display.nil? || display&.to_xml == node.text
85
+ d = display.empty? ? "" : ", display <tt>#{display.to_xml}</tt>"
86
+ node.children = "symbol <tt>#{node.text}</tt>#{d} "\
87
+ "not resolved via ID <tt>#{target}</tt>"
88
+ end
89
+
61
90
  def modify_ref_node(node, target)
62
91
  node.name = "xref"
63
- node["target"] = termlookup[target]
92
+ s = termlookup[:symbol][target]
93
+ t = termlookup[:term][target]
94
+ type = node.parent["type"]
95
+ if type == "term" || !type && t
96
+ node["target"] = t
97
+ elsif type == "symbol" || !type && s
98
+ node["target"] = s
99
+ end
64
100
  end
65
101
 
66
102
  def replace_automatic_generated_ids_terms
67
- xmldoc.xpath("//term").each.with_object({}) do |term_node, res|
68
- normalize_id_and_memorize(term_node, res, "./preferred")
103
+ r = xmldoc.xpath("//term").each.with_object({}) do |n, res|
104
+ normalize_id_and_memorize(n, res, "./preferred", "term")
105
+ end
106
+ s = xmldoc.xpath("//definitions//dt").each.with_object({}) do |n, res|
107
+ normalize_id_and_memorize(n, res, ".", "symbol")
69
108
  end
109
+ { term: r, symbol: s }
70
110
  end
71
111
 
72
- def normalize_id_and_memorize(term_node, res_table, text_selector)
73
- term_text = normalize_ref_id(term_node.at(text_selector).text)
74
- unless AUTOMATIC_GENERATED_ID_REGEXP.match(term_node["id"]).nil?
75
- id = unique_text_id(term_text)
76
- term_node["id"] = id
112
+ def normalize_id_and_memorize(node, res_table, text_selector, prefix)
113
+ term_text = normalize_ref_id(node.at(text_selector).text)
114
+ unless AUTOMATIC_GENERATED_ID_REGEXP.match(node["id"]).nil? &&
115
+ !node["id"].nil?
116
+ id = unique_text_id(term_text, prefix)
117
+ node["id"] = id
77
118
  @idhash[id] = true
78
119
  end
79
- res_table[term_text] = term_node["id"]
120
+ res_table[term_text] = node["id"]
80
121
  end
81
122
 
82
123
  def normalize_ref_id(text)
83
124
  text.downcase.gsub(/[[:space:]]/, "-")
84
125
  end
85
126
 
86
- def unique_text_id(text)
87
- unless @idhash["term-#{text}"]
88
- return "term-#{text}"
127
+ def unique_text_id(text, prefix)
128
+ unless @idhash["#{prefix}-#{text}"]
129
+ return "#{prefix}-#{text}"
89
130
  end
90
131
 
91
132
  (1..Float::INFINITY).lazy.each do |index|
92
- unless @idhash["term-#{text}-#{index}"]
93
- break("term-#{text}-#{index}")
133
+ unless @idhash["#{prefix}-#{text}-#{index}"]
134
+ break("#{prefix}-#{text}-#{index}")
94
135
  end
95
136
  end
96
137
  end