metanorma-standoc 1.7.3 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asciidoctor/standoc/base.rb +31 -44
  3. data/lib/asciidoctor/standoc/basicdoc.rng +5 -3
  4. data/lib/asciidoctor/standoc/blocks.rb +7 -7
  5. data/lib/asciidoctor/standoc/blocks_notes.rb +2 -2
  6. data/lib/asciidoctor/standoc/cleanup.rb +5 -6
  7. data/lib/asciidoctor/standoc/cleanup_block.rb +3 -3
  8. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +56 -0
  9. data/lib/asciidoctor/standoc/cleanup_inline.rb +22 -26
  10. data/lib/asciidoctor/standoc/cleanup_ref.rb +0 -85
  11. data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +94 -0
  12. data/lib/asciidoctor/standoc/converter.rb +0 -1
  13. data/lib/asciidoctor/standoc/front.rb +2 -2
  14. data/lib/asciidoctor/standoc/inline.rb +1 -1
  15. data/lib/asciidoctor/standoc/isodoc.rng +3 -0
  16. data/lib/asciidoctor/standoc/lists.rb +2 -2
  17. data/lib/asciidoctor/standoc/macros_plantuml.rb +1 -1
  18. data/lib/asciidoctor/standoc/ref_sect.rb +2 -2
  19. data/lib/asciidoctor/standoc/reqt.rb +6 -1
  20. data/lib/asciidoctor/standoc/section.rb +3 -80
  21. data/lib/asciidoctor/standoc/table.rb +1 -1
  22. data/lib/asciidoctor/standoc/terms.rb +125 -0
  23. data/lib/asciidoctor/standoc/utils.rb +2 -96
  24. data/lib/metanorma/standoc/version.rb +1 -1
  25. data/metanorma-standoc.gemspec +2 -2
  26. data/spec/asciidoctor-standoc/base_spec.rb +30 -1
  27. data/spec/asciidoctor-standoc/cleanup_spec.rb +111 -2
  28. data/spec/asciidoctor-standoc/isobib_cache_spec.rb +4 -4
  29. data/spec/asciidoctor-standoc/refs_dl_spec.rb +13 -1
  30. data/spec/asciidoctor-standoc/refs_spec.rb +12 -12
  31. data/spec/asciidoctor-standoc/section_spec.rb +5 -3
  32. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +47 -47
  33. data/spec/vcr_cassettes/isobib_get_123.yml +11 -11
  34. data/spec/vcr_cassettes/isobib_get_123_1.yml +26 -26
  35. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +36 -36
  36. data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -14
  37. data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
  38. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
  39. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +45 -45
  40. metadata +19 -18
  41. data/lib/asciidoctor/standoc/log.rb +0 -59
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf94c8165f552d893fafcd889f4a87497cf9d3cacf47aa9b1ea840da7d95b1c6
4
- data.tar.gz: 0a7aa11f804bf0cb450252c9183353f11571dddf9f3ca15d279aca27483510ac
3
+ metadata.gz: 28995a48904029f160e1da3411c440ac27e3b4f84405e8fc1f8680214bc79c42
4
+ data.tar.gz: bfce935749b5da318ebfe12c458210db5bc884ce7fa37126de4c3eff0e22e9d4
5
5
  SHA512:
6
- metadata.gz: 89c736fe574b64de2b97a244435f3a851d667d99e952ec6d5ba5e0d4f0c40986cb87958e1ed99d68e6d6bdd6ae89dccdba104855cd12738e0801b8657e3b3adf
7
- data.tar.gz: fb9b3000f186215a782eb1d65114c86108e48742336337ae365320344cc6f0c23e5bbd2a20ab7cfa0534ff55140baa23a21870a0af14e40b3dd8589f02db32d5
6
+ metadata.gz: b3839c128f0b278364e7a91f64529cbe2709c504e52aa82c31d284986b45f8ffc8a55a8c2871a7eee481bdbe8c5bdedb58c7b459b3a5aab0d64d7baf7d46f859
7
+ data.tar.gz: d26bfe3ca6146c2d6d7bf68d3a1112a8afde89f88a9713dbafb40a304f002b76d6e225d5fda3dd71eaa2f6c603cd4a362d1735cc4e83e822f0545efb86665adf
@@ -7,6 +7,7 @@ require "open-uri"
7
7
  require "isodoc"
8
8
  require "relaton"
9
9
  require "fileutils"
