metanorma-standoc 1.9.2 → 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.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +3 -13
- data/.hound.yml +3 -1
- data/.rubocop.yml +4 -6
- data/lib/asciidoctor/standoc/base.rb +3 -1
- data/lib/asciidoctor/standoc/biblio.rng +1 -0
- data/lib/asciidoctor/standoc/blocks.rb +1 -1
- data/lib/asciidoctor/standoc/cleanup.rb +34 -15
- data/lib/asciidoctor/standoc/cleanup_block.rb +0 -1
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +2 -2
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +0 -1
- data/lib/asciidoctor/standoc/cleanup_inline.rb +117 -77
- data/lib/asciidoctor/standoc/cleanup_maths.rb +0 -1
- data/lib/asciidoctor/standoc/cleanup_ref.rb +7 -0
- data/lib/asciidoctor/standoc/cleanup_section.rb +73 -137
- data/lib/asciidoctor/standoc/cleanup_section_names.rb +75 -0
- data/lib/asciidoctor/standoc/cleanup_terms.rb +19 -18
- data/lib/asciidoctor/standoc/converter.rb +1 -0
- data/lib/asciidoctor/standoc/front.rb +1 -2
- data/lib/asciidoctor/standoc/front_contributor.rb +66 -42
- data/lib/asciidoctor/standoc/inline.rb +45 -34
- data/lib/asciidoctor/standoc/isodoc.rng +66 -10
- data/lib/asciidoctor/standoc/macros.rb +7 -5
- data/lib/asciidoctor/standoc/macros_plantuml.rb +21 -23
- data/lib/asciidoctor/standoc/macros_terms.rb +60 -23
- data/lib/asciidoctor/standoc/section.rb +19 -12
- data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +87 -33
- data/lib/asciidoctor/standoc/terms.rb +1 -1
- data/lib/asciidoctor/standoc/utils.rb +0 -1
- data/lib/asciidoctor/standoc/validate.rb +22 -8
- data/lib/isodoc/html/html_titlepage.html +81 -0
- data/lib/isodoc/html/htmlstyle.css +983 -0
- data/lib/isodoc/html/htmlstyle.scss +714 -0
- data/lib/isodoc/html/scripts.html +71 -0
- data/lib/metanorma/standoc/processor.rb +16 -7
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +3 -3
- data/spec/asciidoctor/base_spec.rb +697 -557
- data/spec/asciidoctor/blocks_spec.rb +6 -8
- data/spec/asciidoctor/cleanup_sections_spec.rb +14 -14
- data/spec/asciidoctor/cleanup_spec.rb +899 -688
- data/spec/asciidoctor/inline_spec.rb +62 -14
- data/spec/asciidoctor/isobib_cache_spec.rb +4 -6
- data/spec/asciidoctor/lists_spec.rb +149 -137
- data/spec/asciidoctor/macros_json2text_spec.rb +1 -1
- data/spec/asciidoctor/macros_plantuml_spec.rb +8 -8
- data/spec/asciidoctor/macros_spec.rb +646 -169
- data/spec/asciidoctor/refs_dl_spec.rb +4 -4
- data/spec/asciidoctor/refs_spec.rb +1527 -1532
- data/spec/asciidoctor/section_spec.rb +58 -22
- data/spec/asciidoctor/table_spec.rb +6 -6
- data/spec/asciidoctor/validate_spec.rb +352 -304
- data/spec/spec_helper.rb +2 -0
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +49 -49
- data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_123_1.yml +27 -27
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +35 -35
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -14
- data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +44 -44
- metadata +12 -11
- data/lib/liquid/custom_blocks/key_iterator.rb +0 -21
- data/lib/liquid/custom_blocks/with_json_nested_context.rb +0 -18
- data/lib/liquid/custom_blocks/with_yaml_nested_context.rb +0 -19
- data/lib/liquid/custom_filters/values.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5a985aefd39dadc19549ad39c23e0849bac873ea5883e50762ca911c8bd3aad
|
4
|
+
data.tar.gz: b7560f906a1e50fc4032f3261a44d1edcb2e691872b3e85d14a0363d7668b575
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 437c04558d97c828a200ca21668a0e74e7e9fe5b5581ab759955f9ada241a0a87ccfddf114b7bd616430107e5869ce785c547715d627a08b87e35a30237b0516
|
7
|
+
data.tar.gz: 11d70602d2bd7733e9daab869ec22e3bf58ff6397378b38734711d46cb8f6e04b25e5b5fbcd3b5cd1e36b8e58a1061c92a87502fab945ea8a8c573205e25b126
|
data/.github/workflows/rake.yml
CHANGED
@@ -4,7 +4,7 @@ name: rake
|
|
4
4
|
|
5
5
|
on:
|
6
6
|
push:
|
7
|
-
branches: [ master, main
|
7
|
+
branches: [ master, main ]
|
8
8
|
tags: [ v* ]
|
9
9
|
pull_request:
|
10
10
|
|
@@ -16,19 +16,9 @@ jobs:
|
|
16
16
|
strategy:
|
17
17
|
fail-fast: false
|
18
18
|
matrix:
|
19
|
-
ruby: [ '
|
19
|
+
ruby: [ '3.0', '2.7', '2.6', '2.5' ]
|
20
20
|
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
21
|
experimental: [ false ]
|
22
|
-
include:
|
23
|
-
- ruby: '3.0'
|
24
|
-
os: 'ubuntu-latest'
|
25
|
-
experimental: true
|
26
|
-
- ruby: '3.0'
|
27
|
-
os: 'windows-latest'
|
28
|
-
experimental: true
|
29
|
-
- ruby: '3.0'
|
30
|
-
os: 'macos-latest'
|
31
|
-
experimental: true
|
32
22
|
steps:
|
33
23
|
- uses: actions/checkout@master
|
34
24
|
|
@@ -49,5 +39,5 @@ jobs:
|
|
49
39
|
with:
|
50
40
|
token: ${{ secrets.METANORMA_CI_PAT_TOKEN || secrets.GITHUB_TOKEN }}
|
51
41
|
repository: ${{ github.repository }}
|
52
|
-
event-type:
|
42
|
+
event-type: tests-passed
|
53
43
|
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
|
data/.hound.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
#
|
2
|
-
# https://github.com/
|
3
|
-
# All project-specific additions and overrides should be specified in this file.
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
4
3
|
inherit_from:
|
5
4
|
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
6
5
|
|
7
6
|
# local repo-specific modifications
|
7
|
+
# ...
|
8
8
|
|
9
9
|
AllCops:
|
10
|
-
|
11
|
-
StyleGuideCopsOnly: false
|
12
|
-
TargetRubyVersion: 2.4
|
10
|
+
TargetRubyVersion: 2.5
|
@@ -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"
|
@@ -48,11 +47,13 @@ module Asciidoctor
|
|
48
47
|
htmlcoverpage: node.attr("htmlcoverpage"),
|
49
48
|
htmlintropage: node.attr("htmlintropage"),
|
50
49
|
scripts: node.attr("scripts"),
|
50
|
+
scripts_override: node.attr("scripts-override"),
|
51
51
|
scripts_pdf: node.attr("scripts-pdf"),
|
52
52
|
datauriimage: node.attr("data-uri-image"),
|
53
53
|
htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
|
54
54
|
doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
|
55
55
|
break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
|
56
|
+
bare: node.attr("bare"),
|
56
57
|
sectionsplit: node.attr("sectionsplit"),
|
57
58
|
}
|
58
59
|
end
|
@@ -80,6 +81,7 @@ module Asciidoctor
|
|
80
81
|
htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
|
81
82
|
doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
|
82
83
|
break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
|
84
|
+
bare: node.attr("bare"),
|
83
85
|
}
|
84
86
|
|
85
87
|
if font_manifest_file = node.attr("mn2pdf-font-manifest-file")
|
@@ -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)
|
@@ -72,24 +71,39 @@ module Asciidoctor
|
|
72
71
|
xmldoc
|
73
72
|
end
|
74
73
|
|
74
|
+
IGNORE_DUMBQUOTES = "//pre | //pre//* | //tt | //tt//* | "\
|
75
|
+
"//sourcecode | //sourcecode//* | //bibdata//* | //stem | "\
|
76
|
+
"//stem//* | //figure[@class = 'pseudocode'] | "\
|
77
|
+
"//figure[@class = 'pseudocode']//*".freeze
|
78
|
+
|
75
79
|
def smartquotes_cleanup(xmldoc)
|
76
80
|
xmldoc.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
|
77
|
-
|
78
|
-
|
81
|
+
if @smartquotes then smartquotes_cleanup1(xmldoc)
|
82
|
+
else dumbquote_cleanup(xmldoc)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def smartquotes_cleanup1(xmldoc)
|
87
|
+
(xmldoc.xpath("//*[child::text()]") - xmldoc.xpath(IGNORE_DUMBQUOTES))
|
88
|
+
.each do |x|
|
89
|
+
x.children.each do |n|
|
90
|
+
next unless n.text?
|
79
91
|
|
80
|
-
if @smartquotes
|
81
92
|
/[-'"(<>]|\.\.|\dx/.match(n) or next
|
82
93
|
|
83
|
-
n.ancestors("pre, tt, sourcecode, bibdata, on, "\
|
84
|
-
"stem, figure[@class = 'pseudocode']").empty? or next
|
85
94
|
n.replace(Metanorma::Utils::smartformat(n.text))
|
86
|
-
else
|
87
|
-
n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'")) # .
|
88
|
-
# gsub(/</, "<").gsub(/>/, ">"))
|
89
95
|
end
|
90
96
|
end
|
91
97
|
end
|
92
98
|
|
99
|
+
def dumbquote_cleanup(xmldoc)
|
100
|
+
xmldoc.traverse do |n|
|
101
|
+
next unless n.text?
|
102
|
+
|
103
|
+
n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'")) # .
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
93
107
|
def docidentifier_cleanup(xmldoc); end
|
94
108
|
|
95
109
|
TEXT_ELEMS =
|
@@ -125,11 +139,7 @@ module Asciidoctor
|
|
125
139
|
end
|
126
140
|
|
127
141
|
def variant_cleanup(xmldoc)
|
128
|
-
xmldoc
|
129
|
-
c&.next&.text? && c&.next&.next&.name == "variant" &&
|
130
|
-
c.next.text.gsub(/\s/, "").empty? and
|
131
|
-
c.next.remove
|
132
|
-
end
|
142
|
+
variant_space_cleanup(xmldoc)
|
133
143
|
xmldoc.xpath("//*[variant]").each do |c|
|
134
144
|
next unless c.children.any? do |n|
|
135
145
|
n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?)
|
@@ -147,6 +157,15 @@ module Asciidoctor
|
|
147
157
|
end
|
148
158
|
xmldoc.xpath("//variantwrap").each { |n| n.name = "variant" }
|
149
159
|
end
|
160
|
+
|
161
|
+
def variant_space_cleanup(xmldoc)
|
162
|
+
xmldoc.xpath("//*[variant]").each do |c|
|
163
|
+
if c&.next&.text? && c&.next&.next&.name == "variant"
|
164
|
+
c.next.text.gsub(/\s/, "").empty? and
|
165
|
+
c.next.remove
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
150
169
|
end
|
151
170
|
end
|
152
171
|
end
|
@@ -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 << <<~
|
161
|
+
ins << <<~BIB
|
162
162
|
<bibitem id="#{x}" type="internal">
|
163
163
|
<docidentifier type="repository">#{x.sub(/^#{prefix}_/, "#{prefix}/")}</docidentifier>
|
164
164
|
</bibitem>
|
165
|
-
|
165
|
+
BIB
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -3,32 +3,54 @@ require "metanorma-utils"
|
|
3
3
|
module Asciidoctor
|
4
4
|
module Standoc
|
5
5
|
module Cleanup
|
6
|
-
def empty_text_before_first_element(
|
7
|
-
|
8
|
-
return false if c.text?
|
6
|
+
def empty_text_before_first_element(elem)
|
7
|
+
elem.children.each do |c|
|
8
|
+
return false if c.text? && /\S/.match(c.text)
|
9
9
|
return true if c.element?
|
10
10
|
end
|
11
11
|
true
|
12
12
|
end
|
13
13
|
|
14
|
-
def strip_initial_space(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
def strip_initial_space(elem)
|
15
|
+
return unless elem.children[0].text?
|
16
|
+
|
17
|
+
if /\S/.match?(elem.children[0].text)
|
18
|
+
elem.children[0].content = elem.children[0].text.gsub(/^ /, "")
|
19
|
+
else
|
20
|
+
elem.children[0].remove
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
def bookmark_cleanup(xmldoc)
|
25
|
+
li_bookmark_cleanup(xmldoc)
|
26
|
+
dt_bookmark_cleanup(xmldoc)
|
27
|
+
end
|
28
|
+
|
29
|
+
def bookmark_to_id(elem, bookmark)
|
30
|
+
parent = bookmark.parent
|
31
|
+
elem["id"] = bookmark.remove["id"]
|
32
|
+
strip_initial_space(parent)
|
33
|
+
end
|
34
|
+
|
35
|
+
def li_bookmark_cleanup(xmldoc)
|
25
36
|
xmldoc.xpath("//li[descendant::bookmark]").each do |x|
|
26
|
-
if x
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
37
|
+
if x.at("./*[1][local-name() = 'p']/"\
|
38
|
+
"*[1][local-name() = 'bookmark']") &&
|
39
|
+
empty_text_before_first_element(x.elements[0])
|
40
|
+
bookmark_to_id(x, x.elements[0].elements[0])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def dt_bookmark_cleanup(xmldoc)
|
46
|
+
xmldoc.xpath("//dt[descendant::bookmark]").each do |x|
|
47
|
+
if x.at("./*[1][local-name() = 'p']/"\
|
48
|
+
"*[1][local-name() = 'bookmark']") &&
|
49
|
+
empty_text_before_first_element(x.elements[0])
|
50
|
+
bookmark_to_id(x, x.elements[0].elements[0])
|
51
|
+
elsif x.at("./*[1][local-name() = 'bookmark']") &&
|
52
|
+
empty_text_before_first_element(x)
|
53
|
+
bookmark_to_id(x, x.elements[0])
|
32
54
|
end
|
33
55
|
end
|
34
56
|
end
|
@@ -46,65 +68,67 @@ module Asciidoctor
|
|
46
68
|
LOCALITY_RE = Regexp.new(LOCALITY_REGEX_STR.gsub(/\s/, ""),
|
47
69
|
Regexp::IGNORECASE | Regexp::MULTILINE)
|
48
70
|
|
49
|
-
def tq(
|
50
|
-
|
71
|
+
def tq(text)
|
72
|
+
text.sub(/^"/, "").sub(/"$/, "")
|
51
73
|
end
|
52
74
|
|
53
|
-
def extract_localities(
|
54
|
-
f =
|
75
|
+
def extract_localities(elem)
|
76
|
+
f = elem&.children&.first or return
|
55
77
|
f.text? or return
|
56
78
|
head = f.remove.text
|
57
|
-
tail =
|
58
|
-
extract_localities1(
|
59
|
-
tail and
|
79
|
+
tail = elem&.children&.remove
|
80
|
+
extract_localities1(elem, head)
|
81
|
+
tail and elem << tail
|
60
82
|
end
|
61
83
|
|
62
|
-
def extract_localities1(
|
63
|
-
b =
|
84
|
+
def extract_localities1(elem, text)
|
85
|
+
b = elem.add_child("<localityStack/>").first if LOCALITY_RE.match text
|
64
86
|
while (m = LOCALITY_RE.match text)
|
65
87
|
ref = m[:ref] ? "<referenceFrom>#{tq m[:ref]}</referenceFrom>" : ""
|
66
88
|
refto = m[:to] ? "<referenceTo>#{tq m[:to]}</referenceTo>" : ""
|
67
89
|
loc = m[:locality]&.downcase || m[:locality2]&.downcase
|
68
90
|
b.add_child("<locality type='#{loc}'>#{ref}#{refto}</locality>")
|
69
91
|
text = m[:text]
|
70
|
-
b =
|
92
|
+
b = elem.add_child("<localityStack/>").first if m[:punct] == ";"
|
71
93
|
end
|
72
|
-
|
94
|
+
elem.add_child(text) if text
|
73
95
|
end
|
74
96
|
|
75
|
-
def xref_to_eref(
|
76
|
-
|
77
|
-
unless
|
78
|
-
@internal_eref_namespaces.include?(
|
79
|
-
|
80
|
-
|
97
|
+
def xref_to_eref(elem)
|
98
|
+
elem["bibitemid"] = elem["target"]
|
99
|
+
unless elem["citeas"] = @anchors&.dig(elem["target"], :xref)
|
100
|
+
@internal_eref_namespaces.include?(elem["type"]) or
|
101
|
+
@log.add("Crossreferences", elem,
|
102
|
+
"#{elem['target']} does not have a corresponding "\
|
103
|
+
"anchor ID in the bibliography!")
|
81
104
|
end
|
82
|
-
|
83
|
-
extract_localities(
|
105
|
+
elem.delete("target")
|
106
|
+
extract_localities(elem) unless elem.children.empty?
|
84
107
|
end
|
85
108
|
|
86
109
|
def xref_cleanup(xmldoc)
|
87
110
|
xmldoc.xpath("//xref").each do |x|
|
88
111
|
/:/.match(x["target"]) and xref_to_internal_eref(x)
|
89
112
|
next unless x.name == "xref"
|
113
|
+
|
90
114
|
if refid? x["target"]
|
91
115
|
x.name = "eref"
|
92
116
|
xref_to_eref(x)
|
93
|
-
else
|
94
|
-
x.delete("type")
|
117
|
+
else x.delete("type")
|
95
118
|
end
|
96
119
|
end
|
97
120
|
end
|
98
121
|
|
99
|
-
def xref_to_internal_eref(
|
100
|
-
a =
|
101
|
-
unless
|
102
|
-
|
103
|
-
a.size > 2 and
|
104
|
-
|
122
|
+
def xref_to_internal_eref(elem)
|
123
|
+
a = elem["target"].split(":", 3)
|
124
|
+
unless a.size < 2 || a[0].empty? || a[1].empty?
|
125
|
+
elem["target"] = "#{a[0]}_#{a[1]}"
|
126
|
+
a.size > 2 and
|
127
|
+
elem.children = %{anchor="#{a[2..-1].join}",#{elem&.children&.text}}
|
128
|
+
elem["type"] = a[0]
|
105
129
|
@internal_eref_namespaces << a[0]
|
106
|
-
|
107
|
-
xref_to_eref(
|
130
|
+
elem.name = "eref"
|
131
|
+
xref_to_eref(elem)
|
108
132
|
end
|
109
133
|
end
|
110
134
|
|
@@ -116,10 +140,11 @@ module Asciidoctor
|
|
116
140
|
|
117
141
|
def origin_cleanup(xmldoc)
|
118
142
|
xmldoc.xpath("//origin/concept[termref]").each do |x|
|
119
|
-
x.
|
143
|
+
t = x.at("./termref")
|
144
|
+
x.replace(t)
|
120
145
|
end
|
121
146
|
xmldoc.xpath("//origin").each do |x|
|
122
|
-
x["citeas"] = @anchors&.dig(x["bibitemid"], :xref)
|
147
|
+
x["citeas"] = @anchors&.dig(x["bibitemid"], :xref) or
|
123
148
|
@log.add("Crossreferences", x,
|
124
149
|
"#{x['bibitemid']} does not have a corresponding anchor "\
|
125
150
|
"ID in the bibliography!")
|
@@ -128,68 +153,83 @@ module Asciidoctor
|
|
128
153
|
end
|
129
154
|
|
130
155
|
def concept_cleanup(xmldoc)
|
131
|
-
xmldoc.xpath("//concept").each do |x|
|
132
|
-
x.
|
133
|
-
if
|
156
|
+
xmldoc.xpath("//concept[not(termxref)]").each do |x|
|
157
|
+
term = x.at("./refterm")
|
158
|
+
term&.remove if term&.text&.empty?
|
159
|
+
x.children.remove if x&.children&.text&.strip&.empty?
|
160
|
+
key_extract_locality(x)
|
161
|
+
if /:/.match?(x["key"]) then concept_termbase_cleanup(x)
|
134
162
|
elsif refid? x["key"] then concept_eref_cleanup(x)
|
135
|
-
else
|
136
|
-
concept_xref_cleanup(x)
|
163
|
+
else concept_xref_cleanup(x)
|
137
164
|
end
|
138
165
|
x.delete("key")
|
139
166
|
end
|
140
167
|
end
|
141
168
|
|
142
|
-
def
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
169
|
+
def key_extract_locality(elem)
|
170
|
+
return unless /,/.match?(elem["key"])
|
171
|
+
|
172
|
+
elem.add_child("<locality>#{elem['key'].sub(/^[^,]+,/, '')}</locality>")
|
173
|
+
elem["key"] = elem["key"].sub(/,.*$/, "")
|
174
|
+
end
|
175
|
+
|
176
|
+
def concept_termbase_cleanup(elem)
|
177
|
+
t = elem&.at("./xrefrender")&.remove&.children
|
178
|
+
termbase, key = elem["key"].split(/:/, 2)
|
179
|
+
elem.add_child(%(<termref base="#{termbase}" target="#{key}">) +
|
180
|
+
"#{t&.to_xml}</termref>")
|
147
181
|
end
|
148
182
|
|
149
|
-
def concept_xref_cleanup(
|
150
|
-
|
151
|
-
|
183
|
+
def concept_xref_cleanup(elem)
|
184
|
+
t = elem&.at("./xrefrender")&.remove&.children
|
185
|
+
elem.add_child(%(<xref target="#{elem['key']}">#{t&.to_xml}</xref>))
|
152
186
|
end
|
153
187
|
|
154
|
-
def concept_eref_cleanup(
|
155
|
-
|
156
|
-
|
188
|
+
def concept_eref_cleanup(elem)
|
189
|
+
t = elem&.at("./xrefrender")&.remove&.children&.to_xml
|
190
|
+
l = elem&.at("./locality")&.remove&.children&.to_xml
|
191
|
+
elem.add_child "<eref bibitemid='#{elem['key']}'>#{l}</eref>"
|
192
|
+
extract_localities(elem.elements[-1])
|
193
|
+
elem.elements[-1].add_child(t) if t
|
157
194
|
end
|
158
195
|
|
159
|
-
def to_xreftarget(
|
160
|
-
return Metanorma::Utils::to_ncname(
|
161
|
-
|
162
|
-
pref
|
163
|
-
|
196
|
+
def to_xreftarget(str)
|
197
|
+
return Metanorma::Utils::to_ncname(str) unless /^[^#]+#.+$/.match?(str)
|
198
|
+
|
199
|
+
/^(?<pref>[^#]+)#(?<suff>.+)$/ =~ str
|
200
|
+
pref = pref.gsub(%r([#{Metanorma::Utils::NAMECHAR}])o, "_")
|
201
|
+
suff = suff.gsub(%r([#{Metanorma::Utils::NAMECHAR}])o, "_")
|
164
202
|
"#{pref}##{suff}"
|
165
203
|
end
|
166
204
|
|
167
205
|
IDREF = "//*/@id | //review/@from | //review/@to | "\
|
168
206
|
"//callout/@target | //citation/@bibitemid | //eref/@bibitemid".freeze
|
169
207
|
|
170
|
-
def anchor_cleanup(
|
171
|
-
anchor_cleanup1(
|
172
|
-
xreftarget_cleanup(
|
208
|
+
def anchor_cleanup(elem)
|
209
|
+
anchor_cleanup1(elem)
|
210
|
+
xreftarget_cleanup(elem)
|
173
211
|
end
|
174
212
|
|
175
|
-
def anchor_cleanup1(
|
176
|
-
|
213
|
+
def anchor_cleanup1(elem)
|
214
|
+
elem.xpath(IDREF).each do |s|
|
177
215
|
if (ret = Metanorma::Utils::to_ncname(s.value)) != (orig = s.value)
|
178
216
|
s.value = ret
|
179
217
|
output = s.parent.dup
|
180
218
|
output.children.remove
|
181
|
-
@log.add("Anchors", s.parent,
|
219
|
+
@log.add("Anchors", s.parent,
|
220
|
+
"normalised identifier in #{output} from #{orig}")
|
182
221
|
end
|
183
222
|
end
|
184
223
|
end
|
185
224
|
|
186
|
-
def xreftarget_cleanup(
|
187
|
-
|
225
|
+
def xreftarget_cleanup(elem)
|
226
|
+
elem.xpath("//xref/@target").each do |s|
|
188
227
|
if (ret = to_xreftarget(s.value)) != (orig = s.value)
|
189
228
|
s.value = ret
|
190
229
|
output = s.parent.dup
|
191
230
|
output.children.remove
|
192
|
-
@log.add("Anchors", s.parent,
|
231
|
+
@log.add("Anchors", s.parent,
|
232
|
+
"normalised identifier in #{output} from #{orig}")
|
193
233
|
end
|
194
234
|
end
|
195
235
|
end
|