metanorma-standoc 1.6.1 → 1.7.0
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 +66 -0
- data/README.adoc +1 -3
- data/lib/asciidoctor/standoc/base.rb +8 -16
- data/lib/asciidoctor/standoc/basicdoc.rng +50 -3
- data/lib/asciidoctor/standoc/cleanup.rb +52 -4
- data/lib/asciidoctor/standoc/cleanup_block.rb +41 -4
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +47 -20
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +14 -0
- data/lib/asciidoctor/standoc/cleanup_inline.rb +9 -3
- data/lib/asciidoctor/standoc/cleanup_ref.rb +17 -24
- data/lib/asciidoctor/standoc/cleanup_terms.rb +4 -6
- data/lib/asciidoctor/standoc/converter.rb +71 -1
- data/lib/asciidoctor/standoc/front.rb +6 -0
- data/lib/asciidoctor/standoc/front_contributor.rb +8 -4
- data/lib/asciidoctor/standoc/inline.rb +6 -5
- data/lib/asciidoctor/standoc/isodoc.rng +36 -43
- data/lib/asciidoctor/standoc/lists.rb +4 -2
- data/lib/asciidoctor/standoc/macros.rb +55 -59
- data/lib/asciidoctor/standoc/macros_terms.rb +82 -0
- data/lib/asciidoctor/standoc/ref.rb +19 -25
- data/lib/asciidoctor/standoc/ref_sect.rb +4 -3
- data/lib/asciidoctor/standoc/section.rb +21 -20
- data/lib/asciidoctor/standoc/table.rb +12 -0
- data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +86 -0
- data/lib/asciidoctor/standoc/utils.rb +2 -0
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +5 -3
- data/spec/asciidoctor-standoc/base_spec.rb +14 -4
- data/spec/asciidoctor-standoc/blocks_spec.rb +14 -9
- data/spec/asciidoctor-standoc/cleanup_sections_spec.rb +1519 -0
- data/spec/asciidoctor-standoc/cleanup_spec.rb +416 -1554
- data/spec/asciidoctor-standoc/converter_spec.rb +8 -0
- data/spec/asciidoctor-standoc/inline_spec.rb +2 -5
- data/spec/asciidoctor-standoc/isobib_cache_spec.rb +16 -9
- data/spec/asciidoctor-standoc/lists_spec.rb +10 -1
- data/spec/asciidoctor-standoc/macros_lutaml_spec.rb +80 -0
- data/spec/asciidoctor-standoc/macros_plantuml_spec.rb +307 -0
- data/spec/asciidoctor-standoc/macros_spec.rb +408 -169
- data/spec/asciidoctor-standoc/refs_dl_spec.rb +6 -6
- data/spec/asciidoctor-standoc/refs_spec.rb +112 -65
- data/spec/asciidoctor-standoc/section_spec.rb +17 -12
- data/spec/asciidoctor-standoc/table_spec.rb +86 -0
- data/spec/asciidoctor-standoc/validate_spec.rb +26 -0
- data/spec/fixtures/diagram_definitions.lutaml +22 -0
- data/spec/fixtures/test.exp +121 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +59 -243
- data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_123_1.yml +27 -119
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +35 -35
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -60
- data/spec/vcr_cassettes/isobib_get_124.yml +11 -57
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +281 -157
- metadata +45 -11
- data/.github/workflows/macos.yml +0 -41
- data/.github/workflows/ubuntu.yml +0 -45
- data/.github/workflows/windows.yml +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6af6d01c6514c3fbfe4a1bbe33b088f15eb78c7243db92fb36694d050a84635
|
4
|
+
data.tar.gz: 4dc1bdc07d11ce753ff4a26482cf5adba8f81153da808a9eb68a6b4cdda13a89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc0064271a3104f6e26cecdd33228befe52771b31aff7aa18e44325851ebaeb5d2bda60aca28fe5113d87097df945153723553526357e7d6225176a9dbc1067f
|
7
|
+
data.tar.gz: b5f306f4fbab92edefee5887fb3acaa22d31583d37d0de0ddb8d8c469a17ced57d8300ab6254e0c860e3aa7c6519e0ce5f77eaa7986e49bfb497672997c7c743
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
name: rake
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches: [ master, main ]
|
8
|
+
tags: [ v* ]
|
9
|
+
pull_request:
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
rake:
|
13
|
+
name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
|
14
|
+
runs-on: ${{ matrix.os }}
|
15
|
+
continue-on-error: ${{ matrix.experimental }}
|
16
|
+
strategy:
|
17
|
+
fail-fast: false
|
18
|
+
matrix:
|
19
|
+
ruby: [ '2.6', '2.5', '2.4' ]
|
20
|
+
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
|
+
experimental: [ false ]
|
22
|
+
include:
|
23
|
+
- ruby: '2.7'
|
24
|
+
os: 'ubuntu-latest'
|
25
|
+
experimental: true
|
26
|
+
- ruby: '2.7'
|
27
|
+
os: 'windows-latest'
|
28
|
+
experimental: true
|
29
|
+
- ruby: '2.7'
|
30
|
+
os: 'macos-latest'
|
31
|
+
experimental: true
|
32
|
+
steps:
|
33
|
+
- uses: actions/checkout@master
|
34
|
+
|
35
|
+
- uses: ruby/setup-ruby@v1
|
36
|
+
with:
|
37
|
+
ruby-version: ${{ matrix.ruby }}
|
38
|
+
|
39
|
+
- uses: actions/cache@v2
|
40
|
+
with:
|
41
|
+
path: vendor/bundle
|
42
|
+
key: bundle-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}
|
43
|
+
restore-keys: bundle-${{ matrix.os }}-${{ matrix.ruby }}
|
44
|
+
|
45
|
+
- run: bundle config set path 'vendor/bundle'
|
46
|
+
|
47
|
+
- run: bundle install --jobs 4 --retry 3
|
48
|
+
|
49
|
+
- name: install plantuml ubuntu
|
50
|
+
if: matrix.os == 'ubuntu-latest'
|
51
|
+
uses: nick-invision/retry@v1
|
52
|
+
with:
|
53
|
+
polling_interval_seconds: 5
|
54
|
+
timeout_minutes: 5
|
55
|
+
max_attempts: 3
|
56
|
+
command: >
|
57
|
+
sudo apt-get update -y && sudo bash -c
|
58
|
+
"curl -L https://github.com/metanorma/plantuml-install/raw/master/ubuntu.sh | bash"
|
59
|
+
|
60
|
+
- if: matrix.os == 'macos-latest'
|
61
|
+
run: brew install plantuml
|
62
|
+
|
63
|
+
- if: matrix.os == 'windows-latest'
|
64
|
+
run: cinst -y plantuml
|
65
|
+
|
66
|
+
- run: bundle exec rake
|
data/README.adoc
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
= Metanorma-standoc
|
2
2
|
|
3
3
|
image:https://img.shields.io/gem/v/metanorma-standoc.svg["Gem Version", link="https://rubygems.org/gems/metanorma-standoc"]
|
4
|
-
image:https://github.com/metanorma/metanorma-standoc/workflows/
|
5
|
-
image:https://github.com/metanorma/metanorma-standoc/workflows/ubuntu/badge.svg["Build Status (ubuntu)", link="https://github.com/metanorma/metanorma-standoc/actions?workflow=ubuntu"]
|
6
|
-
image:https://github.com/metanorma/metanorma-standoc/workflows/windows/badge.svg["Build Status (Windows)", link="https://github.com/metanorma/metanorma-standoc/actions?workflow=windows"]
|
4
|
+
image:https://github.com/metanorma/metanorma-standoc/workflows/rake/badge.svg["Build Status", link="https://github.com/metanorma/metanorma-standoc/actions?workflow=rake"]
|
7
5
|
image:https://codeclimate.com/github/metanorma/metanorma-standoc/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/metanorma-standoc"]
|
8
6
|
image:https://img.shields.io/github/issues-pr-raw/metanorma/metanorma-standoc.svg["Pull Requests", link="https://github.com/metanorma/metanorma-standoc/pulls"]
|
9
7
|
image:https://img.shields.io/github/commits-since/metanorma/metanorma-standoc/latest.svg["Commits since latest",link="https://github.com/metanorma/metanorma-standoc/releases"]
|
@@ -94,12 +94,10 @@ module Asciidoctor
|
|
94
94
|
@draft = node.attributes.has_key?("draft")
|
95
95
|
@novalid = node.attr("novalid")
|
96
96
|
@smartquotes = node.attr("smartquotes") != "false"
|
97
|
-
@keepasciimath = node.attr("mn-keep-asciimath") &&
|
98
|
-
node.attr("mn-keep-asciimath") != "false"
|
97
|
+
@keepasciimath = node.attr("mn-keep-asciimath") && node.attr("mn-keep-asciimath") != "false"
|
99
98
|
@fontheader = default_fonts(node)
|
100
99
|
@files_to_delete = []
|
101
|
-
@filename = node.attr("docfile") ?
|
102
|
-
File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : ""
|
100
|
+
@filename = node.attr("docfile") ? File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : ""
|
103
101
|
@localdir = Utils::localdir(node)
|
104
102
|
@output_dir = outputdir node
|
105
103
|
@no_isobib_cache = node.attr("no-isobib-cache")
|
@@ -119,11 +117,9 @@ module Asciidoctor
|
|
119
117
|
|
120
118
|
def default_fonts(node)
|
121
119
|
b = node.attr("body-font") ||
|
122
|
-
(node.attr("script") == "Hans" ? '"SimSun",serif' :
|
123
|
-
'"Cambria",serif')
|
120
|
+
(node.attr("script") == "Hans" ? '"SimSun",serif' : '"Cambria",serif')
|
124
121
|
h = node.attr("header-font") ||
|
125
|
-
(node.attr("script") == "Hans" ? '"SimHei",sans-serif' :
|
126
|
-
'"Cambria",serif')
|
122
|
+
(node.attr("script") == "Hans" ? '"SimHei",sans-serif' : '"Cambria",serif')
|
127
123
|
m = node.attr("monospace-font") || '"Courier New",monospace'
|
128
124
|
"$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
|
129
125
|
end
|
@@ -154,8 +150,7 @@ module Asciidoctor
|
|
154
150
|
end
|
155
151
|
|
156
152
|
def makexml1(node)
|
157
|
-
result = ["<?xml version='1.0' encoding='UTF-8'?>",
|
158
|
-
"<#{xml_root_tag} type='semantic' version='#{version}'>"]
|
153
|
+
result = ["<?xml version='1.0' encoding='UTF-8'?>", "<#{xml_root_tag} type='semantic' version='#{version}'>"]
|
159
154
|
result << noko { |ixml| front node, ixml }
|
160
155
|
result << noko { |ixml| middle node, ixml }
|
161
156
|
result << "</#{xml_root_tag}>"
|
@@ -192,16 +187,14 @@ module Asciidoctor
|
|
192
187
|
|
193
188
|
def term_source_attrs(seen_xref)
|
194
189
|
{ bibitemid: seen_xref.children[0]["target"],
|
195
|
-
format: seen_xref.children[0]["format"],
|
196
|
-
type: "inline" }
|
190
|
+
format: seen_xref.children[0]["format"], type: "inline" }
|
197
191
|
end
|
198
192
|
|
199
193
|
def add_term_source(xml_t, seen_xref, m)
|
200
194
|
if seen_xref.children[0].name == "concept"
|
201
195
|
xml_t.origin { |o| o << seen_xref.children[0].to_xml }
|
202
196
|
else
|
203
|
-
xml_t.origin seen_xref.children[0].content,
|
204
|
-
**attr_code(term_source_attrs(seen_xref))
|
197
|
+
xml_t.origin seen_xref.children[0].content, **attr_code(term_source_attrs(seen_xref))
|
205
198
|
end
|
206
199
|
m[:text] && xml_t.modification do |mod|
|
207
200
|
mod.p { |p| p << m[:text].sub(/^\s+/, "") }
|
@@ -219,8 +212,7 @@ module Asciidoctor
|
|
219
212
|
|
220
213
|
def extract_termsource_refs(text, node)
|
221
214
|
matched = TERM_REFERENCE_RE.match text
|
222
|
-
matched.nil? and
|
223
|
-
@log.add("AsciiDoc Input", node, "term reference not in expected format: #{text}")
|
215
|
+
matched.nil? and @log.add("AsciiDoc Input", node, "term reference not in expected format: #{text}")
|
224
216
|
matched
|
225
217
|
end
|
226
218
|
|
@@ -596,6 +596,7 @@
|
|
596
596
|
<ref name="bookmark"/>
|
597
597
|
<ref name="image"/>
|
598
598
|
<ref name="index"/>
|
599
|
+
<ref name="index-xref"/>
|
599
600
|
</choice>
|
600
601
|
</define>
|
601
602
|
<define name="PureTextElement">
|
@@ -728,15 +729,61 @@
|
|
728
729
|
</define>
|
729
730
|
<define name="index">
|
730
731
|
<element name="index">
|
731
|
-
<attribute name="
|
732
|
+
<attribute name="to">
|
733
|
+
<data type="IDREF"/>
|
734
|
+
</attribute>
|
735
|
+
<element name="primary">
|
736
|
+
<oneOrMore>
|
737
|
+
<ref name="PureTextElement"/>
|
738
|
+
</oneOrMore>
|
739
|
+
</element>
|
732
740
|
<optional>
|
733
|
-
<
|
741
|
+
<element name="secondary">
|
742
|
+
<oneOrMore>
|
743
|
+
<ref name="PureTextElement"/>
|
744
|
+
</oneOrMore>
|
745
|
+
</element>
|
734
746
|
</optional>
|
735
747
|
<optional>
|
736
|
-
<
|
748
|
+
<element name="tertiary">
|
749
|
+
<oneOrMore>
|
750
|
+
<ref name="PureTextElement"/>
|
751
|
+
</oneOrMore>
|
752
|
+
</element>
|
737
753
|
</optional>
|
738
754
|
</element>
|
739
755
|
</define>
|
756
|
+
<define name="index-xref">
|
757
|
+
<element name="index-xref">
|
758
|
+
<attribute name="also">
|
759
|
+
<data type="boolean"/>
|
760
|
+
</attribute>
|
761
|
+
<element name="primary">
|
762
|
+
<oneOrMore>
|
763
|
+
<ref name="PureTextElement"/>
|
764
|
+
</oneOrMore>
|
765
|
+
</element>
|
766
|
+
<optional>
|
767
|
+
<element name="secondary">
|
768
|
+
<oneOrMore>
|
769
|
+
<ref name="PureTextElement"/>
|
770
|
+
</oneOrMore>
|
771
|
+
</element>
|
772
|
+
</optional>
|
773
|
+
<optional>
|
774
|
+
<element name="tertiary">
|
775
|
+
<oneOrMore>
|
776
|
+
<ref name="PureTextElement"/>
|
777
|
+
</oneOrMore>
|
778
|
+
</element>
|
779
|
+
</optional>
|
780
|
+
<element name="target">
|
781
|
+
<oneOrMore>
|
782
|
+
<ref name="PureTextElement"/>
|
783
|
+
</oneOrMore>
|
784
|
+
</element>
|
785
|
+
</element>
|
786
|
+
</define>
|
740
787
|
<!-- bare ID element, used for referencing arbitrary spans of text -->
|
741
788
|
<define name="bookmark">
|
742
789
|
<element name="bookmark">
|
@@ -69,6 +69,7 @@ module Asciidoctor
|
|
69
69
|
bibdata_cleanup(xmldoc)
|
70
70
|
boilerplate_cleanup(xmldoc)
|
71
71
|
smartquotes_cleanup(xmldoc)
|
72
|
+
variant_cleanup(xmldoc)
|
72
73
|
para_cleanup(xmldoc)
|
73
74
|
empty_element_cleanup(xmldoc)
|
74
75
|
img_cleanup(xmldoc)
|
@@ -155,17 +156,42 @@ module Asciidoctor
|
|
155
156
|
x.children = math
|
156
157
|
end
|
157
158
|
|
159
|
+
MATHML_NS = "http://www.w3.org/1998/Math/MathML".freeze
|
160
|
+
|
158
161
|
def mathml_preserve_space(m)
|
159
|
-
m.xpath(".//m:mtext",
|
160
|
-
"m" => "http://www.w3.org/1998/Math/MathML").each do |x|
|
162
|
+
m.xpath(".//m:mtext", "m" => MATHML_NS).each do |x|
|
161
163
|
x.children = x.children.to_xml.gsub(/^\s/, " ").
|
162
164
|
gsub(/\s$/, " ")
|
163
165
|
end
|
164
166
|
end
|
165
167
|
|
166
168
|
def mathml_namespace(stem)
|
167
|
-
stem.xpath("./math", ).each
|
168
|
-
|
169
|
+
stem.xpath("./math", ).each { |x| x.default_namespace = MATHML_NS }
|
170
|
+
end
|
171
|
+
|
172
|
+
def mathml_mi_italics
|
173
|
+
{ uppergreek: true, upperroman: true,
|
174
|
+
lowergreek: true, lowerroman: true }
|
175
|
+
end
|
176
|
+
|
177
|
+
# presuppose multichar mi upright, singlechar mi MathML default italic
|
178
|
+
def mathml_italicise(x)
|
179
|
+
x.xpath(".//m:mi[not(ancestor::*[@mathvariant])]", "m" => MATHML_NS).each do |i|
|
180
|
+
char = HTMLEntities.new.decode(i.text)
|
181
|
+
i["mathvariant"] = "normal" if mi_italicise?(char)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def mi_italicise?(c)
|
186
|
+
return false if c.length > 1
|
187
|
+
if /\p{Greek}/.match(c)
|
188
|
+
/\p{Lower}/.match(c) && !mathml_mi_italics[:lowergreek] ||
|
189
|
+
/\p{Upper}/.match(c) && !mathml_mi_italics[:uppergreek]
|
190
|
+
elsif /\p{Latin}/.match(c)
|
191
|
+
/\p{Lower}/.match(c) && !mathml_mi_italics[:lowerroman] ||
|
192
|
+
/\p{Upper}/.match(c) && !mathml_mi_italics[:upperroman]
|
193
|
+
else
|
194
|
+
false
|
169
195
|
end
|
170
196
|
end
|
171
197
|
|
@@ -174,6 +200,7 @@ module Asciidoctor
|
|
174
200
|
xml_unescape_mathml(x)
|
175
201
|
mathml_namespace(x)
|
176
202
|
mathml_preserve_space(x)
|
203
|
+
mathml_italicise(x)
|
177
204
|
end
|
178
205
|
end
|
179
206
|
|
@@ -192,6 +219,27 @@ module Asciidoctor
|
|
192
219
|
i["src"] = datauri(i["src"])
|
193
220
|
end
|
194
221
|
end
|
222
|
+
|
223
|
+
def variant_cleanup(xmldoc)
|
224
|
+
xmldoc.xpath("//*[variant]").each do |c|
|
225
|
+
c&.next&.text? && c&.next&.next&.name == "variant" &&
|
226
|
+
c.next.text.gsub(/\s/, "").empty? and c.next.remove
|
227
|
+
end
|
228
|
+
xmldoc.xpath("//*[variant]").each do |c|
|
229
|
+
next unless c.children.any? do |n|
|
230
|
+
n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?)
|
231
|
+
end
|
232
|
+
c.xpath("./variant").each do |n|
|
233
|
+
if n.at_xpath('preceding-sibling::node()[not(self::text()'\
|
234
|
+
'[not(normalize-space())])][1][self::variantwrap]')
|
235
|
+
n.previous_element << n
|
236
|
+
else
|
237
|
+
n.replace('<variantwrap/>').first << n
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
xmldoc.xpath("//variantwrap").each { |n| n.name = "variant" }
|
242
|
+
end
|
195
243
|
end
|
196
244
|
end
|
197
245
|
end
|
@@ -19,12 +19,22 @@ module Asciidoctor
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
def dl1_table_cleanup(xmldoc)
|
23
|
+
q = "//table/following-sibling::*[1][self::dl]"
|
24
|
+
xmldoc.xpath(q).each do |s|
|
25
|
+
if s["key"] == "true"
|
26
|
+
s.previous_element << s.remove
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
22
31
|
# move Key dl after table footer
|
23
|
-
def
|
32
|
+
def dl2_table_cleanup(xmldoc)
|
24
33
|
q = "//table/following-sibling::*[1][self::p]"
|
25
34
|
xmldoc.xpath(q).each do |s|
|
26
35
|
if s.text =~ /^\s*key[^a-z]*$/i && !s.next_element.nil? &&
|
27
36
|
s.next_element.name == "dl"
|
37
|
+
s.next_element["key"] = "true"
|
28
38
|
s.previous_element << s.next_element.remove
|
29
39
|
s.remove
|
30
40
|
end
|
@@ -54,7 +64,8 @@ module Asciidoctor
|
|
54
64
|
end
|
55
65
|
|
56
66
|
def table_cleanup(xmldoc)
|
57
|
-
|
67
|
+
dl1_table_cleanup(xmldoc)
|
68
|
+
dl2_table_cleanup(xmldoc)
|
58
69
|
notes_table_cleanup(xmldoc)
|
59
70
|
header_rows_cleanup(xmldoc)
|
60
71
|
end
|
@@ -74,22 +85,47 @@ module Asciidoctor
|
|
74
85
|
|
75
86
|
# include where definition list inside stem block
|
76
87
|
def formula_cleanup(x)
|
88
|
+
formula_cleanup_where1(x)
|
89
|
+
formula_cleanup_where2(x)
|
90
|
+
end
|
91
|
+
|
92
|
+
def formula_cleanup_where1(x)
|
93
|
+
q = "//formula/following-sibling::*[1][self::dl]"
|
94
|
+
x.xpath(q).each do |s|
|
95
|
+
if s["key"] == "true"
|
96
|
+
s.previous_element << s.remove
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def formula_cleanup_where2(x)
|
77
102
|
q = "//formula/following-sibling::*[1][self::p]"
|
78
103
|
x.xpath(q).each do |s|
|
79
104
|
if s.text =~ /^\s*where[^a-z]*$/i && !s.next_element.nil? &&
|
80
105
|
s.next_element.name == "dl"
|
106
|
+
s.next_element["key"] = "true"
|
81
107
|
s.previous_element << s.next_element.remove
|
82
108
|
s.remove
|
83
109
|
end
|
84
110
|
end
|
85
111
|
end
|
86
112
|
|
113
|
+
def figure_dl_cleanup1(xmldoc)
|
114
|
+
q = "//figure/following-sibling::*[self::dl]"
|
115
|
+
xmldoc.xpath(q).each do |s|
|
116
|
+
if s["key"] == "true"
|
117
|
+
s.previous_element << s.remove
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
87
122
|
# include key definition list inside figure
|
88
|
-
def
|
123
|
+
def figure_dl_cleanup2(xmldoc)
|
89
124
|
q = "//figure/following-sibling::*[self::p]"
|
90
125
|
xmldoc.xpath(q).each do |s|
|
91
126
|
if s.text =~ /^\s*key[^a-z]*$/i && !s.next_element.nil? &&
|
92
127
|
s.next_element.name == "dl"
|
128
|
+
s.next_element["key"] = "true"
|
93
129
|
s.previous_element << s.next_element.remove
|
94
130
|
s.remove
|
95
131
|
end
|
@@ -115,7 +151,8 @@ module Asciidoctor
|
|
115
151
|
|
116
152
|
def figure_cleanup(xmldoc)
|
117
153
|
figure_footnote_cleanup(xmldoc)
|
118
|
-
|
154
|
+
figure_dl_cleanup1(xmldoc)
|
155
|
+
figure_dl_cleanup2(xmldoc)
|
119
156
|
subfigure_cleanup(xmldoc)
|
120
157
|
end
|
121
158
|
|
@@ -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
|
|
@@ -91,10 +104,24 @@ module Asciidoctor
|
|
91
104
|
end
|
92
105
|
|
93
106
|
def bibdata_cleanup(xmldoc)
|
107
|
+
bibdata_anchor_cleanup(xmldoc)
|
108
|
+
bibdata_docidentifier_cleanup(xmldoc)
|
109
|
+
end
|
110
|
+
|
111
|
+
def bibdata_anchor_cleanup(xmldoc)
|
94
112
|
xmldoc.xpath("//bibdata//bibitem | //bibdata//note").each do |b|
|
95
113
|
b.delete("id")
|
96
114
|
end
|
97
115
|
end
|
116
|
+
|
117
|
+
def bibdata_docidentifier_cleanup(xmldoc)
|
118
|
+
ins = xmldoc.at("//bibdata/docidentifier")
|
119
|
+
xmldoc.xpath("//bibdata/docidentifier").each_with_index do |b, i|
|
120
|
+
next if i == 0
|
121
|
+
ins.next = b.remove
|
122
|
+
ins = ins.next
|
123
|
+
end
|
124
|
+
end
|
98
125
|
end
|
99
126
|
end
|
100
127
|
end
|