10
+ require "metanorma-utils"
10
11
 
11
12
  module Asciidoctor
12
13
  module Standoc
@@ -91,6 +92,7 @@ module Asciidoctor
91
92
  @draft = false
92
93
  @refids = Set.new
93
94
  @anchors = {}
95
+ @internal_eref_namespaces = []
94
96
  @draft = node.attributes.has_key?("draft")
95
97
  @novalid = node.attr("novalid")
96
98
  @smartquotes = node.attr("smartquotes") != "false"
@@ -98,7 +100,7 @@ module Asciidoctor
98
100
  @fontheader = default_fonts(node)
99
101
  @files_to_delete = []
100
102
  @filename = node.attr("docfile") ? File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : ""
101
- @localdir = Utils::localdir(node)
103
+ @localdir = Metanorma::Utils::localdir(node)
102
104
  @output_dir = outputdir node
103
105
  @no_isobib_cache = node.attr("no-isobib-cache")
104
106
  @no_isobib = node.attr("no-isobib")
@@ -106,20 +108,22 @@ module Asciidoctor
106
108
  @seen_headers = []
107
109
  @datauriimage = node.attr("data-uri-image")
108
110
  @boilerplateauthority = node.attr("boilerplate-authority")
109
- @log = Asciidoctor::Standoc::Log.new
111
+ @sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
112
+ @sourcecode_markup_end = node.attr("sourcecode-markup-start") || "}}}"
113
+ @log = Metanorma::Utils::Log.new
110
114
  init_bib_caches(node)
111
115
  init_iev_caches(node)
112
116
  @lang = (node.attr("language") || "en")
113
- @script = (node.attr("script") || "Latn")
117
+ @script = (node.attr("script") || default_script(node.attr("language")))
114
118
  @isodoc = isodoc(@lang, @script, node.attr("i18nyaml"))
115
119
  @i18n = @isodoc.i18n
116
120
  end
117
121
 
118
122
  def default_fonts(node)
119
123
  b = node.attr("body-font") ||
120
- (node.attr("script") == "Hans" ? '"SimSun",serif' : '"Cambria",serif')
124
+ (node.attr("script") == "Hans" ? '"Source Han Sans",serif' : '"Cambria",serif')
121
125
  h = node.attr("header-font") ||
122
- (node.attr("script") == "Hans" ? '"SimHei",sans-serif' : '"Cambria",serif')
126
+ (node.attr("script") == "Hans" ? '"Source Han Sans",sans-serif' : '"Cambria",serif')
123
127
  m = node.attr("monospace-font") || '"Courier New",monospace'
124
128
  "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
125
129
  end
@@ -185,52 +189,35 @@ module Asciidoctor
185
189
  end
186
190
  end
187
191
 
188
- def term_source_attrs(seen_xref)
189
- { bibitemid: seen_xref.children[0]["target"],
190
- format: seen_xref.children[0]["format"], type: "inline" }
191
- end
192
-
193
- def add_term_source(xml_t, seen_xref, m)
194
- if seen_xref.children[0].name == "concept"
195
- xml_t.origin { |o| o << seen_xref.children[0].to_xml }
192
+ def default_script(lang)
193
+ case lang
194
+ when "ar", "fa"
195
+ "Arab"
196
+ when "ur"
197
+ "Aran"
198
+ when "ru", "bg"
199
+ "Cyrl"
200
+ when "hi"
201
+ "Deva"
202
+ when "el"
203
+ "Grek"
204
+ when "zh"
205
+ "Hans"
206
+ when "ko"
207
+ "Kore"
208
+ when "he"
209
+ "Hebr"
210
+ when "ja"
211
+ "Jpan"
196
212
  else
197
- xml_t.origin seen_xref.children[0].content, **attr_code(term_source_attrs(seen_xref))
213
+ "Latn"
198
214
  end
