isodoc 1.8.4 → 2.0.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 +3 -31
- data/lib/isodoc/function/references.rb +31 -22
- data/lib/isodoc/function/section_titles.rb +6 -1
- data/lib/isodoc/function/utils.rb +1 -0
- data/lib/isodoc/html_function/postprocess.rb +9 -2
- data/lib/isodoc/presentation_function/bibdata.rb +0 -6
- data/lib/isodoc/presentation_function/section.rb +27 -7
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/xref/xref_sect_gen.rb +7 -3
- data/spec/isodoc/blocks_spec.rb +2 -1
- data/spec/isodoc/postproc_spec.rb +28 -0
- data/spec/isodoc/presentation_xml_spec.rb +208 -37
- data/spec/isodoc/ref_spec.rb +332 -300
- data/spec/isodoc/section_spec.rb +70 -204
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94378642fdbff3fdfd64fc15d3f502fd3ac966926d19b060c5b7bbd4b9f9e545
|
4
|
+
data.tar.gz: eeb1da05b0df09ea66cd55692f3d2f706991904216c5869025b9d936dc93cf12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8164bf9d471f1b409ff4c0d933f69b9f834d340548caf3b441d7ca4584460b026420bb752903121561d573f8ddc618e5796d5e22dd09c1a9f3ca429cf567df5
|
7
|
+
data.tar.gz: 75a73a94378f4d0fe6187b343d84961265e60d1417d23c43c38b11c819190cba0838dd0a99ba21d7e49824add339f7a6007c42748f87130a7abd2ce35d14105b
|
data/.github/workflows/rake.yml
CHANGED
@@ -10,34 +10,6 @@ on:
|
|
10
10
|
|
11
11
|
jobs:
|
12
12
|
rake:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
strategy:
|
17
|
-
fail-fast: false
|
18
|
-
matrix:
|
19
|
-
ruby: [ '3.0', '2.7', '2.6', '2.5' ]
|
20
|
-
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
|
-
experimental: [ false ]
|
22
|
-
steps:
|
23
|
-
- uses: actions/checkout@master
|
24
|
-
|
25
|
-
- uses: ruby/setup-ruby@v1
|
26
|
-
with:
|
27
|
-
ruby-version: ${{ matrix.ruby }}
|
28
|
-
bundler-cache: true
|
29
|
-
|
30
|
-
- uses: metanorma/metanorma-build-scripts/inkscape-setup-action@master
|
31
|
-
|
32
|
-
- run: bundle exec rake
|
33
|
-
|
34
|
-
tests-passed:
|
35
|
-
needs: rake
|
36
|
-
runs-on: ubuntu-latest
|
37
|
-
steps:
|
38
|
-
- uses: peter-evans/repository-dispatch@v1
|
39
|
-
with:
|
40
|
-
token: ${{ secrets.METANORMA_CI_PAT_TOKEN || secrets.GITHUB_TOKEN }}
|
41
|
-
repository: ${{ github.repository }}
|
42
|
-
event-type: tests-passed
|
43
|
-
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
|
13
|
+
uses: metanorma/metanorma-build-scripts/.github/workflows/inkscape-rake.yml@main
|
14
|
+
secrets:
|
15
|
+
pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
|
@@ -14,27 +14,28 @@ module IsoDoc
|
|
14
14
|
def nonstd_bibitem(list, bib, ordinal, biblio)
|
15
15
|
list.p **attr_code(iso_bibitem_entry_attrs(bib, biblio)) do |ref|
|
16
16
|
ids = bibitem_ref_code(bib)
|
17
|
-
|
18
|
-
if biblio then ref_entry_code(ref, ordinal,
|
17
|
+
idents = render_identifier(ids)
|
18
|
+
if biblio then ref_entry_code(ref, ordinal, idents, ids)
|
19
19
|
else
|
20
|
-
ref << (
|
21
|
-
ref << ", #{
|
20
|
+
ref << (idents[:ordinal] || idents[:metanorma] || idents[:sdo]).to_s
|
21
|
+
ref << ", #{idents[sdo]}" if idents[:ordinal] && idents[:sdo]
|
22
22
|
end
|
23
|
-
ref << ", " unless biblio && !
|
23
|
+
ref << ", " unless biblio && !idents[:sdo]
|
24
24
|
reference_format(bib, ref)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def std_bibitem_entry(list, bib, ordinal, biblio)
|
29
29
|
list.p **attr_code(iso_bibitem_entry_attrs(bib, biblio)) do |ref|
|
30
|
-
|
31
|
-
if biblio then ref_entry_code(ref, ordinal,
|
30
|
+
idents = render_identifier(bibitem_ref_code(bib))
|
31
|
+
if biblio then ref_entry_code(ref, ordinal, idents, nil)
|
32
32
|
else
|
33
|
-
ref << (
|
34
|
-
ref << ", #{
|
33
|
+
ref << (idents[:ordinal] || idents[:metanorma] || idents[:sdo]).to_s
|
34
|
+
ref << ", #{idents[:sdo]}" if (idents[:ordinal] ||
|
35
|
+
idents[:metanorma]) && idents[:sdo]
|
35
36
|
end
|
36
37
|
date_note_process(bib, ref)
|
37
|
-
ref << ", " unless biblio && !
|
38
|
+
ref << ", " unless biblio && !idents[:sdo]
|
38
39
|
reference_format(bib, ref)
|
39
40
|
end
|
40
41
|
end
|
@@ -42,13 +43,15 @@ module IsoDoc
|
|
42
43
|
# if ids is just a number, only use that ([1] Non-Standard)
|
43
44
|
# else, use both ordinal, as prefix, and ids
|
44
45
|
def ref_entry_code(ref, ordinal, ids, _id)
|
45
|
-
prefix_bracketed_ref(ref, ids[
|
46
|
-
|
46
|
+
prefix_bracketed_ref(ref, ids[:ordinal] || ids[:metanorma] ||
|
47
|
+
"[#{ordinal}]")
|
48
|
+
ids[:sdo] and ref << (ids[:sdo]).to_s
|
47
49
|
end
|
48
50
|
|
49
51
|
def pref_ref_code(bib)
|
50
52
|
bib.at(ns("./docidentifier[not(@type = 'DOI' or @type = 'metanorma' "\
|
51
|
-
"or @type = '
|
53
|
+
"or @type = 'metanorma-ordinal' or "\
|
54
|
+
"@type = 'ISSN' or @type = 'ISBN' or "\
|
52
55
|
"@type = 'rfc-anchor')]"))
|
53
56
|
end
|
54
57
|
|
@@ -58,11 +61,12 @@ module IsoDoc
|
|
58
61
|
id1 = pref_ref_code(bib)
|
59
62
|
id2 = bib.at(ns("./docidentifier[@type = 'DOI' or @type = 'ISSN' or "\
|
60
63
|
"@type = 'ISBN']"))
|
61
|
-
|
64
|
+
id3 = bib.at(ns("./docidentifier[@type = 'metanorma-ordinal']"))
|
65
|
+
return [id, id1, id2, id3] if id || id1 || id2 || id3
|
62
66
|
|
63
67
|
id = Nokogiri::XML::Node.new("docidentifier", bib.document)
|
64
68
|
id << "(NO ID)"
|
65
|
-
[nil, id, nil]
|
69
|
+
[nil, id, nil, nil]
|
66
70
|
end
|
67
71
|
|
68
72
|
def bracket_if_num(num)
|
@@ -74,10 +78,15 @@ module IsoDoc
|
|
74
78
|
num
|
75
79
|
end
|
76
80
|
|
81
|
+
def unbracket(ident)
|
82
|
+
ident&.text&.sub(/^\[/, "")&.sub(/\]$/, "")
|
83
|
+
end
|
84
|
+
|
77
85
|
def render_identifier(ident)
|
78
|
-
|
79
|
-
|
80
|
-
|
86
|
+
{ metanorma: bracket_if_num(ident[0]),
|
87
|
+
sdo: unbracket(ident[1]),
|
88
|
+
doi: unbracket(ident[2]),
|
89
|
+
ordinal: bracket_if_num(ident[3]) }
|
81
90
|
end
|
82
91
|
|
83
92
|
def docid_prefix(prefix, docid)
|
@@ -133,7 +142,7 @@ module IsoDoc
|
|
133
142
|
end
|
134
143
|
end
|
135
144
|
|
136
|
-
def
|
145
|
+
def standard?(bib)
|
137
146
|
ret = false
|
138
147
|
drop = %w(metanorma DOI ISSN ISBN)
|
139
148
|
bib.xpath(ns("./docidentifier")).each do |id|
|
@@ -151,7 +160,7 @@ module IsoDoc
|
|
151
160
|
next if implicit_reference(b)
|
152
161
|
|
153
162
|
i += 1
|
154
|
-
if
|
163
|
+
if standard?(b) then std_bibitem_entry(div, b, i, biblio)
|
155
164
|
else nonstd_bibitem(div, b, i, biblio)
|
156
165
|
end
|
157
166
|
else
|
@@ -166,7 +175,7 @@ module IsoDoc
|
|
166
175
|
end
|
167
176
|
|
168
177
|
def norm_ref(isoxml, out, num)
|
169
|
-
f = isoxml.at(ns(norm_ref_xpath)) and f["hidden"] != "true" or
|
178
|
+
(f = isoxml.at(ns(norm_ref_xpath)) and f["hidden"] != "true") or
|
170
179
|
return num
|
171
180
|
out.div do |div|
|
172
181
|
num = num + 1
|
@@ -186,7 +195,7 @@ module IsoDoc
|
|
186
195
|
end
|
187
196
|
|
188
197
|
def bibliography(isoxml, out)
|
189
|
-
f = isoxml.at(ns(bibliography_xpath)) and f["hidden"] != "true" or
|
198
|
+
(f = isoxml.at(ns(bibliography_xpath)) and f["hidden"] != "true") or
|
190
199
|
return
|
191
200
|
page_break(out)
|
192
201
|
out.div do |div|
|
@@ -76,7 +76,12 @@ module IsoDoc
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
def variant_title(
|
79
|
+
def variant_title(node, out)
|
80
|
+
out.p **attr_code(style: "display:none;",
|
81
|
+
class: "variant-title-#{node['type']}") do |p|
|
82
|
+
node.children.each { |c| parse(c, p) }
|
83
|
+
end
|
84
|
+
end
|
80
85
|
end
|
81
86
|
end
|
82
87
|
end
|
@@ -129,6 +129,7 @@ module IsoDoc
|
|
129
129
|
|
130
130
|
def header_strip(hdr)
|
131
131
|
h1 = to_xhtml_fragment(hdr.to_s.gsub(%r{<br\s*/>}, " ")
|
132
|
+
.gsub(%r{</?p(\s[^>]+)?>}, "")
|
132
133
|
.gsub(/<\/?h[123456][^>]*>/, "").gsub(/<\/?b[^>]*>/, "").dup)
|
133
134
|
h1.traverse do |x|
|
134
135
|
if x.name == "span" && /mso-tab-count/.match(x["style"])
|
@@ -122,8 +122,10 @@ module IsoDoc
|
|
122
122
|
end
|
123
123
|
|
124
124
|
def html_toc_entry(level, header)
|
125
|
+
content = header.at("./following-sibling::p"\
|
126
|
+
"[@class = 'variant-title-toc']") || header
|
125
127
|
%(<li class="#{level}"><a href="##{header['id']}">\
|
126
|
-
#{header_strip(
|
128
|
+
#{header_strip(content)}</a></li>)
|
127
129
|
end
|
128
130
|
|
129
131
|
def toclevel_classes
|
@@ -144,7 +146,7 @@ module IsoDoc
|
|
144
146
|
idx = docxml.at("//div[@id = 'toc']") or return docxml
|
145
147
|
toc = "<ul>"
|
146
148
|
path = toclevel_classes.map do |l|
|
147
|
-
"//main//#{l}
|
149
|
+
"//main//#{l}#{toc_exclude_class}"
|
148
150
|
end
|
149
151
|
docxml.xpath(path.join(" | ")).each_with_index do |h, tocidx|
|
150
152
|
h["id"] ||= "toc#{tocidx}"
|
@@ -154,6 +156,11 @@ module IsoDoc
|
|
154
156
|
docxml
|
155
157
|
end
|
156
158
|
|
159
|
+
def toc_exclude_class
|
160
|
+
"[not(@class = 'TermNum')][not(@class = 'noTOC')]"\
|
161
|
+
"[string-length(normalize-space(.))>0]"
|
162
|
+
end
|
163
|
+
|
157
164
|
# presupposes that the image source is local
|
158
165
|
def move_images(docxml)
|
159
166
|
FileUtils.rm_rf tmpimagedir
|
@@ -10,12 +10,6 @@ module IsoDoc
|
|
10
10
|
"</localized-strings>"
|
11
11
|
end
|
12
12
|
|
13
|
-
def docid_prefixes(docxml)
|
14
|
-
docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
|
15
|
-
i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
13
|
def address_precompose(bib)
|
20
14
|
bib.xpath(ns("//bibdata//address")).each do |b|
|
21
15
|
next if b.at(ns("./formattedAddress"))
|
@@ -29,9 +29,9 @@ module IsoDoc
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def floattitle1(elem)
|
32
|
-
|
33
|
-
|
34
|
-
p["
|
32
|
+
elem.xpath(ns(".//floating-title")).each do |p|
|
33
|
+
p.name = "p"
|
34
|
+
p["type"] = "floating-title"
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -60,7 +60,29 @@ module IsoDoc
|
|
60
60
|
prefix_name(elem, "", "#{lbl}#{clausedelim}", "name")
|
61
61
|
end
|
62
62
|
|
63
|
-
def references(docxml)
|
63
|
+
def references(docxml)
|
64
|
+
bibliography_bibitem_number(docxml)
|
65
|
+
end
|
66
|
+
|
67
|
+
def bibliography_bibitem_number_skip(bibitem)
|
68
|
+
@xrefs.klass.implicit_reference(bibitem) ||
|
69
|
+
bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) ||
|
70
|
+
bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']"))
|
71
|
+
# || @xrefs.klass.standard?(bibitem)
|
72
|
+
end
|
73
|
+
|
74
|
+
def bibliography_bibitem_number(docxml)
|
75
|
+
i = 0
|
76
|
+
docxml.xpath(ns("//references[@normative = 'false']/bibitem")).each do |b|
|
77
|
+
next if bibliography_bibitem_number_skip(b)
|
78
|
+
|
79
|
+
i += 1
|
80
|
+
id = b.at(ns(".//docidentifier"))
|
81
|
+
id.previous =
|
82
|
+
"<docidentifier type='metanorma-ordinal'>[#{i}]</docidentifier>"
|
83
|
+
end
|
84
|
+
@xrefs.references docxml
|
85
|
+
end
|
64
86
|
|
65
87
|
def docid_prefixes(docxml)
|
66
88
|
docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
|
@@ -102,9 +124,7 @@ module IsoDoc
|
|
102
124
|
display_order_xpath(docxml, "//indexsect", i)
|
103
125
|
end
|
104
126
|
|
105
|
-
def clausetitle(docxml)
|
106
|
-
docxml.xpath(ns("//variant-title[@type = 'toc']")).each(&:remove)
|
107
|
-
end
|
127
|
+
def clausetitle(docxml); end
|
108
128
|
|
109
129
|
def toc(docxml)
|
110
130
|
docxml.xpath(ns("//toc//xref[text()]")).each do |x|
|
data/lib/isodoc/version.rb
CHANGED
@@ -9,6 +9,10 @@ module IsoDoc
|
|
9
9
|
docxml.xpath(ns(@klass.bibliography_xpath)).each do |b|
|
10
10
|
preface_names(b)
|
11
11
|
end
|
12
|
+
references(docxml)
|
13
|
+
end
|
14
|
+
|
15
|
+
def references(docxml)
|
12
16
|
docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
|
13
17
|
reference_names(ref)
|
14
18
|
end
|
@@ -148,11 +152,11 @@ module IsoDoc
|
|
148
152
|
"xmlns:name = 'International Electrotechnical Commission']".freeze
|
149
153
|
|
150
154
|
def reference_names(ref)
|
151
|
-
# isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
|
152
155
|
ids = @klass.bibitem_ref_code(ref)
|
153
156
|
identifiers = @klass.render_identifier(ids)
|
154
|
-
|
155
|
-
|
157
|
+
reference = @klass
|
158
|
+
.docid_l10n(identifiers[:metanorma] || identifiers[:sdo] ||
|
159
|
+
identifiers[:ordinal] || identifiers[:doi])
|
156
160
|
@anchors[ref["id"]] = { xref: reference }
|
157
161
|
end
|
158
162
|
end
|
data/spec/isodoc/blocks_spec.rb
CHANGED
@@ -1752,7 +1752,7 @@ RSpec.describe IsoDoc do
|
|
1752
1752
|
</foreword></preface>
|
1753
1753
|
<bibliography><references id="_bibliography" obligation="informative" normative="false" displayorder='2'>
|
1754
1754
|
<title depth='1'>Bibliography</title>
|
1755
|
-
<bibitem id="rfc2616" type="standard"> <fetched>2020-03-27</fetched> <title format="text/plain" language="en" script="Latn">Hypertext Transfer Protocol — HTTP/1.1</title> <uri type="xml">https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2616.xml</uri> <uri type="src">https://www.rfc-editor.org/info/rfc2616</uri>
|
1755
|
+
<bibitem id="rfc2616" type="standard"> <fetched>2020-03-27</fetched> <title format="text/plain" language="en" script="Latn">Hypertext Transfer Protocol — HTTP/1.1</title> <uri type="xml">https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2616.xml</uri> <uri type="src">https://www.rfc-editor.org/info/rfc2616</uri> <docidentifier type='metanorma-ordinal'>[1]</docidentifier> <docidentifier type="IETF">IETF RFC 2616</docidentifier> <docidentifier type="rfc-anchor">RFC2616</docidentifier> <docidentifier type="DOI">DOI 10.17487/RFC2616</docidentifier> <date type="published"> <on>1999-06</on> </date> <contributor> <role type="author"/> <person> <name> <completename language="en">R. Fielding</completename> </name> <affiliation> <organization> <name>IETF</name> <abbreviation>IETF</abbreviation> </organization> </affiliation> </person> </contributor> <contributor> <role type="author"/> <person> <name> <completename language="en">J. Gettys</completename> </name> <affiliation> <organization> <name>IETF</name> <abbreviation>IETF</abbreviation> </organization> </affiliation> </person> </contributor> <contributor> <role type="author"/> <person> <name> <completename language="en">J. Mogul</completename> </name> <affiliation> <organization> <name>IETF</name> <abbreviation>IETF</abbreviation> </organization> </affiliation> </person> </contributor> <contributor> <role type="author"/> <person> <name> <completename language="en">H. Frystyk</completename> </name> <affiliation> <organization> <name>IETF</name> <abbreviation>IETF</abbreviation> </organization> </affiliation> </person> </contributor> <contributor> <role type="author"/> <person> <name> <completename language="en">L. Masinter</completename> </name> <affiliation> <organization> <name>IETF</name> <abbreviation>IETF</abbreviation> </organization> </affiliation> </person> </contributor> <contributor> <role type="author"/> <person> <name> <completename language="en">P. Leach</completename> </name> <affiliation> <organization> <name>IETF</name> <abbreviation>IETF</abbreviation> </organization> </affiliation> </person> </contributor> <contributor> <role type="author"/> <person> <name> <completename language="en">T. Berners-Lee</completename> </name> <affiliation> <organization> <name>IETF</name> <abbreviation>IETF</abbreviation> </organization> </affiliation> </person> </contributor> <language>en</language> <script>Latn</script> <abstract format="text/plain" language="en" script="Latn">HTTP has been in use by the World-Wide Web global information initiative since 1990. This specification defines the protocol referred to as “HTTP/1.1”, and is an update to RFC 2068. [STANDARDS-TRACK]</abstract> <series type="main"> <title format="text/plain" language="en" script="Latn">RFC</title> <number>2616</number> </series> <place>Fremont, CA</place></bibitem>
|
1756
1756
|
</references></bibliography>
|
1757
1757
|
</iso-standard>
|
1758
1758
|
OUTPUT
|
@@ -2518,6 +2518,7 @@ RSpec.describe IsoDoc do
|
|
2518
2518
|
<bibliography>
|
2519
2519
|
<references hidden='true' normative='false' displayorder="1">
|
2520
2520
|
<bibitem id='express_action_schema' type='internal'>
|
2521
|
+
<docidentifier type='metanorma-ordinal'>[1]</docidentifier>
|
2521
2522
|
<docidentifier type='repository'>express/action_schema</docidentifier>
|
2522
2523
|
</bibitem>
|
2523
2524
|
</references>
|
@@ -474,6 +474,33 @@ RSpec.describe IsoDoc do
|
|
474
474
|
OUTPUT
|
475
475
|
end
|
476
476
|
|
477
|
+
=begin
|
478
|
+
it "populates HTML ToC" do
|
479
|
+
FileUtils.rm_f "test.doc"
|
480
|
+
FileUtils.rm_f "test.html"
|
481
|
+
IsoDoc::HtmlConvert.new({ htmltoclevels: 3 })
|
482
|
+
.convert("test", <<~"INPUT", false)
|
483
|
+
<iso-standard xmlns="http://riboseinc.com/isoxml">
|
484
|
+
<preface><foreword><title>Foreword</title>
|
485
|
+
<variant-title type="toc">FORVORT</variant-title>
|
486
|
+
</foreword></preface>
|
487
|
+
<sections>
|
488
|
+
<clause><title>First Clause</title>
|
489
|
+
<clause><title>First Subclause</title>
|
490
|
+
<variant-title type="toc">SUBCLOZ</variant-title>
|
491
|
+
</clause>
|
492
|
+
</clause>
|
493
|
+
</sections>
|
494
|
+
</iso-standard>
|
495
|
+
INPUT
|
496
|
+
html = Nokogiri::XML(File.read("test.html")).
|
497
|
+
at("//div[@id = 'toc']")
|
498
|
+
expect(xmlpp(html)).to be_equivalent_to xmlpp(<<~OUTPUT)
|
499
|
+
HAJSHJAS
|
500
|
+
OUTPUT
|
501
|
+
end
|
502
|
+
=end
|
503
|
+
|
477
504
|
it "populates Word ToC" do
|
478
505
|
FileUtils.rm_f "test.doc"
|
479
506
|
IsoDoc::WordConvert.new(
|
@@ -495,6 +522,7 @@ RSpec.describe IsoDoc do
|
|
495
522
|
</fn></p>
|
496
523
|
<clause id="P" inline-header="false" obligation="normative">
|
497
524
|
<title>Clause 4.2.1</title>
|
525
|
+
<variant-title type="toc">SUBCLOZ</variant-title>
|
498
526
|
</clause>
|
499
527
|
</clause></clause>
|
500
528
|
</sections>
|