isodoc 1.8.3.2 → 2.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +3 -31
- data/Gemfile +0 -1
- data/lib/isodoc/base_style/all.css +9 -0
- data/lib/isodoc/base_style/reset.css +9 -0
- data/lib/isodoc/base_style/reset.scss +11 -0
- data/lib/isodoc/class_utils.rb +18 -6
- data/lib/isodoc/convert.rb +8 -1
- data/lib/isodoc/function/blocks.rb +4 -1
- data/lib/isodoc/function/references.rb +32 -23
- data/lib/isodoc/function/section_titles.rb +6 -1
- data/lib/isodoc/function/to_word_html.rb +3 -3
- data/lib/isodoc/function/utils.rb +13 -14
- data/lib/isodoc/headlesshtml_convert.rb +1 -1
- data/lib/isodoc/html_convert.rb +1 -1
- data/lib/isodoc/html_function/postprocess.rb +9 -2
- data/lib/isodoc/i18n.rb +6 -3
- data/lib/isodoc/pdf_convert.rb +1 -1
- data/lib/isodoc/presentation_function/bibdata.rb +0 -6
- data/lib/isodoc/presentation_function/section.rb +40 -4
- data/lib/isodoc/presentation_function/terms.rb +25 -20
- data/lib/isodoc/presentation_xml_convert.rb +1 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/xref/xref_sect_gen.rb +7 -3
- data/lib/isodoc/xslfo_convert.rb +1 -5
- data/spec/isodoc/blocks_spec.rb +3 -2
- data/spec/isodoc/postproc_spec.rb +46 -16
- data/spec/isodoc/presentation_xml_spec.rb +208 -37
- data/spec/isodoc/ref_spec.rb +332 -300
- data/spec/isodoc/section_spec.rb +713 -601
- data/spec/isodoc/utils_spec.rb +57 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cf2e2e18bcb28744fc2f4cf2525267935dc981281ab4642c7b0e57ea8b68b6d
|
4
|
+
data.tar.gz: 12f9afbb69bd5e9903dd15ace22e5a3357520dfc8c58e4a316bc8e92a42e34bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3996461e5a31740161f1bf08c0305b7e9faa229f263da26deaaf9fd50924c9cb39f2eaffacf4b6e69992a197d81c10b130a82b06d0c630917b3c22b34eca615
|
7
|
+
data.tar.gz: 7c3a9fe8073d10c915e56f06bf973b6e7dfbd2e6296604598d93b90267496f74ebf5cbb2bcfd970eafafc0c808dc69e9273b0a1e1975a459e32993bfe0f57de6
|
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 }}
|
data/Gemfile
CHANGED
@@ -68,6 +68,12 @@ code *, pre *, tt *, kbd *, samp * {
|
|
68
68
|
font-family: {{monospacefont}} !important;
|
69
69
|
font-variant-ligatures: none; }
|
70
70
|
|
71
|
+
p code, dt code, li code, label code, legend code, caption code, th code, td code,
|
72
|
+
p tt, dt tt, li tt, label tt, legend tt, caption tt, th tt, td tt,
|
73
|
+
p kbd, dt kbd, li kbd, label kbd, legend kbd, caption kbd, th kbd, td kbd,
|
74
|
+
p samp, dt samp, li samp, label samp, legend samp, caption samp, th samp, td samp {
|
75
|
+
font-size: {{monospacefontsize}}; }
|
76
|
+
|
71
77
|
article, aside, details, figcaption, figure,
|
72
78
|
footer, header, hgroup, menu, nav, section {
|
73
79
|
display: block; }
|
@@ -79,6 +85,9 @@ table {
|
|
79
85
|
h1, h2, h3, h4, h5, h6 {
|
80
86
|
font-family: {{headerfont}}; }
|
81
87
|
|
88
|
+
.h1, .h2, .h3, .h4, .h5, .h6 {
|
89
|
+
font-family: {{headerfont}}; }
|
90
|
+
|
82
91
|
blockquote, q {
|
83
92
|
quotes: none; }
|
84
93
|
blockquote:before, blockquote:after, q:before, q:after {
|
@@ -68,6 +68,12 @@ code *, pre *, tt *, kbd *, samp * {
|
|
68
68
|
font-family: {{monospacefont}} !important;
|
69
69
|
font-variant-ligatures: none; }
|
70
70
|
|
71
|
+
p code, dt code, li code, label code, legend code, caption code, th code, td code,
|
72
|
+
p tt, dt tt, li tt, label tt, legend tt, caption tt, th tt, td tt,
|
73
|
+
p kbd, dt kbd, li kbd, label kbd, legend kbd, caption kbd, th kbd, td kbd,
|
74
|
+
p samp, dt samp, li samp, label samp, legend samp, caption samp, th samp, td samp {
|
75
|
+
font-size: {{monospacefontsize}}; }
|
76
|
+
|
71
77
|
article, aside, details, figcaption, figure,
|
72
78
|
footer, header, hgroup, menu, nav, section {
|
73
79
|
display: block; }
|
@@ -79,6 +85,9 @@ table {
|
|
79
85
|
h1, h2, h3, h4, h5, h6 {
|
80
86
|
font-family: {{headerfont}}; }
|
81
87
|
|
88
|
+
.h1, .h2, .h3, .h4, .h5, .h6 {
|
89
|
+
font-family: {{headerfont}}; }
|
90
|
+
|
82
91
|
blockquote, q {
|
83
92
|
quotes: none; }
|
84
93
|
blockquote:before, blockquote:after, q:before, q:after {
|
@@ -74,6 +74,13 @@ code *, pre *, tt *, kbd *, samp * {
|
|
74
74
|
font-variant-ligatures: none;
|
75
75
|
}
|
76
76
|
|
77
|
+
p code, dt code, li code, label code, legend code, caption code, th code, td code,
|
78
|
+
p tt, dt tt, li tt, label tt, legend tt, caption tt, th tt, td tt,
|
79
|
+
p kbd, dt kbd, li kbd, label kbd, legend kbd, caption kbd, th kbd, td kbd,
|
80
|
+
p samp, dt samp, li samp, label samp, legend samp, caption samp, th samp, td samp {
|
81
|
+
font-size: $monospacefontsize;
|
82
|
+
}
|
83
|
+
|
77
84
|
article, aside, details, figcaption, figure,
|
78
85
|
footer, header, hgroup, menu, nav, section {
|
79
86
|
display: block;
|
@@ -88,6 +95,10 @@ h1, h2, h3, h4, h5, h6 {
|
|
88
95
|
font-family: $headerfont;
|
89
96
|
}
|
90
97
|
|
98
|
+
.h1, .h2, .h3, .h4, .h5, .h6 {
|
99
|
+
font-family: $headerfont;
|
100
|
+
}
|
101
|
+
|
91
102
|
blockquote, q {
|
92
103
|
quotes: none;
|
93
104
|
|
data/lib/isodoc/class_utils.rb
CHANGED
@@ -28,25 +28,37 @@ module IsoDoc
|
|
28
28
|
Liquid::Template.parse(doc)
|
29
29
|
end
|
30
30
|
|
31
|
-
def case_strict(text, casing, script)
|
31
|
+
def case_strict(text, casing, script, firstonly: true)
|
32
32
|
return text unless %w(Latn Cyrl Grek Armn).include?(script)
|
33
33
|
|
34
|
-
|
34
|
+
seen = false
|
35
|
+
text.split(/(\s+)/).map do |w|
|
36
|
+
letters = w.chars
|
37
|
+
case_strict1(letters, casing) if !seen || !firstonly
|
38
|
+
seen ||= /\S/.match?(w)
|
39
|
+
letters.join
|
40
|
+
end.join
|
41
|
+
end
|
42
|
+
|
43
|
+
def case_strict1(letters, casing)
|
44
|
+
return letters if letters.empty?
|
45
|
+
|
35
46
|
case casing
|
36
47
|
when "capital" then letters.first.upcase!
|
37
48
|
when "lowercase" then letters.first.downcase!
|
49
|
+
when "allcaps" then letters.map(&:upcase!)
|
38
50
|
end
|
39
|
-
letters.join
|
40
51
|
end
|
41
52
|
|
42
|
-
def case_with_markup(linkend, casing, script)
|
53
|
+
def case_with_markup(linkend, casing, script, firstonly: true)
|
43
54
|
seen = false
|
44
55
|
xml = Nokogiri::XML("<root>#{linkend}</root>")
|
45
56
|
xml.traverse do |b|
|
46
57
|
next unless b.text? && !seen
|
47
58
|
|
48
|
-
b.replace(Common::case_strict(b.text, casing, script
|
49
|
-
|
59
|
+
b.replace(Common::case_strict(b.text, casing, script,
|
60
|
+
firstonly: firstonly))
|
61
|
+
seen = true if firstonly
|
50
62
|
end
|
51
63
|
xml.root.children.to_xml
|
52
64
|
end
|
data/lib/isodoc/convert.rb
CHANGED
@@ -5,6 +5,7 @@ require "fileutils"
|
|
5
5
|
require "tempfile"
|
6
6
|
require_relative "i18n"
|
7
7
|
require_relative "css"
|
8
|
+
require "securerandom"
|
8
9
|
|
9
10
|
module IsoDoc
|
10
11
|
class Convert < ::IsoDoc::Common
|
@@ -103,10 +104,16 @@ module IsoDoc
|
|
103
104
|
@fn_bookmarks = {}
|
104
105
|
@baseassetpath = options[:baseassetpath]
|
105
106
|
@aligncrosselements = options[:aligncrosselements]
|
107
|
+
@tmpimagedir_suffix = tmpimagedir_suffix
|
108
|
+
@tmpfilesdir_suffix = tmpfilesdir_suffix
|
106
109
|
end
|
107
110
|
|
108
111
|
def tmpimagedir_suffix
|
109
|
-
"_images"
|
112
|
+
"_#{SecureRandom.hex(8)}_images"
|
113
|
+
end
|
114
|
+
|
115
|
+
def tmpfilesdir_suffix
|
116
|
+
"_#{SecureRandom.hex(8)}_files"
|
110
117
|
end
|
111
118
|
|
112
119
|
def html_doc_path(*file)
|
@@ -174,10 +174,13 @@ module IsoDoc
|
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
177
|
-
def para_class(
|
177
|
+
def para_class(node)
|
178
178
|
classtype = nil
|
179
179
|
classtype = "MsoCommentText" if in_comment
|
180
180
|
classtype = "Sourcecode" if @annotation
|
181
|
+
if node["type"] == "floating-title"
|
182
|
+
classtype = "h#{node['depth']}"
|
183
|
+
end
|
181
184
|
classtype
|
182
185
|
end
|
183
186
|
|
@@ -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)
|
@@ -89,7 +98,7 @@ module IsoDoc
|
|
89
98
|
def omit_docid_prefix(prefix)
|
90
99
|
return true if prefix.nil? || prefix.empty?
|
91
100
|
|
92
|
-
%w(ISO IEC IEV ITU W3C csd metanorma repository
|
101
|
+
%w(ISO IEC IEV ITU W3C csd metanorma repository metanorma-ordinal)
|
93
102
|
.include? prefix
|
94
103
|
end
|
95
104
|
|
@@ -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
|
@@ -30,7 +30,7 @@ module IsoDoc
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def init_dir(filename, debug)
|
33
|
-
dir = "#{filename}
|
33
|
+
dir = "#{filename}#{@tmpfilesdir_suffix}"
|
34
34
|
unless debug
|
35
35
|
Dir.mkdir(dir, 0o777) unless File.exists?(dir)
|
36
36
|
FileUtils.rm_rf "#{dir}/*"
|
@@ -40,11 +40,11 @@ module IsoDoc
|
|
40
40
|
|
41
41
|
# tmp image dir is same directory as @filename
|
42
42
|
def tmpimagedir
|
43
|
-
@filename + tmpimagedir_suffix
|
43
|
+
@filename + @tmpimagedir_suffix
|
44
44
|
end
|
45
45
|
|
46
46
|
def rel_tmpimagedir
|
47
|
-
Pathname.new(@filename).basename.to_s + tmpimagedir_suffix
|
47
|
+
Pathname.new(@filename).basename.to_s + @tmpimagedir_suffix
|
48
48
|
end
|
49
49
|
|
50
50
|
# isodoc.css overrides any CSS injected by Html2Doc, which
|
@@ -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"])
|
@@ -142,9 +143,9 @@ module IsoDoc
|
|
142
143
|
|
143
144
|
def header_strip_elem?(elem)
|
144
145
|
elem.name == "img" ||
|
145
|
-
elem.name == "span" && elem["class"] == "MsoCommentReference" ||
|
146
|
-
elem.name == "a" && elem["class"] == "FootnoteRef" ||
|
147
|
-
elem.name == "span" && /mso-bookmark/.match(elem["style"])
|
146
|
+
(elem.name == "span" && elem["class"] == "MsoCommentReference") ||
|
147
|
+
(elem.name == "a" && elem["class"] == "FootnoteRef") ||
|
148
|
+
(elem.name == "span" && /mso-bookmark/.match(elem["style"]))
|
148
149
|
end
|
149
150
|
|
150
151
|
def liquid(doc)
|
@@ -192,12 +193,6 @@ module IsoDoc
|
|
192
193
|
save_dataimage(img["src"], false)
|
193
194
|
when %r{^([A-Z]:)?/}
|
194
195
|
img["src"]
|
195
|
-
=begin
|
196
|
-
if /^data:/.match? img["src"]
|
197
|
-
save_dataimage(img["src"], false)
|
198
|
-
elsif %r{^([A-Z]:)?/}.match? img["src"]
|
199
|
-
img["src"]
|
200
|
-
=end
|
201
196
|
else
|
202
197
|
File.join(@localdir, img["src"])
|
203
198
|
end
|
@@ -213,12 +208,16 @@ module IsoDoc
|
|
213
208
|
application/x-msmetafile image/x-xbitmap).include? type
|
214
209
|
end
|
215
210
|
|
216
|
-
def cleanup_entities(text)
|
211
|
+
def cleanup_entities(text, is_xml: true)
|
217
212
|
c = HTMLEntities.new
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
213
|
+
if is_xml
|
214
|
+
text.split(/([<>])/).each_slice(4).map do |a|
|
215
|
+
a[0] = c.encode(c.decode(a[0]), :hexadecimal)
|
216
|
+
a
|
217
|
+
end.join
|
218
|
+
else
|
219
|
+
c.encode(c.decode(text), :hexadecimal)
|
220
|
+
end
|
222
221
|
end
|
223
222
|
|
224
223
|
def external_path(path)
|
data/lib/isodoc/html_convert.rb
CHANGED
@@ -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
|
data/lib/isodoc/i18n.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "yaml"
|
2
|
+
require_relative "function/utils"
|
2
3
|
|
3
4
|
module IsoDoc
|
4
5
|
class I18n
|
@@ -17,7 +18,7 @@ module IsoDoc
|
|
17
18
|
end
|
18
19
|
ret
|
19
20
|
when Array then ret.map { |n| normalise_hash(n) }
|
20
|
-
when String then ret.unicode_normalize(:nfc)
|
21
|
+
when String then cleanup_entities(ret.unicode_normalize(:nfc))
|
21
22
|
else ret
|
22
23
|
end
|
23
24
|
end
|
@@ -96,8 +97,9 @@ module IsoDoc
|
|
96
97
|
xml.traverse do |n|
|
97
98
|
next unless n.text?
|
98
99
|
|
99
|
-
n.replace(n.text.gsub(/ /, "").gsub(/:/, ":")
|
100
|
-
.gsub(
|
100
|
+
n.replace(cleanup_entities(n.text.gsub(/ /, "").gsub(/:/, ":")
|
101
|
+
.gsub(/,/, "、").gsub(/\(/, "(").gsub(/\)/, ")")
|
102
|
+
.gsub(/\[/, "【").gsub(/\]/, "】"), is_xml: false))
|
101
103
|
end
|
102
104
|
xml.to_xml.gsub(/<b>/, "").gsub("</b>", "").gsub(/<\?[^>]+>/, "")
|
103
105
|
end
|
@@ -111,6 +113,7 @@ module IsoDoc
|
|
111
113
|
l10n(names[0..-2].join(", ") + " #{andword} #{names[-1]}", @lang, @script)
|
112
114
|
end
|
113
115
|
|
116
|
+
include Function::Utils
|
114
117
|
# module_function :l10n
|
115
118
|
end
|
116
119
|
end
|
data/lib/isodoc/pdf_convert.rb
CHANGED
@@ -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"))
|
@@ -19,6 +19,22 @@ module IsoDoc
|
|
19
19
|
prefix_name(elem, "<tab/>", "#{lbl}#{clausedelim}", "title")
|
20
20
|
end
|
21
21
|
|
22
|
+
def floattitle(docxml)
|
23
|
+
docxml.xpath(ns("//clause | //annex | //appendix | //introduction | "\
|
24
|
+
"//foreword | //preface/abstract | //acknowledgements | "\
|
25
|
+
"//terms | //definitions | //references"))
|
26
|
+
.each do |f|
|
27
|
+
floattitle1(f)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def floattitle1(elem)
|
32
|
+
elem.xpath(ns(".//floating-title")).each do |p|
|
33
|
+
p.name = "p"
|
34
|
+
p["type"] = "floating-title"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
22
38
|
def annex(docxml)
|
23
39
|
docxml.xpath(ns("//annex")).each do |f|
|
24
40
|
annex1(f)
|
@@ -44,7 +60,29 @@ module IsoDoc
|
|
44
60
|
prefix_name(elem, "", "#{lbl}#{clausedelim}", "name")
|
45
61
|
end
|
46
62
|
|
47
|
-
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
|
48
86
|
|
49
87
|
def docid_prefixes(docxml)
|
50
88
|
docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
|
@@ -86,9 +124,7 @@ module IsoDoc
|
|
86
124
|
display_order_xpath(docxml, "//indexsect", i)
|
87
125
|
end
|
88
126
|
|
89
|
-
def clausetitle(docxml)
|
90
|
-
docxml.xpath(ns("//variant-title[@type = 'toc']")).each(&:remove)
|
91
|
-
end
|
127
|
+
def clausetitle(docxml); end
|
92
128
|
|
93
129
|
def toc(docxml)
|
94
130
|
docxml.xpath(ns("//toc//xref[text()]")).each do |x|
|