199
- m[:text] && xml_t.modification do |mod|
200
- mod.p { |p| p << m[:text].sub(/^\s+/, "") }
201
- end
202
- end
203
-
204
- TERM_REFERENCE_RE_STR = <<~REGEXP.freeze
205
- ^(?<xref><(xref|concept)[^>]+>([^<]*</(xref|concept)>)?)
206
- (,\s(?<text>.*))?
207
- $
208
- REGEXP
209
- TERM_REFERENCE_RE =
210
- Regexp.new(TERM_REFERENCE_RE_STR.gsub(/\s/, "").gsub(/_/, "\\s"),
211
- Regexp::IGNORECASE | Regexp::MULTILINE)
212
-
213
- def extract_termsource_refs(text, node)
214
- matched = TERM_REFERENCE_RE.match text
215
- matched.nil? and @log.add("AsciiDoc Input", node, "term reference not in expected format: #{text}")
216
- matched
217
- end
218
-
219
- def termsource(node)
220
- matched = extract_termsource_refs(node.content, node) || return
221
- noko do |xml|
222
- attrs = { status: matched[:text] ? "modified" : "identical" }
223
- xml.termsource **attrs do |xml_t|
224
- seen_xref = Nokogiri::XML.fragment(matched[:xref])
225
- add_term_source(xml_t, seen_xref, matched)
226
- end
227
- end.join("\n")
228
215
  end
229
216
 
230
217
  private
231
218
 
232
219
  def outputdir(node)
233
- if node.attr("output_dir").nil_or_empty? then Utils::localdir(node)
220
+ if node.attr("output_dir").nil_or_empty? then Metanorma::Utils::localdir(node)
234
221
  else File.join(node.attr("output_dir"), "")
235
222
  end
236
223
  end
@@ -729,9 +729,11 @@
729
729
  </define>
730
730
  <define name="index">
731
731
  <element name="index">
732
- <attribute name="to">
733
- <data type="IDREF"/>
734
- </attribute>
732
+ <optional>
733
+ <attribute name="to">
734
+ <data type="IDREF"/>
735
+ </attribute>
736
+ </optional>
735
737
  <element name="primary">
736
738
  <oneOrMore>
737
739
  <ref name="PureTextElement"/>
@@ -6,11 +6,11 @@ module Asciidoctor
6
6
  module Standoc
7
7
  module Blocks
8
8
  def id_attr(node = nil)
9
- { id: Utils::anchor_or_uuid(node) }
9
+ { id: Metanorma::Utils::anchor_or_uuid(node) }
10
10
  end
11
11
 
12
12
  def id_unnum_attrs(node)
13
- attr_code( id: Utils::anchor_or_uuid(node),
13
+ attr_code( id: Metanorma::Utils::anchor_or_uuid(node),
14
14
  unnumbered: node.option?("unnumbered") ? "true" : nil,
15
15
  number: node.attr("number"),
16
16
  subsequence: node.attr("subsequence") )
@@ -29,7 +29,7 @@ module Asciidoctor
29
29
  # We append each contained block to its parent
30
30
  def open(node)
31
31
  role = node.role || node.attr("style")
32
- Utils::reqt_subpart(role) and return requirement_subpart(node)
32
+ reqt_subpart(role) and return requirement_subpart(node)
33
33
  result = []
34
34
  node.blocks.each do |b|
35
35
  result << send(b.context, b)
@@ -45,7 +45,7 @@ module Asciidoctor
45
45
  noko do |xml|
46
46
  xml.figure **literal_attrs(node) do |f|
47
47
  figure_title(node, f)
48
- f.pre node.lines.join("\n"), **attr_code(id: Utils::anchor_or_uuid,
48
+ f.pre node.lines.join("\n"), **attr_code(id: Metanorma::Utils::anchor_or_uuid,
49
49
  alt: node.attr("alt"))
50
50
  end
51
51
  end
@@ -121,7 +121,7 @@ module Asciidoctor
121
121
 
122
122
  def para_attrs(node)
123
123
  attr_code(keep_attrs(node).merge(align: node.attr("align"),
124
- id: Utils::anchor_or_uuid(node)))
124
+ id: Metanorma::Utils::anchor_or_uuid(node)))
125
125
  end
126
126
 
127
127
  def paragraph(node)
@@ -135,7 +135,7 @@ module Asciidoctor
135
135
 
136
136
  def quote_attrs(node)
137
137
  attr_code(keep_attrs(node).merge(align: node.attr("align"),
138
- id: Utils::anchor_or_uuid(node)))
138
+ id: Metanorma::Utils::anchor_or_uuid(node)))
139
139
  end
140
140
 
141
141
  def quote_attribution(node, out)
@@ -160,7 +160,7 @@ module Asciidoctor
160
160
 
161
161
  def listing_attrs(node)
