metanorma-standoc 1.6.5 → 1.8.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 +17 -0
- data/lib/asciidoctor/standoc/base.rb +31 -44
- data/lib/asciidoctor/standoc/basicdoc.rng +20 -3
- data/lib/asciidoctor/standoc/blocks.rb +7 -7
- data/lib/asciidoctor/standoc/blocks_notes.rb +2 -2
- data/lib/asciidoctor/standoc/cleanup.rb +5 -6
- data/lib/asciidoctor/standoc/cleanup_block.rb +3 -11
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +89 -20
- data/lib/asciidoctor/standoc/cleanup_inline.rb +23 -25
- data/lib/asciidoctor/standoc/cleanup_ref.rb +0 -85
- data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +94 -0
- data/lib/asciidoctor/standoc/cleanup_terms.rb +1 -6
- data/lib/asciidoctor/standoc/converter.rb +2 -51
- data/lib/asciidoctor/standoc/front.rb +2 -2
- data/lib/asciidoctor/standoc/front_contributor.rb +8 -4
- data/lib/asciidoctor/standoc/inline.rb +8 -6
- data/lib/asciidoctor/standoc/isodoc.rng +36 -3
- data/lib/asciidoctor/standoc/lists.rb +2 -2
- data/lib/asciidoctor/standoc/macros.rb +14 -1
- data/lib/asciidoctor/standoc/macros_plantuml.rb +1 -1
- data/lib/asciidoctor/standoc/ref_sect.rb +2 -2
- data/lib/asciidoctor/standoc/reqt.rb +6 -1
- data/lib/asciidoctor/standoc/section.rb +14 -89
- data/lib/asciidoctor/standoc/table.rb +1 -1
- data/lib/asciidoctor/standoc/terms.rb +125 -0
- data/lib/asciidoctor/standoc/utils.rb +2 -94
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +2 -3
- data/spec/asciidoctor-standoc/base_spec.rb +44 -9
- data/spec/asciidoctor-standoc/blocks_spec.rb +6 -1
- data/spec/asciidoctor-standoc/cleanup_sections_spec.rb +12 -7
- data/spec/asciidoctor-standoc/cleanup_spec.rb +116 -4
- data/spec/asciidoctor-standoc/inline_spec.rb +4 -5
- data/spec/asciidoctor-standoc/isobib_cache_spec.rb +4 -4
- data/spec/asciidoctor-standoc/macros_lutaml_spec.rb +1 -1
- data/spec/asciidoctor-standoc/macros_spec.rb +30 -0
- data/spec/asciidoctor-standoc/refs_dl_spec.rb +17 -5
- data/spec/asciidoctor-standoc/refs_spec.rb +12 -12
- data/spec/asciidoctor-standoc/section_spec.rb +149 -4
- data/spec/asciidoctor-standoc/table_spec.rb +60 -0
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +48 -48
- data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_123_1.yml +26 -26
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +36 -36
- 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 +8 -8
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +65 -59
- metadata +18 -31
- data/lib/asciidoctor/standoc/log.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28995a48904029f160e1da3411c440ac27e3b4f84405e8fc1f8680214bc79c42
|
4
|
+
data.tar.gz: bfce935749b5da318ebfe12c458210db5bc884ce7fa37126de4c3eff0e22e9d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3839c128f0b278364e7a91f64529cbe2709c504e52aa82c31d284986b45f8ffc8a55a8c2871a7eee481bdbe8c5bdedb58c7b459b3a5aab0d64d7baf7d46f859
|
7
|
+
data.tar.gz: d26bfe3ca6146c2d6d7bf68d3a1112a8afde89f88a9713dbafb40a304f002b76d6e225d5fda3dd71eaa2f6c603cd4a362d1735cc4e83e822f0545efb86665adf
|
data/.github/workflows/rake.yml
CHANGED
@@ -36,6 +36,9 @@ jobs:
|
|
36
36
|
with:
|
37
37
|
ruby-version: ${{ matrix.ruby }}
|
38
38
|
|
39
|
+
- if: matrix.os == 'macos-latest'
|
40
|
+
run: brew install autoconf automake libtool
|
41
|
+
|
39
42
|
- uses: actions/cache@v2
|
40
43
|
with:
|
41
44
|
path: vendor/bundle
|
@@ -64,3 +67,17 @@ jobs:
|
|
64
67
|
run: cinst -y plantuml
|
65
68
|
|
66
69
|
- run: bundle exec rake
|
70
|
+
|
71
|
+
tests-passed:
|
72
|
+
needs: rake
|
73
|
+
runs-on: ubuntu-latest
|
74
|
+
continue-on-error: true
|
75
|
+
steps:
|
76
|
+
- name: Trigger tests passed event
|
77
|
+
uses: Sibz/github-status-action@v1
|
78
|
+
with:
|
79
|
+
authToken: ${{ secrets.METANORMA_CI_PAT_TOKEN || secrets.GITHUB_TOKEN }}
|
80
|
+
context: 'tests-passed-successfully'
|
81
|
+
description: 'Tests passed successfully'
|
82
|
+
state: 'success'
|
83
|
+
sha: ${{ github.event.pull_request.head.sha || github.sha }}
|
@@ -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
|
-
@
|
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") || "
|
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" ? '"
|
124
|
+
(node.attr("script") == "Hans" ? '"Source Han Sans",serif' : '"Cambria",serif')
|
121
125
|
h = node.attr("header-font") ||
|
122
|
-
(node.attr("script") == "Hans" ? '"
|
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
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
-
|
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,12 +729,29 @@
|
|
729
729
|
</define>
|
730
730
|
<define name="index">
|
731
731
|
<element name="index">
|
732
|
-
<attribute name="primary"/>
|
733
732
|
<optional>
|
734
|
-
<attribute name="
|
733
|
+
<attribute name="to">
|
734
|
+
<data type="IDREF"/>
|
735
|
+
</attribute>
|
736
|
+
</optional>
|
737
|
+
<element name="primary">
|
738
|
+
<oneOrMore>
|
739
|
+
<ref name="PureTextElement"/>
|
740
|
+
</oneOrMore>
|
741
|
+
</element>
|
742
|
+
<optional>
|
743
|
+
<element name="secondary">
|
744
|
+
<oneOrMore>
|
745
|
+
<ref name="PureTextElement"/>
|
746
|
+
</oneOrMore>
|
747
|
+
</element>
|
735
748
|
</optional>
|
736
749
|
<optional>
|
737
|
-
<
|
750
|
+
<element name="tertiary">
|
751
|
+
<oneOrMore>
|
752
|
+
<ref name="PureTextElement"/>
|
753
|
+
</oneOrMore>
|
754
|
+
</element>
|
738
755
|
</optional>
|
739
756
|
</element>
|
740
757
|
</define>
|
@@ -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
|
-
|
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(/</, "<").gsub(/>/, ">"))
|
@@ -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/, " ").
|
164
|
-
gsub(/\s$/, " ")
|
163
|
+
x.children = x.children.to_xml.gsub(/^\s/, " ").gsub(/\s$/, " ")
|
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
|
|
@@ -133,14 +133,6 @@ module Asciidoctor
|
|
133
133
|
end
|
134
134
|
|
135
135
|
# examples containing only figures become subfigures of figures
|
136
|
-
def subfigure_cleanup(xmldoc)
|
137
|
-
nodes = xmldoc.xpath("//example/figure")
|
138
|
-
while !nodes.empty?
|
139
|
-
nodes[0].parent.name = "figure"
|
140
|
-
nodes = xmldoc.xpath("//example/figure")
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
136
|
def subfigure_cleanup(xmldoc)
|
145
137
|
xmldoc.xpath("//example[figure]").each do |e|
|
146
138
|
next unless e.elements.map { |m| m.name }.
|
@@ -193,7 +185,7 @@ module Asciidoctor
|
|
193
185
|
def requirement_descriptions(x)
|
194
186
|
x.xpath("//requirement | //recommendation | //permission").each do |r|
|
195
187
|
r.children.each do |e|
|
196
|
-
unless e.element? && (
|
188
|
+
unless e.element? && (reqt_subpart(e.name) ||
|
197
189
|
%w(requirement recommendation permission).include?(e.name))
|
198
190
|
t = Nokogiri::XML::Element.new("description", x)
|
199
191
|
e.before(t)
|
@@ -3,14 +3,12 @@ module Asciidoctor
|
|
3
3
|
module Cleanup
|
4
4
|
def external_terms_boilerplate(sources)
|
5
5
|
@i18n.l10n(
|
6
|
-
@i18n.external_terms_boilerplate.gsub(/%/, sources || "???"),
|
7
|
-
@lang, @script)
|
6
|
+
@i18n.external_terms_boilerplate.gsub(/%/, sources || "???"), @lang, @script)
|
8
7
|
end
|
9
8
|
|
10
9
|
def internal_external_terms_boilerplate(sources)
|
11
10
|
@i18n.l10n(
|
12
|
-
@i18n.internal_external_terms_boilerplate.gsub(/%/, sources || "??"),
|
13
|
-
@lang, @script)
|
11
|
+
@i18n.internal_external_terms_boilerplate.gsub(/%/, sources || "??"), @lang, @script)
|
14
12
|
end
|
15
13
|
|
16
14
|
def term_defs_boilerplate(div, source, term, preface, isodoc)
|
@@ -19,11 +17,9 @@ module Asciidoctor
|
|
19
17
|
@anchors[s["bibitemid"]] or
|
20
18
|
@log.add("Crossreferences", nil, "term source #{s['bibitemid']} not referenced")
|
21
19
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
div.next = term_defs_boilerplate_cont(source, term, isodoc)
|
26
|
-
end
|
20
|
+
a = (source.empty? && term.nil?) ? @i18n.no_terms_boilerplate :
|
21
|
+
term_defs_boilerplate_cont(source, term, isodoc)
|
22
|
+
a and div.next = a
|
27
23
|
end
|
28
24
|
|
29
25
|
def term_defs_boilerplate_cont(src, term, isodoc)
|
@@ -38,15 +34,14 @@ module Asciidoctor
|
|
38
34
|
end
|
39
35
|
|
40
36
|
def norm_ref_preface(f)
|
41
|
-
|
42
|
-
|
37
|
+
refs = f.elements.select do |e|
|
38
|
+
["reference", "bibitem"].include? e.name
|
39
|
+
end
|
40
|
+
f.at("./title").next =
|
41
|
+
"<p>#{(refs.empty? ? @i18n.norm_empty_pref : @i18n.norm_with_refs_pref)}</p>"
|
43
42
|
end
|
44
|
-
f.at("./title").next =
|
45
|
-
"<p>#{(refs.empty? ? @i18n.norm_empty_pref : @i18n.norm_with_refs_pref)}</p>"
|
46
|
-
end
|
47
43
|
|
48
|
-
TERM_CLAUSE = "//sections/terms | "
|
49
|
-
"//sections/clause[descendant::terms]".freeze
|
44
|
+
TERM_CLAUSE = "//sections/terms | //sections/clause[descendant::terms]".freeze
|
50
45
|
|
51
46
|
NORM_REF = "//bibliography/references[@normative = 'true']".freeze
|
52
47
|
|
@@ -59,15 +54,33 @@ module Asciidoctor
|
|
59
54
|
@isodoc
|
60
55
|
end
|
61
56
|
|
57
|
+
def termdef_boilerplate_cleanup(xmldoc)
|
58
|
+
#termdef_remove_initial_paras(xmldoc)
|
59
|
+
end
|
60
|
+
|
61
|
+
def termdef_remove_initial_paras(xmldoc)
|
62
|
+
xmldoc.xpath("//terms/p | //terms/ul").each(&:remove)
|
63
|
+
end
|
64
|
+
|
65
|
+
def termdef_unwrap_boilerplate_clauses(xmldoc)
|
66
|
+
xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
|
67
|
+
f.xpath(".//clause[@type = 'boilerplate']").each do |c|
|
68
|
+
c&.at("./title")&.remove
|
69
|
+
c.replace(c.children)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
62
74
|
def boilerplate_cleanup(xmldoc)
|
63
75
|
isodoc = boilerplate_isodoc(xmldoc)
|
76
|
+
termdef_boilerplate_cleanup(xmldoc)
|
64
77
|
xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
|
65
|
-
|
66
|
-
|
78
|
+
next if f.at("./clause[@type = 'boilerplate']")
|
79
|
+
term_defs_boilerplate(f.at("./title"), xmldoc.xpath(".//termdocsource"),
|
67
80
|
f.at(".//term"), f.at(".//p"), isodoc)
|
68
81
|
end
|
69
|
-
|
70
|
-
|
82
|
+
termdef_unwrap_boilerplate_clauses(xmldoc)
|
83
|
+
f = xmldoc.at(self.class::NORM_REF) and norm_ref_preface(f)
|
71
84
|
initial_boilerplate(xmldoc, isodoc)
|
72
85
|
end
|
73
86
|
|
@@ -93,6 +106,7 @@ module Asciidoctor
|
|
93
106
|
def bibdata_cleanup(xmldoc)
|
94
107
|
bibdata_anchor_cleanup(xmldoc)
|
95
108
|
bibdata_docidentifier_cleanup(xmldoc)
|
109
|
+
biblio_indirect_erefs(xmldoc, @internal_eref_namespaces&.uniq)
|
96
110
|
end
|
97
111
|
|
98
112
|
def bibdata_anchor_cleanup(xmldoc)
|
@@ -109,6 +123,61 @@ module Asciidoctor
|
|
109
123
|
ins = ins.next
|
110
124
|
end
|
111
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
|
112
181
|
end
|
113
182
|
end
|
114
183
|
end
|