isodoc 1.6.2 → 1.6.7
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 +2 -12
- data/.hound.yml +3 -1
- data/.rubocop.yml +4 -6
- data/Rakefile +2 -2
- data/isodoc.gemspec +3 -2
- data/lib/isodoc-yaml/i18n-en.yaml +1 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +1 -0
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +1 -0
- data/lib/isodoc.rb +0 -2
- data/lib/isodoc/convert.rb +7 -1
- data/lib/isodoc/function/blocks.rb +5 -4
- data/lib/isodoc/function/cleanup.rb +52 -43
- data/lib/isodoc/function/inline.rb +7 -7
- data/lib/isodoc/function/references.rb +32 -51
- data/lib/isodoc/function/section.rb +28 -16
- data/lib/isodoc/function/table.rb +21 -22
- data/lib/isodoc/function/terms.rb +6 -7
- data/lib/isodoc/function/to_word_html.rb +6 -3
- data/lib/isodoc/function/utils.rb +181 -163
- data/lib/isodoc/gem_tasks.rb +8 -9
- data/lib/isodoc/headlesshtml_convert.rb +8 -7
- data/lib/isodoc/html_convert.rb +5 -1
- data/lib/isodoc/html_function/comments.rb +14 -12
- data/lib/isodoc/html_function/footnotes.rb +14 -7
- data/lib/isodoc/html_function/html.rb +30 -26
- data/lib/isodoc/html_function/postprocess.rb +191 -182
- data/lib/isodoc/html_function/sectionsplit.rb +230 -0
- data/lib/isodoc/metadata.rb +22 -20
- data/lib/isodoc/metadata_contributor.rb +31 -28
- data/lib/isodoc/pdf_convert.rb +11 -13
- data/lib/isodoc/presentation_function/bibdata.rb +61 -30
- data/lib/isodoc/presentation_function/inline.rb +34 -27
- data/lib/isodoc/presentation_function/section.rb +54 -19
- data/lib/isodoc/presentation_xml_convert.rb +2 -0
- data/lib/isodoc/sassc_importer.rb +1 -1
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/postprocess.rb +50 -36
- data/lib/isodoc/xref.rb +2 -0
- data/lib/isodoc/xref/xref_counter.rb +1 -2
- data/lib/isodoc/xref/xref_gen.rb +21 -14
- data/lib/isodoc/xref/xref_gen_seq.rb +60 -35
- data/lib/isodoc/xref/xref_sect_gen.rb +15 -15
- data/spec/assets/scripts_override.html +3 -0
- data/spec/isodoc/blocks_spec.rb +624 -997
- data/spec/isodoc/cleanup_spec.rb +40 -42
- data/spec/isodoc/i18n_spec.rb +694 -821
- data/spec/isodoc/inline_spec.rb +482 -328
- data/spec/isodoc/metadata_spec.rb +384 -379
- data/spec/isodoc/postproc_spec.rb +163 -55
- data/spec/isodoc/presentation_xml_spec.rb +355 -278
- data/spec/isodoc/ref_spec.rb +5 -5
- data/spec/isodoc/section_spec.rb +216 -199
- data/spec/isodoc/sectionsplit_spec.rb +190 -0
- data/spec/isodoc/table_spec.rb +41 -42
- data/spec/isodoc/terms_spec.rb +84 -84
- data/spec/isodoc/xref_spec.rb +974 -932
- metadata +22 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffc474474290bb4fbd16f4e488e94366bd18e22d19c8041fbc5a01858fefb346
|
4
|
+
data.tar.gz: 753d8c7b604eb1afe6eaea153e58d1eec4a249676eec23b480181566a9f37557
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68977dc8fe66bc0d62cce9676dc55479a0789bcf68e6d5e0f12f2e7d586c777b1d37be754385fb71856ba80fa9aca60d2d3dbadeeee6f9ecbb7b47660c2fb57f
|
7
|
+
data.tar.gz: 54a4312fb6b6b353146e28a7844e7e0daaf77a19d5754c34e520d0514f8c73610be103986b61140b3605fa3d7bd6851f2c27eefe6c3101723e624fd87fead776
|
data/.github/workflows/rake.yml
CHANGED
@@ -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
|
data/Rakefile
CHANGED
data/isodoc.gemspec
CHANGED
@@ -26,14 +26,14 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
spec.files = `git ls-files`.split("\n")
|
28
28
|
spec.test_files = `git ls-files -- {spec}/*`.split("\n")
|
29
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
29
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
30
30
|
|
31
31
|
spec.add_dependency "asciimath"
|
32
32
|
spec.add_dependency "html2doc", "~> 1.1.1"
|
33
33
|
spec.add_dependency "htmlentities", "~> 4.3.4"
|
34
34
|
spec.add_dependency "liquid", "~> 4"
|
35
35
|
spec.add_dependency "metanorma", ">= 1.2.0"
|
36
|
-
spec.add_dependency "nokogiri", "~> 1.
|
36
|
+
spec.add_dependency "nokogiri", "~> 1.11.0"
|
37
37
|
spec.add_dependency "relaton-cli"
|
38
38
|
spec.add_dependency "roman-numerals"
|
39
39
|
spec.add_dependency "thread_safe"
|
@@ -50,5 +50,6 @@ Gem::Specification.new do |spec|
|
|
50
50
|
spec.add_development_dependency "rubocop", "~> 1.5.2"
|
51
51
|
spec.add_development_dependency "sassc", "~> 2.4.0"
|
52
52
|
spec.add_development_dependency "simplecov", "~> 0.15"
|
53
|
+
spec.add_development_dependency "metanorma-iso"
|
53
54
|
spec.add_development_dependency "timecop", "~> 0.9"
|
54
55
|
end
|
data/lib/isodoc.rb
CHANGED
@@ -8,7 +8,6 @@ require "mime/types"
|
|
8
8
|
require "image_size"
|
9
9
|
require "set"
|
10
10
|
require "pp"
|
11
|
-
require "uuidtools"
|
12
11
|
require "html2doc"
|
13
12
|
require "liquid"
|
14
13
|
require "htmlentities"
|
@@ -26,5 +25,4 @@ require "isodoc/xref"
|
|
26
25
|
require "isodoc/i18n"
|
27
26
|
|
28
27
|
module IsoDoc
|
29
|
-
|
30
28
|
end
|
data/lib/isodoc/convert.rb
CHANGED
@@ -32,10 +32,13 @@ module IsoDoc
|
|
32
32
|
# monospace: font to use for monospace text
|
33
33
|
# suppressheadingnumbers: suppress heading numbers for clauses
|
34
34
|
# scripts: Scripts file for HTML
|
35
|
+
# scripts_override: Override scripts file for HTML
|
35
36
|
# scripts_pdf: Scripts file for PDF (not used in XSLT PDF)
|
36
37
|
# datauriimage: Encode images in HTML output as data URIs
|
37
38
|
# break_up_urls_in_tables: whether to insert spaces in URLs in tables
|
38
39
|
# every 40-odd chars
|
40
|
+
# sectionsplit: split up HTML output on sections
|
41
|
+
# bare: do not insert any prefatory material (coverpage, boilerplate)
|
39
42
|
def initialize(options)
|
40
43
|
@libdir ||= File.dirname(__FILE__) # rubocop:disable Lint/DisjunctiveAssignmentInConstructor
|
41
44
|
options.merge!(default_fonts(options)) do |_, old, new|
|
@@ -64,12 +67,15 @@ module IsoDoc
|
|
64
67
|
@scripts = options[:scripts] ||
|
65
68
|
File.join(File.dirname(__FILE__), "base_style", "scripts.html")
|
66
69
|
@scripts_pdf = options[:scripts_pdf]
|
70
|
+
@scripts_override = options[:scripts_override]
|
67
71
|
@i18nyaml = options[:i18nyaml]
|
68
72
|
@ulstyle = options[:ulstyle]
|
69
73
|
@olstyle = options[:olstyle]
|
70
74
|
@datauriimage = options[:datauriimage]
|
71
75
|
@suppressheadingnumbers = options[:suppressheadingnumbers]
|
72
76
|
@break_up_urls_in_tables = options[:break_up_urls_in_tables] == "true"
|
77
|
+
@sectionsplit = options[:sectionsplit] == "true"
|
78
|
+
@bare = options[:bare]
|
73
79
|
@termdomain = ""
|
74
80
|
@termexample = false
|
75
81
|
@note = false
|
@@ -150,7 +156,7 @@ module IsoDoc
|
|
150
156
|
[docxml, filename, dir]
|
151
157
|
end
|
152
158
|
|
153
|
-
def convert(input_filename, file = nil, debug = false,
|
159
|
+
def convert(input_filename, file = nil, debug = false,
|
154
160
|
output_filename = nil)
|
155
161
|
file = File.read(input_filename, encoding: "utf-8") if file.nil?
|
156
162
|
@openmathdelim, @closemathdelim = extract_delims(file)
|
@@ -14,10 +14,11 @@ module IsoDoc::Function
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def figure_name_parse(
|
18
|
-
return if name.nil?
|
17
|
+
def figure_name_parse(_node, div, name)
|
18
|
+
return if name.nil?
|
19
|
+
|
19
20
|
div.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
|
20
|
-
name.children.each { |n| parse(n,
|
21
|
+
name.children.each { |n| parse(n, p) }
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
@@ -61,7 +62,7 @@ module IsoDoc::Function
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def sourcecode_name_parse(node, div, name)
|
64
|
-
return if name.nil?
|
65
|
+
return if name.nil?
|
65
66
|
|
66
67
|
div.p **{ class: "SourceTitle", style: "text-align:center;" } do |p|
|
67
68
|
name.children.each { |n| parse(n, p) }
|
@@ -1,16 +1,17 @@
|
|
1
1
|
module IsoDoc::Function
|
2
2
|
module Cleanup
|
3
3
|
def textcleanup(docxml)
|
4
|
-
|
4
|
+
termref_cleanup(passthrough_cleanup(docxml))
|
5
5
|
end
|
6
6
|
|
7
7
|
def termref_cleanup(docxml)
|
8
|
-
docxml
|
9
|
-
gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/,
|
10
|
-
|
11
|
-
gsub(
|
12
|
-
gsub(
|
13
|
-
gsub(
|
8
|
+
docxml
|
9
|
+
.gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/,
|
10
|
+
l10n(", #{@i18n.modified} [/TERMREF]"))
|
11
|
+
.gsub(%r{\s*\[/TERMREF\]\s*</p>\s*<p>\s*\[TERMREF\]}, "; ")
|
12
|
+
.gsub(/\[TERMREF\]\s*/, l10n("[#{@i18n.source}: "))
|
13
|
+
.gsub(%r{\s*\[/TERMREF\]\s*}, l10n("]"))
|
14
|
+
.gsub(/\s*\[MODIFICATION\]/, l10n(", #{@i18n.modified} — "))
|
14
15
|
end
|
15
16
|
|
16
17
|
def passthrough_cleanup(docxml)
|
@@ -21,7 +22,7 @@ module IsoDoc::Function
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def cleanup(docxml)
|
24
|
-
@i18n ||= i18n_init(@lang, @script)
|
25
|
+
@i18n ||= i18n_init(@lang, @script)
|
25
26
|
comment_cleanup(docxml)
|
26
27
|
footnote_cleanup(docxml)
|
27
28
|
inline_header_cleanup(docxml)
|
@@ -34,30 +35,36 @@ module IsoDoc::Function
|
|
34
35
|
|
35
36
|
def table_long_strings_cleanup(docxml)
|
36
37
|
return unless @break_up_urls_in_tables == true
|
38
|
+
|
37
39
|
docxml.xpath("//td | //th").each do |d|
|
38
40
|
d.traverse do |n|
|
39
41
|
next unless n.text?
|
42
|
+
|
40
43
|
n.replace(HTMLEntities.new.encode(
|
41
|
-
|
44
|
+
break_up_long_strings(n.text),
|
45
|
+
))
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
|
-
def break_up_long_strings(
|
47
|
-
return
|
48
|
-
|
49
|
-
|
50
|
+
def break_up_long_strings(text)
|
51
|
+
return text if /^\s*$/.match?(text)
|
52
|
+
|
53
|
+
text.split(/(?=\s)/).map do |w|
|
54
|
+
if /^\s*$/.match(text) || (w.size < 30) then w
|
55
|
+
else
|
50
56
|
w.scan(/.{,30}/).map do |w1|
|
51
|
-
|
52
|
-
|
57
|
+
w1.size < 30 ? w1 : break_up_long_strings1(w1)
|
58
|
+
end.join
|
59
|
+
end
|
53
60
|
end.join
|
54
61
|
end
|
55
62
|
|
56
|
-
def break_up_long_strings1(
|
57
|
-
s =
|
58
|
-
if s.size == 1 then
|
63
|
+
def break_up_long_strings1(text)
|
64
|
+
s = text.split(%r{(?<=[,.?+;/=])})
|
65
|
+
if s.size == 1 then "#{text} "
|
59
66
|
else
|
60
|
-
s[-1] = "
|
67
|
+
s[-1] = " #{s[-1]}"
|
61
68
|
s.join
|
62
69
|
end
|
63
70
|
end
|
@@ -78,11 +85,11 @@ module IsoDoc::Function
|
|
78
85
|
docxml
|
79
86
|
end
|
80
87
|
|
81
|
-
def figure_get_or_make_dl(
|
82
|
-
dl =
|
88
|
+
def figure_get_or_make_dl(elem)
|
89
|
+
dl = elem.at(".//dl")
|
83
90
|
if dl.nil?
|
84
|
-
|
85
|
-
dl =
|
91
|
+
elem.add_child("<p><b>#{@i18n.key}</b></p><dl></dl>")
|
92
|
+
dl = elem.at(".//dl")
|
86
93
|
end
|
87
94
|
dl
|
88
95
|
end
|
@@ -91,10 +98,10 @@ module IsoDoc::Function
|
|
91
98
|
"//div[@class = 'figure'][descendant::aside]"\
|
92
99
|
"[not(descendant::div[@class = 'figure'])]".freeze
|
93
100
|
|
94
|
-
def figure_aside_process(
|
101
|
+
def figure_aside_process(elem, aside, key)
|
95
102
|
# get rid of footnote link, it is in diagram
|
96
|
-
|
97
|
-
fnref =
|
103
|
+
elem&.at("./a[@class='TableFootnoteRef']")&.remove
|
104
|
+
fnref = elem.at(".//span[@class='TableFootnoteRef']/..")
|
98
105
|
dt = key.add_child("<dt></dt>").first
|
99
106
|
dd = key.add_child("<dd></dd>").first
|
100
107
|
fnref.parent = dt
|
@@ -109,6 +116,7 @@ module IsoDoc::Function
|
|
109
116
|
def figure_cleanup(docxml)
|
110
117
|
docxml.xpath(FIGURE_WITH_FOOTNOTES).each do |f|
|
111
118
|
next unless f.at(".//aside[not(ancestor::p[@class = 'FigureTitle'])]")
|
119
|
+
|
112
120
|
key = figure_get_or_make_dl(f)
|
113
121
|
f.xpath(".//aside").each do |aside|
|
114
122
|
figure_aside_process(f, aside, key)
|
@@ -137,12 +145,13 @@ module IsoDoc::Function
|
|
137
145
|
docxml
|
138
146
|
end
|
139
147
|
|
140
|
-
def merge_fnref_into_fn_text(
|
141
|
-
fn =
|
148
|
+
def merge_fnref_into_fn_text(elem)
|
149
|
+
fn = elem.at('.//span[@class="TableFootnoteRef"]/..')
|
142
150
|
n = fn.next_element
|
143
151
|
n&.children&.first&.add_previous_sibling(fn.remove)
|
144
152
|
end
|
145
153
|
|
154
|
+
# preempt html2doc putting MsoNormal under TableFootnote class
|
146
155
|
def table_footnote_cleanup(docxml)
|
147
156
|
docxml.xpath("//table[descendant::aside]").each do |t|
|
148
157
|
t.xpath(".//aside").each do |a|
|
@@ -152,36 +161,36 @@ module IsoDoc::Function
|
|
152
161
|
t << a.remove
|
153
162
|
end
|
154
163
|
end
|
155
|
-
# preempt html2doc putting MsoNormal there
|
156
164
|
docxml.xpath("//p[not(self::*[@class])]"\
|
157
165
|
"[ancestor::*[@class = 'TableFootnote']]").each do |p|
|
158
166
|
p["class"] = "TableFootnote"
|
159
167
|
end
|
160
168
|
end
|
161
169
|
|
162
|
-
def remove_bottom_border(
|
163
|
-
|
164
|
-
|
170
|
+
def remove_bottom_border(cell)
|
171
|
+
cell["style"] =
|
172
|
+
cell["style"].gsub(/border-bottom:[^;]+;/, "border-bottom:0pt;")
|
165
173
|
end
|
166
174
|
|
167
|
-
def table_get_or_make_tfoot(
|
168
|
-
tfoot =
|
175
|
+
def table_get_or_make_tfoot(table)
|
176
|
+
tfoot = table.at(".//tfoot")
|
169
177
|
if tfoot.nil?
|
170
|
-
|
171
|
-
tfoot =
|
178
|
+
table.add_child("<tfoot></tfoot>")
|
179
|
+
tfoot = table.at(".//tfoot")
|
172
180
|
else
|
173
181
|
tfoot.xpath(".//td | .//th").each { |td| remove_bottom_border(td) }
|
174
182
|
end
|
175
183
|
tfoot
|
176
184
|
end
|
177
185
|
|
178
|
-
def new_fullcolspan_row(
|
186
|
+
def new_fullcolspan_row(table, tfoot)
|
179
187
|
# how many columns in the table?
|
180
188
|
cols = 0
|
181
|
-
|
189
|
+
table.at(".//tr").xpath("./td | ./th").each do |td|
|
182
190
|
cols += (td["colspan"] ? td["colspan"].to_i : 1)
|
183
191
|
end
|
184
|
-
style =
|
192
|
+
style =
|
193
|
+
%{border-top:0pt;border-bottom:#{IsoDoc::Function::Table::SW} 1.5pt;}
|
185
194
|
tfoot.add_child("<tr><td colspan='#{cols}' style='#{style}'/></tr>")
|
186
195
|
tfoot.xpath(".//td").last
|
187
196
|
end
|
@@ -206,12 +215,12 @@ module IsoDoc::Function
|
|
206
215
|
|
207
216
|
def symbols_cleanup(docxml); end
|
208
217
|
|
209
|
-
def table_footnote_reference_format(
|
210
|
-
|
218
|
+
def table_footnote_reference_format(link)
|
219
|
+
link
|
211
220
|
end
|
212
221
|
|
213
|
-
def footnote_reference_format(
|
214
|
-
|
222
|
+
def footnote_reference_format(link)
|
223
|
+
link
|
215
224
|
end
|
216
225
|
end
|
217
226
|
end
|
@@ -3,11 +3,12 @@ require_relative "inline_simple"
|
|
3
3
|
module IsoDoc::Function
|
4
4
|
module Inline
|
5
5
|
def link_parse(node, out)
|
6
|
-
|
6
|
+
url = node["target"]
|
7
|
+
node["updatetype"] == "true" and url = suffix_url(url)
|
8
|
+
out.a **attr_code(href: url, title: node["alt"]) do |l|
|
7
9
|
if node.text.empty?
|
8
10
|
l << node["target"].sub(/^mailto:/, "")
|
9
|
-
else
|
10
|
-
node.children.each { |n| parse(n, l) }
|
11
|
+
else node.children.each { |n| parse(n, l) }
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -79,8 +80,7 @@ module IsoDoc::Function
|
|
79
80
|
"#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}"\
|
80
81
|
"#{@closemathdelim}"
|
81
82
|
when "MathML" then node.first_element_child.to_s
|
82
|
-
else
|
83
|
-
HTMLEntities.new.encode(node.text)
|
83
|
+
else HTMLEntities.new.encode(node.text)
|
84
84
|
end
|
85
85
|
out.span **{ class: "stem" } do |span|
|
86
86
|
span.parent.add_child ooml
|
@@ -123,13 +123,13 @@ module IsoDoc::Function
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def add_parse(node, out)
|
126
|
-
out.span **{class: "addition"} do |e|
|
126
|
+
out.span **{ class: "addition" } do |e|
|
127
127
|
node.children.each { |n| parse(n, e) }
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
131
|
def del_parse(node, out)
|
132
|
-
out.span **{class: "deletion"} do |e|
|
132
|
+
out.span **{ class: "deletion" } do |e|
|
133
133
|
node.children.each { |n| parse(n, e) }
|
134
134
|
end
|
135
135
|
end
|