162
162
  attr_code(keep_attrs(node).merge(lang: node.attr("language"),
163
- id: Utils::anchor_or_uuid(node),
163
+ id: Metanorma::Utils::anchor_or_uuid(node),
164
164
  unnumbered: node.option?("unnumbered") ? "true" : nil,
165
165
  number: node.attr("number"),
166
166
  filename: node.attr("filename")))
@@ -35,7 +35,7 @@ module Asciidoctor
35
35
  date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "")
36
36
  date += "T00:00:00Z" unless /T/.match date
37
37
  attr_code(
38
- id: Utils::anchor_or_uuid(node),
38
+ id: ::Metanorma::Utils::anchor_or_uuid(node),
39
39
  reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)",
40
40
  date: date )
41
41
  end
@@ -69,7 +69,7 @@ module Asciidoctor
69
69
  a = node.attr("type") and ["danger", "safety precautions"].each do |t|
70
70
  name = t if a.casecmp(t).zero?
71
71
  end
72
- attr_code(keep_attrs(node).merge(id: Utils::anchor_or_uuid(node), type: name,
72
+ attr_code(keep_attrs(node).merge(id: Metanorma::Utils::anchor_or_uuid(node), type: name,
73
73
  beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil))
74
74
  end
75
75
 
@@ -5,6 +5,7 @@ require "html2doc"
5
5
  require_relative "./cleanup_block.rb"
6
6
  require_relative "./cleanup_footnotes.rb"
7
7
  require_relative "./cleanup_ref.rb"
8
+ require_relative "./cleanup_ref_dl.rb"
8
9
  require_relative "./cleanup_boilerplate.rb"
9
10
  require_relative "./cleanup_section.rb"
10
11
  require_relative "./cleanup_terms.rb"
@@ -27,8 +28,7 @@ module Asciidoctor
27
28
  text = text.gsub(%r{<stem type="AsciiMath">(.+?)</stem>}m) do |m|
28
29
  "<amathstem>#{HTMLEntities.new.decode($1)}</amathstem>"
29
30
  end
30
- text = Html2Doc.
31
- asciimath_to_mathml(text, ["<amathstem>", "</amathstem>"])
31
+ text = Html2Doc.asciimath_to_mathml(text, ["<amathstem>", "</amathstem>"])
32
32
  x = Nokogiri::XML(text)
33
33
  x.xpath("//*[local-name() = 'math'][not(parent::stem)]").each do |y|
34
34
  y.wrap("<stem type='MathML'></stem>")
@@ -78,14 +78,14 @@ module Asciidoctor
78
78
  end
79
79
 
80
80
  def smartquotes_cleanup(xmldoc)
81
- xmldoc.xpath("//date").each { |d| Utils::endash_date(d) }
81
+ xmldoc.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
82
82
  xmldoc.traverse do |n|
83
83
  next unless n.text?
84
84
  if @smartquotes
85
85
  /[-'"(<>]|\.\.|\dx/.match(n) or next
86
86
  n.ancestors("pre, tt, sourcecode, bibdata, on, "\
87
87
  "stem, figure[@class = 'pseudocode']").empty? or next
88
- n.replace(Utils::smartformat(n.text))
88
+ n.replace(Metanorma::Utils::smartformat(n.text))
89
89
  else
90
90
  n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'"))#.
91
91
  #gsub(/</, "&lt;").gsub(/>/, "&gt;"))
@@ -160,8 +160,7 @@ module Asciidoctor
160
160
 
161
161
  def mathml_preserve_space(m)
162
162
  m.xpath(".//m:mtext", "m" => MATHML_NS).each do |x|
163
- x.children = x.children.to_xml.gsub(/^\s/, "&#xA0;").
164
- gsub(/\s$/, "&#xA0;")
163
+ x.children = x.children.to_xml.gsub(/^\s/, "&#xA0;").gsub(/\s$/, "&#xA0;")
165
164
  end
166
165
  end
167
166
 
@@ -8,14 +8,14 @@ module Asciidoctor
8
8
  module Cleanup
9
9
  def para_cleanup(xmldoc)
10
10
  ["//p[not(ancestor::bibdata)]", "//ol[not(ancestor::bibdata)]",
11
- "//ul[not(ancestor::bibdata)]",
11
+ "//ul[not(ancestor::bibdata)]", "//quote[not(ancestor::bibdata)]",
12
12
  "//note[not(ancestor::bibitem or ancestor::table or ancestor::bibdata)]"
13
13
  ].each { |w| inject_id(xmldoc, w) }
14
14
  end
15
15
 
16
16
  def inject_id(xmldoc, path)
17
17
  xmldoc.xpath(path).each do |x|
18
- x["id"] ||= Utils::anchor_or_uuid
18
+ x["id"] ||= Metanorma::Utils::anchor_or_uuid
19
19
  end
20
20
  end
21
21
 
@@ -185,7 +185,7 @@ module Asciidoctor
185
185
  def requirement_descriptions(x)
186
186
  x.xpath("//requirement | //recommendation | //permission").each do |r|
187
187
  r.children.each do |e|
188
- unless e.element? && (Utils::reqt_subpart(e.name) ||
188
+ unless e.element? && (reqt_subpart(e.name) ||
189
189
  %w(requirement recommendation permission).include?(e.name))
190
190
  t = Nokogiri::XML::Element.new("description", x)
191
191
  e.before(t)
@@ -106,6 +106,7 @@ module Asciidoctor
106
106
  def bibdata_cleanup(xmldoc)
107
107
  bibdata_anchor_cleanup(xmldoc)
108
108
  bibdata_docidentifier_cleanup(xmldoc)
109
+ biblio_indirect_erefs(xmldoc, @internal_eref_namespaces&.uniq)
109
110
  end
110
111
 
111
112
  def bibdata_anchor_cleanup(xmldoc)
@@ -122,6 +123,61 @@ module Asciidoctor
122
123
  ins = ins.next
123
124
  end
124
125
  end
126
+
127
+ def gather_indirect_erefs(xmldoc, prefix)
128
+ xmldoc.xpath("//eref[@type = '#{prefix}']").each_with_object({}) do |e, m|
129
+ e.delete("type")
130
+ m[e["bibitemid"]] = true
131
+ end.keys
132
+ end
133
+
134
+ def insert_indirect_biblio(xmldoc, refs, prefix)
135
+ ins = xmldoc.at("bibliography") or
136
+ xmldoc.root << "<bibliography/>" and ins = xmldoc.at("bibliography")
137
+ ins = ins.add_child("<references hidden='true' normative='false'/>").first
138
+ refs.each do |x|
139
+ ins << <<~END
140
+ <bibitem id="#{x}" type="internal">
141
+ <docidentifier type="repository">#{x.sub(/^#{prefix}_/, "#{prefix}/")}</docidentifier>
142
+ </bibitem>
143
+ END
144
+ end
145
+ end
146
+
147
+ def indirect_eref_to_xref(e, id)
148
+ loc = e&.at("./localityStack[locality[@type = 'anchor']]")&.remove&.text ||
149
+ e&.at("./locality[@type = 'anchor']")&.remove&.text || id
150
+ e.name = "xref"
151
+ e.delete("bibitemid")
152
+ e.delete("citeas")
153
+ e["target"] = loc
154
+ unless e.document.at("//*[@id = '#{loc}']")
155
+ e.children = %(** Missing target #{loc})
156
+ e["target"] = id
157
+ end
158
+ end
159
+
160
+ def resolve_local_indirect_erefs(xmldoc, refs, prefix)
161
+ refs.each_with_object([]) do |r, m|
162
+ id = r.sub(/^#{prefix}_/, "")
163
+ if xmldoc.at("//*[@id = '#{id}'][@type = '#{prefix}']")
164
+ xmldoc.xpath("//eref[@bibitemid = '#{r}']").each do |e|
165
+ indirect_eref_to_xref(e, id)
166
+ end
167
+ else
168
+ m << r
169
+ end
170
+ end
171
+ end
172
+
173
+ def biblio_indirect_erefs(xmldoc, prefixes)
174
+ prefixes&.each do |prefix|
175
+ refs = gather_indirect_erefs(xmldoc, prefix)
176
+ refs = resolve_local_indirect_erefs(xmldoc, refs, prefix)
177
+ refs.empty? and next
178
+ insert_indirect_biblio(xmldoc, refs, prefix)
179
+ end
180
+ end
125
181
  end
126
182
  end
127
183
  end
@@ -1,3 +1,5 @@
1
+ require "metanorma-utils"
2
+
1
3
  module Asciidoctor
2
4
  module Standoc
3
5
  module Cleanup
@@ -82,6 +84,8 @@ module Asciidoctor
82
84
 
83
85
  def xref_cleanup(xmldoc)
84
86
  xmldoc.xpath("//xref").each do |x|
87
+ /:/.match(x["target"]) and xref_to_internal_eref(x)
88
+ next unless x.name == "xref"
85
89
  if refid? x["target"]
86
90
  x.name = "eref"
87
91
  xref_to_eref(x)
@@ -91,6 +95,18 @@ module Asciidoctor
91
95
  end
92
96
  end
93
97
 
98
+ def xref_to_internal_eref(x)
99
+ a = x["target"].split(":", 3)
100
+ unless a.size < 2 || a[0].empty? || a[1].empty?
101
+ x["target"] = "#{a[0]}_#{a[1]}"
102
+ a.size > 2 and x.children = %{anchor="#{a[2..-1].join("")}",#{x&.children&.text}}
103
+ x["type"] = a[0]
104
+ @internal_eref_namespaces << a[0]
105
+ x.name = "eref"
106
+ xref_to_eref(x)
107
+ end
108
+ end
109
+
94
110
  def quotesource_cleanup(xmldoc)
95
111
  xmldoc.xpath("//quote/source | //terms/source").each do |x|
96
112
  xref_to_eref(x)
@@ -139,29 +155,11 @@ module Asciidoctor
139
155
  extract_localities(x.first_element_child)
140
156
  end
141
157
 
142
- NAMECHAR = "\u0000-\u0022\u0024\u002c\u002f\u003a-\u0040\\u005b-\u005e"\
143
- "\u0060\u007b-\u00b6\u00b8-\u00bf\u00d7\u00f7\u037e\u2000-\u200b"\
144
- "\u200e-\u203e\u2041-\u206f\u2190-\u2bff\u2ff0-\u3000".freeze
145
- #"\ud800-\uf8ff\ufdd0-\ufdef\ufffe-\uffff".freeze
146
- NAMESTARTCHAR = "\\u002d\u002e\u0030-\u0039\u00b7\u0300-\u036f"\
147
- "\u203f-\u2040".freeze
148
-
149
- def to_ncname(s)
150
- start = s[0]
151
- ret1 = %r([#{NAMECHAR}#]).match(start) ? "_" :
152
- (%r([#{NAMESTARTCHAR}#]).match(start) ? "_#{start}" : start)
153
- ret2 = s[1..-1] || ""
154
- ret = (ret1 || "") + ret2.gsub(%r([#{NAMECHAR}#]), "_")
155
- ret
156
- end
157
-
158
- module_function :to_ncname
159
-
160
158
  def to_xreftarget(s)
161
- return to_ncname(s) unless /^[^#]+#.+$/.match(s)
159
+ return Metanorma::Utils::to_ncname(s) unless /^[^#]+#.+$/.match(s)
162
160
  /^(?<pref>[^#]+)#(?<suff>.+)$/ =~ s
163
- pref = pref.gsub(%r([#{NAMECHAR}]), "_")
164
- suff = suff.gsub(%r([#{NAMECHAR}]), "_")
161
+ pref = pref.gsub(%r([#{Metanorma::Utils::NAMECHAR}]), "_")
162
+ suff = suff.gsub(%r([#{Metanorma::Utils::NAMECHAR}]), "_")
165
163
  "#{pref}##{suff}"
166
164
  end
167
165
 
@@ -175,12 +173,11 @@ module Asciidoctor
175
173
 
176
174
  def anchor_cleanup1(x)
177
175
  x.xpath(IDREF).each do |s|
178
- if (ret = to_ncname(s.value)) != (orig = s.value)
176
+ if (ret = Metanorma::Utils::to_ncname(s.value)) != (orig = s.value)
179
177
  s.value = ret
180
178
  output = s.parent.dup
181
179
  output.children.remove
182
- @log.add("Anchors", s.parent, "normalised identifier in #{output} "\
183
- "from #{orig}")
180
+ @log.add("Anchors", s.parent, "normalised identifier in #{output} from #{orig}")
184
181
  end
185
182
  end
186
183
  end
@@ -191,8 +188,7 @@ module Asciidoctor
191
188
  s.value = ret
192
189
  output = s.parent.dup
193
190
  output.children.remove
194
- @log.add("Anchors", s.parent, "normalised identifier in #{output} "\
195
- "from #{orig}")
191
+ @log.add("Anchors", s.parent, "normalised identifier in #{output} from #{orig}")
196
192
  end
197
193
  end
198
194
  end