isodoc 2.4.2 → 2.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/isodoc/class_utils.rb +5 -2
- data/lib/isodoc/convert.rb +10 -3
- data/lib/isodoc/function/blocks.rb +5 -2
- data/lib/isodoc/function/inline_simple.rb +1 -1
- data/lib/isodoc/function/references.rb +17 -38
- data/lib/isodoc/function/section.rb +9 -9
- data/lib/isodoc/function/utils.rb +1 -1
- data/lib/isodoc/metadata.rb +1 -1
- data/lib/isodoc/presentation_function/bibdata.rb +3 -3
- data/lib/isodoc/presentation_function/block.rb +18 -9
- data/lib/isodoc/presentation_function/math.rb +15 -4
- data/lib/isodoc/presentation_function/refs.rb +0 -2
- data/lib/isodoc/presentation_function/section.rb +1 -1
- data/lib/isodoc/presentation_function/sourcecode.rb +27 -11
- data/lib/isodoc/presentation_function/terms.rb +8 -9
- data/lib/isodoc/presentation_xml_convert.rb +40 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +3 -3
- data/lib/isodoc/word_function/comments.rb +23 -18
- data/lib/isodoc/word_function/footnotes.rb +8 -8
- data/lib/isodoc/word_function/postprocess.rb +2 -70
- data/lib/isodoc/word_function/postprocess_table.rb +85 -0
- data/lib/isodoc/word_function/table.rb +32 -14
- data/lib/isodoc/xref/xref_anchor.rb +5 -3
- data/lib/isodoc/xref/xref_gen.rb +24 -11
- data/lib/isodoc/xref/xref_sect_gen.rb +1 -0
- data/lib/isodoc/xref.rb +1 -1
- data/lib/isodoc-yaml/i18n-ar.yaml +1 -0
- data/lib/isodoc-yaml/i18n-de.yaml +1 -0
- data/lib/isodoc-yaml/i18n-en.yaml +1 -0
- data/lib/isodoc-yaml/i18n-es.yaml +1 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +1 -0
- data/lib/isodoc-yaml/i18n-ru.yaml +1 -0
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +1 -0
- data/lib/isodoc.rb +2 -1
- data/lib/relaton/{render → render-isodoc}/config.yml +0 -0
- data/lib/relaton/{render → render-isodoc}/general.rb +0 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a2cc598b5e8c9690a42329b2af309d75d281db2767adc8fc00eb21a498f69cf
|
4
|
+
data.tar.gz: 1026ad146597f3e93b46f035506f648e7775bb0cf3e846d6f578d2af029dfb1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5923a84bcb2fa4ba407eae39adf36202ebd07902ec425274641717d38b00daea3e035c9c8f12a936f1c6f4126e3d38db68a5184dfe63718adbe08b8c6ed4046d
|
7
|
+
data.tar.gz: 36a2d61a352858557db3c8f8f097b590842bf148b0ffaf48fcf3a5dd45f0781dcfe929000de3704427d9bde7c1a2c74458f931c0976356e4594bb510631c66c7
|
data/lib/isodoc/class_utils.rb
CHANGED
@@ -76,8 +76,11 @@ module IsoDoc
|
|
76
76
|
|
77
77
|
# node is at the start of sentence in a Metanorma XML context
|
78
78
|
def start_of_sentence(node)
|
79
|
-
prec =
|
80
|
-
|
79
|
+
prec = [] # all text nodes before node
|
80
|
+
nearest_block_parent(node).traverse do |x|
|
81
|
+
x == node and break
|
82
|
+
x.text? and prec << x
|
83
|
+
end
|
81
84
|
prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map(&:text).join)
|
82
85
|
end
|
83
86
|
end
|
data/lib/isodoc/convert.rb
CHANGED
@@ -50,6 +50,8 @@ module IsoDoc
|
|
50
50
|
# fontlicenseagreement: fontist font license agreement
|
51
51
|
# modspecidentifierbase: base prefix for any Modspec identifiers
|
52
52
|
# sourcehighlighter: whether to apply sourcecode highlighting
|
53
|
+
# semantic_xml_insert: whether to insert into presentation XML
|
54
|
+
# a copy of semantic XML
|
53
55
|
def initialize(options) # rubocop:disable Lint/MissingSuper
|
54
56
|
@options = options_preprocess(options)
|
55
57
|
init_stylesheets(@options)
|
@@ -60,6 +62,7 @@ module IsoDoc
|
|
60
62
|
init_locations(@options)
|
61
63
|
init_i18n(@options)
|
62
64
|
init_rendering(@options)
|
65
|
+
init_arrangement(@options)
|
63
66
|
end
|
64
67
|
|
65
68
|
def options_preprocess(options)
|
@@ -77,14 +80,18 @@ module IsoDoc
|
|
77
80
|
@datauriimage = options[:datauriimage]
|
78
81
|
@suppressheadingnumbers = options[:suppressheadingnumbers]
|
79
82
|
@break_up_urls_in_tables = options[:breakupurlsintables]
|
80
|
-
@sectionsplit = options[:sectionsplit] == "true"
|
81
83
|
@suppressasciimathdup = options[:suppressasciimathdup]
|
82
|
-
@bare = options[:bare]
|
83
84
|
@aligncrosselements = options[:aligncrosselements]
|
84
85
|
@modspecidentifierbase = options[:modspecidentifierbase]
|
85
86
|
@sourcehighlighter = options[:sourcehighlighter]
|
86
87
|
end
|
87
88
|
|
89
|
+
def init_arrangement(options)
|
90
|
+
@sectionsplit = options[:sectionsplit] == "true"
|
91
|
+
@bare = options[:bare]
|
92
|
+
@semantic_xml_insert = options[:semanticxmlinsert] != "false"
|
93
|
+
end
|
94
|
+
|
88
95
|
def init_i18n(options)
|
89
96
|
@i18nyaml = options[:i18nyaml]
|
90
97
|
@lang = options[:language] || "en"
|
@@ -187,7 +194,7 @@ module IsoDoc
|
|
187
194
|
@xrefs.parse docxml
|
188
195
|
bibitem_lookup(docxml)
|
189
196
|
noko do |xml|
|
190
|
-
xml.html
|
197
|
+
xml.html lang: @lang.to_s do |html|
|
191
198
|
html.parent.add_namespace("epub", "http://www.idpf.org/2007/ops")
|
192
199
|
info docxml, nil
|
193
200
|
populate_css
|
@@ -82,8 +82,11 @@ module IsoDoc
|
|
82
82
|
|
83
83
|
def sourcecode_parse1(node, div)
|
84
84
|
@sourcecode = "pre"
|
85
|
-
node.at(ns(".//table
|
85
|
+
node.at(ns(".//table[@class = 'rouge-line-table']")) ||
|
86
|
+
node.at("./ancestor::xmlns:table[@class = 'rouge-line-table']") and
|
86
87
|
@sourcecode = "table"
|
88
|
+
# !node.ancestors("table").empty? and
|
89
|
+
# @sourcecode = "table"
|
87
90
|
node.children.each { |n| parse(n, div) unless n.name == "name" }
|
88
91
|
@sourcecode = false
|
89
92
|
end
|
@@ -96,7 +99,7 @@ module IsoDoc
|
|
96
99
|
@sourcecode = false
|
97
100
|
@annotation = true
|
98
101
|
out.div class: "annotation" do |div|
|
99
|
-
#node.at("./preceding-sibling::*[local-name() = 'annotation']") or
|
102
|
+
# node.at("./preceding-sibling::*[local-name() = 'annotation']") or
|
100
103
|
# div << "<br/>"
|
101
104
|
callout = node.at(ns("//callout[@target='#{node['id']}']"))
|
102
105
|
div << "<span class='c'><#{callout.text}></span> "
|
@@ -4,55 +4,35 @@ module IsoDoc
|
|
4
4
|
# This is highly specific to ISO, but it's not a bad precedent for
|
5
5
|
# references anyway; keeping here instead of in IsoDoc::Iso for now
|
6
6
|
def docid_l10n(text)
|
7
|
-
|
8
|
-
|
9
|
-
text.gsub(/
|
7
|
+
text.nil? and return text
|
8
|
+
@i18n.all_parts and text.gsub!(/All Parts/i, @i18n.all_parts.downcase)
|
9
|
+
text.size < 20 and text.gsub!(/ /, " ")
|
10
10
|
text
|
11
11
|
end
|
12
12
|
|
13
|
-
def nonstd_bibitem(list, bib, _ordinal, biblio)
|
13
|
+
def nonstd_bibitem(list, bib, _ordinal, biblio)
|
14
14
|
list.p **attr_code(iso_bibitem_entry_attrs(bib, biblio)) do |ref|
|
15
|
-
# ids = bibitem_ref_code(bib)
|
16
|
-
# idents = render_identifier(ids)
|
17
|
-
# if biblio then ref_entry_code(ref, ordinal, idents, ids)
|
18
|
-
# else
|
19
|
-
# ref << (idents[:ordinal] || idents[:metanorma] || idents[:sdo]).to_s
|
20
|
-
# ref << ", #{idents[sdo]}" if idents[:ordinal] && idents[:sdo]
|
21
|
-
# end
|
22
|
-
# ref << "," if idents[:sdo]
|
23
15
|
tag = bib.at(ns("./biblio-tag"))
|
24
16
|
tag&.children&.each { |n| parse(n, ref) }
|
25
17
|
reference_format(bib, ref)
|
26
18
|
end
|
27
19
|
end
|
28
20
|
|
29
|
-
def std_bibitem_entry(list, bib, _ordinal, biblio)
|
21
|
+
def std_bibitem_entry(list, bib, _ordinal, biblio)
|
30
22
|
list.p **attr_code(iso_bibitem_entry_attrs(bib, biblio)) do |ref|
|
31
|
-
# idents = render_identifier(bibitem_ref_code(bib))
|
32
|
-
# if biblio then ref_entry_code(ref, ordinal, idents, nil)
|
33
|
-
# else
|
34
|
-
# ref << (idents[:ordinal] || idents[:metanorma] || idents[:sdo]).to_s
|
35
|
-
# ref << ", #{idents[:sdo]}" if (idents[:ordinal] ||
|
36
|
-
# idents[:metanorma]) && idents[:sdo]
|
37
|
-
# end
|
38
|
-
# date_note_process(bib, ref)
|
39
|
-
# ref << "," if idents[:sdo]
|
40
23
|
tag = bib.at(ns("./biblio-tag"))
|
41
24
|
tag&.children&.each { |n| parse(n, ref) }
|
42
25
|
reference_format(bib, ref)
|
43
26
|
end
|
44
27
|
end
|
45
28
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# prefix_bracketed_ref(ref, ids[:ordinal] || ids[:metanorma] ||
|
50
|
-
# "[#{ordinal}]")
|
51
|
-
# ids[:sdo] and ref << (ids[:sdo]).to_s
|
52
|
-
# end
|
29
|
+
SKIP_DOCID = <<~XPATH.strip.freeze
|
30
|
+
@type = 'DOI' or @type = 'doi' or @type = 'ISSN' or @type = 'issn' or @type = 'ISBN' or @type = 'isbn' or starts-with(@type, 'ISSN.') or starts-with(@type, 'ISBN.') or starts-with(@type, 'issn.') or starts-with(@type, 'isbn.')
|
31
|
+
XPATH
|
53
32
|
|
54
|
-
|
55
|
-
|
33
|
+
SKIP_DOC1 = <<~XPATH.strip.freeze
|
34
|
+
#{SKIP_DOCID} or @type = 'metanorma-ordinal' or @type = 'metanorma'
|
35
|
+
XPATH
|
56
36
|
|
57
37
|
def pref_ref_code(bib)
|
58
38
|
bib["suppress_identifier"] == "true" and return nil
|
@@ -61,8 +41,8 @@ module IsoDoc
|
|
61
41
|
ret.empty? and
|
62
42
|
ret = bib.xpath(ns("./docidentifier[@primary = 'true']"))
|
63
43
|
ret.empty? and
|
64
|
-
ret = bib.at(ns("./docidentifier[not(#{
|
65
|
-
bib.at(ns("./docidentifier[not(#{
|
44
|
+
ret = bib.at(ns("./docidentifier[not(#{SKIP_DOC1})]#{lang}")) ||
|
45
|
+
bib.at(ns("./docidentifier[not(#{SKIP_DOC1})]"))
|
66
46
|
ret
|
67
47
|
end
|
68
48
|
|
@@ -70,8 +50,7 @@ module IsoDoc
|
|
70
50
|
def bibitem_ref_code(bib)
|
71
51
|
id = bib.at(ns("./docidentifier[@type = 'metanorma']"))
|
72
52
|
id1 = pref_ref_code(bib)
|
73
|
-
id2 = bib.at(ns("./docidentifier[
|
74
|
-
"@type = 'ISBN']"))
|
53
|
+
id2 = bib.at(ns("./docidentifier[#{SKIP_DOCID}]"))
|
75
54
|
id3 = bib.at(ns("./docidentifier[@type = 'metanorma-ordinal']"))
|
76
55
|
return [id, id1, id2, id3] if id || id1 || id2 || id3
|
77
56
|
return [nil, nil, nil, nil] if bib["suppress_identifier"] == "true"
|
@@ -139,9 +118,9 @@ module IsoDoc
|
|
139
118
|
|
140
119
|
def standard?(bib)
|
141
120
|
ret = false
|
142
|
-
drop = %w(metanorma DOI ISSN ISBN)
|
143
121
|
bib.xpath(ns("./docidentifier")).each do |id|
|
144
|
-
next if id["type"].nil? ||
|
122
|
+
next if id["type"].nil? ||
|
123
|
+
id.at(".//self::*[#{SKIP_DOCID} or @type = 'metanorma']")
|
145
124
|
|
146
125
|
ret = true
|
147
126
|
end
|
@@ -194,7 +173,7 @@ module IsoDoc
|
|
194
173
|
return
|
195
174
|
page_break(out)
|
196
175
|
out.div do |div|
|
197
|
-
div.h1
|
176
|
+
div.h1 class: "Section3" do |h1|
|
198
177
|
f.at(ns("./title"))&.children&.each { |c2| parse(c2, h1) }
|
199
178
|
end
|
200
179
|
biblio_list(f, div, true)
|
@@ -58,7 +58,7 @@ module IsoDoc
|
|
58
58
|
num
|
59
59
|
end
|
60
60
|
|
61
|
-
TERM_CLAUSE = "//sections/terms | "\
|
61
|
+
TERM_CLAUSE = "//sections/terms | " \
|
62
62
|
"//sections/clause[descendant::terms]".freeze
|
63
63
|
|
64
64
|
def terms_defs(isoxml, out, num)
|
@@ -100,7 +100,7 @@ module IsoDoc
|
|
100
100
|
def introduction(isoxml, out)
|
101
101
|
f = isoxml.at(ns("//introduction")) || return
|
102
102
|
page_break(out)
|
103
|
-
out.div
|
103
|
+
out.div class: "Section3", id: f["id"] do |div|
|
104
104
|
clause_name(nil, f.at(ns("./title")), div, { class: "IntroTitle" })
|
105
105
|
f.elements.each do |e|
|
106
106
|
parse(e, div) unless e.name == "title"
|
@@ -122,7 +122,7 @@ module IsoDoc
|
|
122
122
|
f = isoxml.at(ns("//acknowledgements")) || return
|
123
123
|
title_attr = { class: "IntroTitle" }
|
124
124
|
page_break(out)
|
125
|
-
out.div
|
125
|
+
out.div class: "Section3", id: f["id"] do |div|
|
126
126
|
clause_name(nil, f&.at(ns("./title")), div, title_attr)
|
127
127
|
f.elements.each do |e|
|
128
128
|
parse(e, div) unless e.name == "title"
|
@@ -140,10 +140,10 @@ module IsoDoc
|
|
140
140
|
end
|
141
141
|
|
142
142
|
def preface(isoxml, out)
|
143
|
-
isoxml.xpath(ns("//preface/clause | //preface/references | "\
|
143
|
+
isoxml.xpath(ns("//preface/clause | //preface/references | " \
|
144
144
|
"//preface/definitions | //preface/terms")).each do |f|
|
145
145
|
page_break(out)
|
146
|
-
out.div
|
146
|
+
out.div class: "Section3", id: f["id"] do |div|
|
147
147
|
clause_name(nil, f&.at(ns("./title")), div, { class: "IntroTitle" })
|
148
148
|
f.elements.each do |e|
|
149
149
|
parse(e, div) unless e.name == "title"
|
@@ -174,7 +174,7 @@ module IsoDoc
|
|
174
174
|
def copyright_parse(node, out)
|
175
175
|
return if @bare
|
176
176
|
|
177
|
-
out.div
|
177
|
+
out.div class: "boilerplate-copyright" do |div|
|
178
178
|
node.children.each { |n| parse(n, div) }
|
179
179
|
end
|
180
180
|
end
|
@@ -182,7 +182,7 @@ module IsoDoc
|
|
182
182
|
def license_parse(node, out)
|
183
183
|
return if @bare
|
184
184
|
|
185
|
-
out.div
|
185
|
+
out.div class: "boilerplate-license" do |div|
|
186
186
|
node.children.each { |n| parse(n, div) }
|
187
187
|
end
|
188
188
|
end
|
@@ -190,7 +190,7 @@ module IsoDoc
|
|
190
190
|
def legal_parse(node, out)
|
191
191
|
return if @bare
|
192
192
|
|
193
|
-
out.div
|
193
|
+
out.div class: "boilerplate-legal" do |div|
|
194
194
|
node.children.each { |n| parse(n, div) }
|
195
195
|
end
|
196
196
|
end
|
@@ -198,7 +198,7 @@ module IsoDoc
|
|
198
198
|
def feedback_parse(node, out)
|
199
199
|
return if @bare
|
200
200
|
|
201
|
-
out.div
|
201
|
+
out.div class: "boilerplate-feedback" do |div|
|
202
202
|
node.children.each { |n| parse(n, div) }
|
203
203
|
end
|
204
204
|
end
|
data/lib/isodoc/metadata.rb
CHANGED
@@ -170,7 +170,7 @@ module IsoDoc
|
|
170
170
|
end
|
171
171
|
|
172
172
|
def code_css(isoxml, _out)
|
173
|
-
c = isoxml.at(ns("//
|
173
|
+
c = isoxml.at(ns("//metanorma-extension/source-highlighter-css")) or return
|
174
174
|
set(:code_css, c.text)
|
175
175
|
end
|
176
176
|
end
|
@@ -17,8 +17,8 @@ module IsoDoc
|
|
17
17
|
def toc_metadata(docxml)
|
18
18
|
return unless @tocfigures || @toctables || @tocrecommendations
|
19
19
|
|
20
|
-
ins = docxml.at(ns("//
|
21
|
-
docxml.at(ns("//bibdata")).after("<
|
20
|
+
ins = docxml.at(ns("//metanorma-extension")) ||
|
21
|
+
docxml.at(ns("//bibdata")).after("<metanorma-extension/>").next_element
|
22
22
|
@tocfigures and
|
23
23
|
ins << "<toc type='figure'><title>#{@i18n.toc_figures}</title></toc>"
|
24
24
|
@toctables and
|
@@ -41,7 +41,7 @@ module IsoDoc
|
|
41
41
|
return unless @fontist_fonts
|
42
42
|
|
43
43
|
ins = xmldoc.at(ns("//presentation-metadata")) ||
|
44
|
-
xmldoc.at(ns("//
|
44
|
+
xmldoc.at(ns("//metanorma-extension")) || xmldoc.at(ns("//bibdata"))
|
45
45
|
CSV.parse_line(@fontist_fonts, col_sep: ";").map(&:strip).each do |f|
|
46
46
|
ins.next = presmeta("fonts", f)
|
47
47
|
end
|
@@ -15,8 +15,7 @@ module IsoDoc
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def prefix_name(node, delim, number, elem)
|
18
|
-
|
19
|
-
|
18
|
+
number.nil? || number.empty? and return
|
20
19
|
unless name = node.at(ns("./#{elem}"))
|
21
20
|
(node.children.empty? and node.add_child("<#{elem}></#{elem}>")) or
|
22
21
|
node.children.first.previous = "<#{elem}></#{elem}>"
|
@@ -54,12 +53,12 @@ module IsoDoc
|
|
54
53
|
end
|
55
54
|
|
56
55
|
def note1(elem)
|
57
|
-
elem.parent.name
|
56
|
+
%w(bibdata bibitem).include?(elem.parent.name) ||
|
57
|
+
elem["notag"] == "true" and return
|
58
58
|
n = @xrefs.get[elem["id"]]
|
59
|
-
lbl =
|
60
|
-
|
61
|
-
|
62
|
-
end
|
59
|
+
lbl = @i18n.note
|
60
|
+
(n.nil? || n[:label].nil? || n[:label].empty?) or
|
61
|
+
lbl = l10n("#{lbl} #{n[:label]}")
|
63
62
|
prefix_name(elem, "", lbl, "name")
|
64
63
|
end
|
65
64
|
|
@@ -68,8 +67,18 @@ module IsoDoc
|
|
68
67
|
end
|
69
68
|
|
70
69
|
def admonition1(elem)
|
71
|
-
|
72
|
-
|
70
|
+
if elem["type"] == "box"
|
71
|
+
admonition_numbered1(elem)
|
72
|
+
else
|
73
|
+
elem["notag"] == "true" || elem.at(ns("./name")) and return
|
74
|
+
prefix_name(elem, "", @i18n.admonition[elem["type"]]&.upcase, "name")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def admonition_numbered1(elem)
|
79
|
+
elem["unnumbered"] && !elem.at(ns("./name")) and return
|
80
|
+
n = @xrefs.anchor(elem["id"], :label, false)
|
81
|
+
prefix_name(elem, block_delim, l10n("#{@i18n.box} #{n}"), "name")
|
73
82
|
end
|
74
83
|
|
75
84
|
def recommendation(docxml)
|
@@ -32,7 +32,7 @@ module IsoDoc
|
|
32
32
|
return localized unless twitter_cldr_reader_symbols[:decimal]
|
33
33
|
|
34
34
|
integer, fraction = localized.split(twitter_cldr_reader_symbols[:decimal])
|
35
|
-
return localized if fraction.nil? || fraction.
|
35
|
+
return localized if fraction.nil? || fraction.empty?
|
36
36
|
|
37
37
|
[integer, decorate_fraction_part(fraction, locale)]
|
38
38
|
.join(twitter_cldr_reader_symbols[:decimal])
|
@@ -97,14 +97,25 @@ module IsoDoc
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def mathml1(node, locale)
|
100
|
+
mathml_style_inherit(node)
|
100
101
|
asciimath_dup(node)
|
101
102
|
localize_maths(node, locale)
|
102
|
-
|
103
|
+
mathml_number_to_number(node)
|
104
|
+
end
|
105
|
+
|
106
|
+
def mathml_style_inherit(node)
|
107
|
+
node.at("./ancestor::xmlns:strong") or return
|
108
|
+
node.children =
|
109
|
+
"<mstyle mathvariant='bold'>#{node.children.to_xml}</mstyle>"
|
110
|
+
end
|
103
111
|
|
112
|
+
def mathml_number_to_number(node)
|
113
|
+
(node.elements.size == 1 && node.elements.first.name == "mn") or return
|
114
|
+
repl = node.at("./m:mn", MATHML).children
|
104
115
|
if node.parent.name == "stem"
|
105
|
-
node.parent.replace(
|
116
|
+
node.parent.replace(repl)
|
106
117
|
else
|
107
|
-
node.replace(
|
118
|
+
node.replace(repl)
|
108
119
|
end
|
109
120
|
end
|
110
121
|
end
|
@@ -17,7 +17,7 @@ module IsoDoc
|
|
17
17
|
level = @xrefs.anchor(elem["id"], :level, false) ||
|
18
18
|
(elem.ancestors("clause, annex").size + 1)
|
19
19
|
t = elem.at(ns("./title")) and t["depth"] = level
|
20
|
-
return if !elem.ancestors("boilerplate").empty? ||
|
20
|
+
return if !elem.ancestors("boilerplate, metanorma-extension").empty? ||
|
21
21
|
@suppressheadingnumbers || elem["unnumbered"]
|
22
22
|
|
23
23
|
lbl = @xrefs.anchor(elem["id"], :label,
|
@@ -1,24 +1,32 @@
|
|
1
1
|
module IsoDoc
|
2
2
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
3
3
|
def sourcehighlighter_css(docxml)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
ret = custom_css(docxml)
|
5
|
+
ret.empty? and return
|
6
|
+
ins = docxml.at(ns("//metanorma-extension")) ||
|
7
|
+
docxml.at(ns("//bibdata")).after("<metanorma-extension/>").next_element
|
8
|
+
ins << "<source-highlighter-css>#{ret}" \
|
8
9
|
"</source-highlighter-css>"
|
9
10
|
end
|
10
11
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
12
|
+
def custom_css(docxml)
|
13
|
+
ret = ""
|
14
|
+
@sourcehighlighter and
|
15
|
+
ret += File.read(File.join(File.dirname(__FILE__), "..", "base_style",
|
16
|
+
"rouge.css"))
|
17
|
+
a = docxml.at(ns("//metanorma-extension/" \
|
18
|
+
"clause[title = 'user-css']/sourcecode")) and
|
19
|
+
ret += "\n#{to_xml(a.children)}"
|
20
|
+
ret
|
14
21
|
end
|
15
22
|
|
16
23
|
def sourcehighlighter
|
17
24
|
@sourcehighlighter or return
|
25
|
+
Rouge::Formatter.enable_escape!
|
18
26
|
f = Rouge::Formatters::HTML.new
|
19
27
|
opts = { gutter_class: "rouge-gutter", code_class: "rouge-code" }
|
20
|
-
|
21
|
-
|
28
|
+
f1 = Rouge::Formatters::HTMLLineTable.new(f, opts)
|
29
|
+
{ formatter: f, formatter_line: f1 }
|
22
30
|
end
|
23
31
|
|
24
32
|
def sourcecode(docxml)
|
@@ -50,6 +58,11 @@ module IsoDoc
|
|
50
58
|
def source_remove_markup(elem)
|
51
59
|
ret = {}
|
52
60
|
name = elem.at(ns("./name")) and ret[:name] = name.remove.to_xml
|
61
|
+
source_remove_annotations(ret, elem)
|
62
|
+
ret
|
63
|
+
end
|
64
|
+
|
65
|
+
def source_remove_annotations(ret, elem)
|
53
66
|
ret[:ann] = elem.xpath(ns("./annotation")).each(&:remove)
|
54
67
|
ret[:call] = elem.xpath(ns("./callout")).each_with_object([]) do |c, m|
|
55
68
|
m << { xml: c.remove.to_xml, line: c.line - elem.line }
|
@@ -99,9 +112,12 @@ module IsoDoc
|
|
99
112
|
end
|
100
113
|
|
101
114
|
def source_lex(elem)
|
102
|
-
|
115
|
+
lexer = (Rouge::Lexer.find(elem["lang"] || "plaintext") ||
|
103
116
|
Rouge::Lexer.find("plaintext"))
|
104
|
-
l.
|
117
|
+
l = Rouge::Lexers::Escape.new(start: "{^^{", end: "}^^}", lang: lexer)
|
118
|
+
source = to_xml(elem.children).gsub(/</, "{^^{<").gsub(/>/, ">}^^}")
|
119
|
+
l.lang.reset!
|
120
|
+
l.lex(@c.decode(source))
|
105
121
|
end
|
106
122
|
|
107
123
|
def source_label(elem)
|
@@ -56,23 +56,22 @@ module IsoDoc
|
|
56
56
|
def concept1_ref(_node, ref, opts)
|
57
57
|
ref.nil? and return
|
58
58
|
opts[:ref] == "false" and return ref.remove
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
"./descendant-or-self::xmlns:termref")
|
63
|
-
%w(xref eref).include? ref&.name and get_linkend(ref)
|
64
|
-
opts[:linkref] == "false" && %w(xref eref).include?(ref&.name) and
|
59
|
+
concept1_ref_content(ref)
|
60
|
+
%w(xref eref).include? ref.name and get_linkend(ref)
|
61
|
+
opts[:linkref] == "false" && %w(xref eref).include?(ref.name) and
|
65
62
|
ref.replace(ref.children)
|
66
63
|
end
|
67
64
|
|
68
65
|
def concept1_ref_content(ref)
|
66
|
+
prev = "["
|
67
|
+
foll = "]"
|
69
68
|
if non_locality_elems(ref).select do |c|
|
70
69
|
!c.text? || /\S/.match(c)
|
71
70
|
end.empty?
|
72
|
-
|
73
|
-
to_xml(ref)))
|
74
|
-
else ref.replace("[#{to_xml(ref)}]")
|
71
|
+
prev, foll = @i18n.term_defined_in.split("%")
|
75
72
|
end
|
73
|
+
ref.previous = prev
|
74
|
+
ref.next = foll
|
76
75
|
end
|
77
76
|
|
78
77
|
def related(docxml)
|
@@ -24,6 +24,7 @@ module IsoDoc
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def conversions(docxml)
|
27
|
+
semantic_xml_insert(docxml)
|
27
28
|
bibdata docxml
|
28
29
|
@xrefs.parse docxml
|
29
30
|
section docxml
|
@@ -84,6 +85,45 @@ module IsoDoc
|
|
84
85
|
related docxml
|
85
86
|
end
|
86
87
|
|
88
|
+
def semantic_xml_insert(xml)
|
89
|
+
@semantic_xml_insert or return
|
90
|
+
embed = embedable_semantic_xml(xml)
|
91
|
+
ins = metanorma_extension_insert_pt(xml)
|
92
|
+
ins = ins.at(ns("./metanorma")) || ins.add_child("<metanorma/>").first
|
93
|
+
ins = ins.add_child("<source/>").first
|
94
|
+
ins << embed
|
95
|
+
end
|
96
|
+
|
97
|
+
def metanorma_extension_insert_pt(xml)
|
98
|
+
xml.at(ns("//metanorma-extension")) ||
|
99
|
+
xml.at(ns("//bibdata"))&.after("<metanorma-extension/>")
|
100
|
+
&.next_element ||
|
101
|
+
xml.root.elements.first.before("<metanorma-extension/>")
|
102
|
+
.previous_element
|
103
|
+
end
|
104
|
+
|
105
|
+
def embedable_semantic_xml(xml)
|
106
|
+
xml = embedable_semantic_xml_tags(xml)
|
107
|
+
embedable_semantic_xml_attributes(xml)
|
108
|
+
end
|
109
|
+
|
110
|
+
def embedable_semantic_xml_tags(xml)
|
111
|
+
Nokogiri::XML(to_xml(xml)
|
112
|
+
.sub(/ xmlns=['"][^"']+['"]/, "")
|
113
|
+
.gsub(%r{(</?)([[:alpha:]])}, "\\1semantic__\\2")).root
|
114
|
+
end
|
115
|
+
|
116
|
+
def embedable_semantic_xml_attributes(xml)
|
117
|
+
Metanorma::Utils::anchor_attributes.each do |(tag_name, attr_name)|
|
118
|
+
tag_name == "*" or tag_name = "semantic__#{tag_name}"
|
119
|
+
xml.xpath("//#{tag_name}[@#{attr_name}]").each do |elem|
|
120
|
+
elem.attributes[attr_name].value =
|
121
|
+
"semantic__#{elem.attributes[attr_name].value}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
xml
|
125
|
+
end
|
126
|
+
|
87
127
|
def postprocess(result, filename, _dir)
|
88
128
|
to_xml_file(result, filename)
|
89
129
|
@files_to_delete.each { |f| FileUtils.rm_rf f }
|
data/lib/isodoc/version.rb
CHANGED
@@ -244,11 +244,11 @@ module IsoDoc
|
|
244
244
|
|
245
245
|
def info(isoxml, out)
|
246
246
|
@tocfigurestitle =
|
247
|
-
isoxml&.at(ns("//
|
247
|
+
isoxml&.at(ns("//metanorma-extension/toc[@type = 'figure']/title"))&.text
|
248
248
|
@toctablestitle =
|
249
|
-
isoxml&.at(ns("//
|
249
|
+
isoxml&.at(ns("//metanorma-extension/toc[@type = 'table']/title"))&.text
|
250
250
|
@tocrecommendationstitle = isoxml
|
251
|
-
&.at(ns("//
|
251
|
+
&.at(ns("//metanorma-extension/toc[@type = 'recommendation']/title"))&.text
|
252
252
|
super
|
253
253
|
end
|
254
254
|
end
|
@@ -4,7 +4,7 @@ module IsoDoc
|
|
4
4
|
def comments(div)
|
5
5
|
return if @comments.empty?
|
6
6
|
|
7
|
-
div.div
|
7
|
+
div.div style: "mso-element:comment-list" do |div1|
|
8
8
|
@comments.each { |fn| div1.parent << fn }
|
9
9
|
end
|
10
10
|
end
|
@@ -26,28 +26,27 @@ module IsoDoc
|
|
26
26
|
# add in from and to links to move the comment into place
|
27
27
|
def make_comment_link(out, fnote, node)
|
28
28
|
out.span(**comment_link_attrs(fnote, node)) do |s1|
|
29
|
-
s1.span
|
30
|
-
s2.a
|
29
|
+
s1.span lang: "EN-GB", style: "font-size:9.0pt" do |s2|
|
30
|
+
s2.a style: "mso-comment-reference:SMC_#{fnote};" \
|
31
31
|
"mso-comment-date:#{node['date'].gsub(/[:-]+/,
|
32
|
-
'')}"
|
33
|
-
s2.span
|
34
|
-
target: fnote } # do |s|
|
32
|
+
'')}"
|
33
|
+
s2.span style: "mso-special-character:comment", target: fnote # do |s|
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
38
|
def make_comment_target(out)
|
40
|
-
out.span
|
41
|
-
s1.span
|
42
|
-
s2.span
|
39
|
+
out.span style: "MsoCommentReference" do |s1|
|
40
|
+
s1.span lang: "EN-GB", style: "font-size:9.0pt" do |s2|
|
41
|
+
s2.span style: "mso-special-character:comment"
|
43
42
|
end
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
46
|
def make_comment_text(node, fnote)
|
48
47
|
noko do |xml|
|
49
|
-
xml.div
|
50
|
-
div.span
|
48
|
+
xml.div style: "mso-element:comment", id: fnote do |div|
|
49
|
+
div.span style: %{mso-comment-author:"#{node['reviewer']}"}
|
51
50
|
make_comment_target(div)
|
52
51
|
node.children.each { |n| parse(n, div) }
|
53
52
|
end
|
@@ -61,7 +60,7 @@ module IsoDoc
|
|
61
60
|
end
|
62
61
|
|
63
62
|
COMMENT_IN_COMMENT_LIST1 =
|
64
|
-
'//div[@style="mso-element:comment-list"]//'\
|
63
|
+
'//div[@style="mso-element:comment-list"]//' \
|
65
64
|
'span[@style="MsoCommentReference"]'.freeze
|
66
65
|
|
67
66
|
def embed_comment_in_comment_list(docxml)
|
@@ -80,18 +79,24 @@ module IsoDoc
|
|
80
79
|
link.children = fromlink
|
81
80
|
end
|
82
81
|
|
83
|
-
def comment_attributes(docxml,
|
84
|
-
fromlink = docxml.at("//*[@id='#{
|
82
|
+
def comment_attributes(docxml, span)
|
83
|
+
fromlink = docxml.at("//*[@id='#{span['from']}']")
|
85
84
|
return(nil) if fromlink.nil?
|
86
85
|
|
87
|
-
tolink = docxml.at("//*[@id='#{
|
88
|
-
target = docxml.at("//*[@id='#{
|
86
|
+
tolink = docxml.at("//*[@id='#{span['to']}']") || fromlink
|
87
|
+
target = docxml.at("//*[@id='#{span['target']}']")
|
89
88
|
{ from: fromlink, to: tolink, target: target }
|
90
89
|
end
|
91
90
|
|
92
91
|
def wrap_comment_cont(from, target)
|
93
|
-
|
94
|
-
|
92
|
+
if %w(ol ul li div p).include?(from.name)
|
93
|
+
from.children.each do |c|
|
94
|
+
wrap_comment_cont(c, target)
|
95
|
+
end
|
96
|
+
else
|
97
|
+
s = from.replace("<span style='mso-comment-continuation:#{target}'>")
|
98
|
+
s.first.children = from
|
99
|
+
end
|
95
100
|
end
|
96
101
|
|
97
102
|
def skip_comment_wrap(from)
|
@@ -45,7 +45,7 @@ module IsoDoc
|
|
45
45
|
|
46
46
|
def make_generic_footnote_text(node, fnid)
|
47
47
|
noko do |xml|
|
48
|
-
xml.aside
|
48
|
+
xml.aside id: "ftn#{fnid}" do |div|
|
49
49
|
node.children.each { |n| parse(n, div) }
|
50
50
|
end
|
51
51
|
end.join("\n")
|
@@ -72,13 +72,13 @@ module IsoDoc
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def seen_footnote_parse(_node, out, footnote)
|
75
|
-
out.span
|
75
|
+
out.span style: "mso-element:field-begin"
|
76
76
|
out << " NOTEREF _Ref#{@fn_bookmarks[footnote]} \\f \\h"
|
77
|
-
out.span
|
78
|
-
out.span
|
77
|
+
out.span style: "mso-element:field-separator"
|
78
|
+
out.span class: "MsoFootnoteReference" do |s|
|
79
79
|
s << footnote
|
80
80
|
end
|
81
|
-
out.span
|
81
|
+
out.span style: "mso-element:field-end"
|
82
82
|
end
|
83
83
|
|
84
84
|
def footnote_parse(node, out)
|
@@ -89,9 +89,9 @@ module IsoDoc
|
|
89
89
|
return seen_footnote_parse(node, out, fn) if @seen_footnote.include?(fn)
|
90
90
|
|
91
91
|
@fn_bookmarks[fn] = bookmarkid
|
92
|
-
out.span
|
93
|
-
s.a
|
94
|
-
|
92
|
+
out.span style: "mso-bookmark:_Ref#{@fn_bookmarks[fn]}" do |s|
|
93
|
+
s.a class: "FootnoteRef", "epub:type": "footnote",
|
94
|
+
href: "#ftn#{fn}" do |a|
|
95
95
|
a.sup { |sup| sup << fn }
|
96
96
|
end
|
97
97
|
end
|
@@ -1,17 +1,11 @@
|
|
1
1
|
require "fileutils"
|
2
2
|
require_relative "./postprocess_cover"
|
3
3
|
require_relative "./postprocess_toc"
|
4
|
+
require_relative "./postprocess_table"
|
4
5
|
|
5
6
|
module IsoDoc
|
6
7
|
module WordFunction
|
7
8
|
module Postprocess
|
8
|
-
def table_note_cleanup(docxml)
|
9
|
-
super
|
10
|
-
# preempt html2doc putting MsoNormal there
|
11
|
-
docxml.xpath("//p[not(self::*[@class])][ancestor::*[@class = 'Note']]")
|
12
|
-
.each { |p| p["class"] = "Note" }
|
13
|
-
end
|
14
|
-
|
15
9
|
def postprocess(result, filename, dir)
|
16
10
|
filename = filename.sub(/\.doc$/, "")
|
17
11
|
header = generate_header(filename, dir)
|
@@ -55,6 +49,7 @@ module IsoDoc
|
|
55
49
|
word_nested_tables(docxml)
|
56
50
|
word_colgroup(docxml)
|
57
51
|
word_table_align(docxml)
|
52
|
+
word_table_pagebreak(docxml)
|
58
53
|
word_table_separator(docxml)
|
59
54
|
word_admonition_images(docxml)
|
60
55
|
word_list_continuations(docxml)
|
@@ -108,54 +103,6 @@ module IsoDoc
|
|
108
103
|
end
|
109
104
|
end
|
110
105
|
|
111
|
-
def word_colgroup(docxml)
|
112
|
-
cells2d = {}
|
113
|
-
docxml.xpath("//table[colgroup]").each do |t|
|
114
|
-
w = colgroup_widths(t)
|
115
|
-
t.xpath(".//tr").each_with_index { |_tr, r| cells2d[r] = {} }
|
116
|
-
t.xpath(".//tr").each_with_index do |tr, r|
|
117
|
-
tr.xpath("./td | ./th").each_with_index do |td, _i|
|
118
|
-
x = 0
|
119
|
-
rs = td.attr("rowspan")&.to_i || 1
|
120
|
-
cs = td.attr("colspan")&.to_i || 1
|
121
|
-
while cells2d[r][x]
|
122
|
-
x += 1
|
123
|
-
end
|
124
|
-
(r..(r + rs - 1)).each do |y2|
|
125
|
-
cells2d[y2].nil? and next
|
126
|
-
(x..(x + cs - 1)).each { |x2| cells2d[y2][x2] = 1 }
|
127
|
-
end
|
128
|
-
width = (x..(x + cs - 1)).each_with_object({ width: 0 }) do |z, m|
|
129
|
-
m[:width] += w[z]
|
130
|
-
end
|
131
|
-
td["width"] = "#{width[:width]}%"
|
132
|
-
x += cs
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
# assume percentages
|
139
|
-
def colgroup_widths(table)
|
140
|
-
table.xpath("./colgroup/col").each_with_object([]) do |c, m|
|
141
|
-
m << c["width"].sub(/%$/, "").to_f
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
def word_nested_tables(docxml)
|
146
|
-
docxml.xpath("//table").each do |t|
|
147
|
-
t.xpath(".//table").reverse.each do |tt|
|
148
|
-
t.next = tt.remove
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def style_update(node, css)
|
154
|
-
node or return
|
155
|
-
node["style"] =
|
156
|
-
node["style"] ? node["style"].sub(/;?$/, ";#{css}") : css
|
157
|
-
end
|
158
|
-
|
159
106
|
def word_image_caption(docxml)
|
160
107
|
docxml.xpath("//p[@class = 'FigureTitle' or @class = 'SourceTitle']")
|
161
108
|
.each do |t|
|
@@ -188,21 +135,6 @@ module IsoDoc
|
|
188
135
|
end
|
189
136
|
end
|
190
137
|
|
191
|
-
def word_table_align(docxml)
|
192
|
-
docxml.xpath("//td[@align]/p | //th[@align]/p").each do |p|
|
193
|
-
p["align"] and next
|
194
|
-
style_update(p, "text-align: #{p.parent['align']}")
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
def word_table_separator(docxml)
|
199
|
-
docxml.xpath("//p[@class = 'TableTitle']").each do |t|
|
200
|
-
t.children.empty? or next
|
201
|
-
t["style"] = t["style"].sub(/;?$/, ";font-size:0pt;")
|
202
|
-
t.children = " "
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
138
|
def word_annex_cleanup(docxml); end
|
207
139
|
|
208
140
|
def word_example_cleanup(docxml)
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
module WordFunction
|
3
|
+
module Postprocess
|
4
|
+
def table_note_cleanup(docxml)
|
5
|
+
super
|
6
|
+
# preempt html2doc putting MsoNormal there
|
7
|
+
docxml.xpath("//p[not(self::*[@class])][ancestor::*[@class = 'Note']]")
|
8
|
+
.each { |p| p["class"] = "Note" }
|
9
|
+
end
|
10
|
+
|
11
|
+
def word_colgroup(docxml)
|
12
|
+
cells2d = {}
|
13
|
+
docxml.xpath("//table[colgroup]").each do |t|
|
14
|
+
w = colgroup_widths(t)
|
15
|
+
t.xpath(".//tr").each_with_index { |_tr, r| cells2d[r] = {} }
|
16
|
+
t.xpath(".//tr").each_with_index do |tr, r|
|
17
|
+
tr.xpath("./td | ./th").each_with_index do |td, _i|
|
18
|
+
x = 0
|
19
|
+
rs = td.attr("rowspan")&.to_i || 1
|
20
|
+
cs = td.attr("colspan")&.to_i || 1
|
21
|
+
while cells2d[r][x]
|
22
|
+
x += 1
|
23
|
+
end
|
24
|
+
(r..(r + rs - 1)).each do |y2|
|
25
|
+
cells2d[y2].nil? and next
|
26
|
+
(x..(x + cs - 1)).each { |x2| cells2d[y2][x2] = 1 }
|
27
|
+
end
|
28
|
+
width = (x..(x + cs - 1)).each_with_object({ width: 0 }) do |z, m|
|
29
|
+
m[:width] += w[z]
|
30
|
+
end
|
31
|
+
td["width"] = "#{width[:width]}%"
|
32
|
+
x += cs
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# assume percentages
|
39
|
+
def colgroup_widths(table)
|
40
|
+
table.xpath("./colgroup/col").each_with_object([]) do |c, m|
|
41
|
+
m << c["width"].sub(/%$/, "").to_f
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def word_nested_tables(docxml)
|
46
|
+
docxml.xpath("//table").each do |t|
|
47
|
+
t.xpath(".//table").reverse.each do |tt|
|
48
|
+
t.next = tt.remove
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def style_update(node, css)
|
54
|
+
node or return
|
55
|
+
node["style"] =
|
56
|
+
node["style"] ? node["style"].sub(/;?$/, ";#{css}") : css
|
57
|
+
end
|
58
|
+
|
59
|
+
def word_table_align(docxml)
|
60
|
+
docxml.xpath("//td[@align]/p | //th[@align]/p").each do |p|
|
61
|
+
p["align"] and next
|
62
|
+
style_update(p, "text-align: #{p.parent['align']}")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def word_table_separator(docxml)
|
67
|
+
docxml.xpath("//p[@class = 'TableTitle']").each do |t|
|
68
|
+
t.children.empty? or next
|
69
|
+
t["style"] = t["style"].sub(/;?$/, ";font-size:0pt;")
|
70
|
+
t.children = " "
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def word_table_pagebreak(docxml)
|
75
|
+
docxml.xpath("//td[@style] | //th[@style]").each do |t|
|
76
|
+
s = /(page-break-after:[^;]+)/.match(t["style"])
|
77
|
+
(s && s[1]) or next
|
78
|
+
t.xpath(".//div | .//p | .//pre").each do |p|
|
79
|
+
style_update(p, s[1])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -24,35 +24,53 @@ module IsoDoc
|
|
24
24
|
def make_tr_attr(cell, row, totalrows, header, bordered)
|
25
25
|
style = cell.name == "th" ? "font-weight:bold;" : ""
|
26
26
|
rowmax = cell["rowspan"] ? row + cell["rowspan"].to_i - 1 : row
|
27
|
-
style += make_tr_attr_style(row, rowmax, totalrows,
|
27
|
+
style += make_tr_attr_style(cell, row, rowmax, totalrows,
|
28
|
+
{ header: header, bordered: bordered })
|
28
29
|
{ rowspan: cell["rowspan"], colspan: cell["colspan"],
|
29
30
|
valign: cell["valign"], align: cell["align"], style: style,
|
30
31
|
class: cell["class"] }
|
31
32
|
end
|
32
33
|
|
33
|
-
def make_tr_attr_style(row, rowmax, totalrows,
|
34
|
+
def make_tr_attr_style(cell, row, rowmax, totalrows, opt)
|
35
|
+
top = row.zero? ? "#{SW1} 1.5pt;" : "none;"
|
36
|
+
bottom = "#{SW1} #{rowmax >= totalrows ? '1.5' : '1.0'}pt;"
|
34
37
|
ret = <<~STYLE.gsub(/\n/, "")
|
35
|
-
border-top:#{
|
36
|
-
mso-border-
|
37
|
-
border-bottom:#{SW1} #{rowmax >= totalrows ? '1.5' : '1.0'}pt;
|
38
|
-
mso-border-bottom-alt:#{SW1} #{rowmax >= totalrows ? '1.5' : '1.0'}pt;
|
38
|
+
border-top:#{top}mso-border-top-alt:#{top}
|
39
|
+
border-bottom:#{bottom}mso-border-bottom-alt:#{bottom}
|
39
40
|
STYLE
|
40
|
-
bordered or ret = ""
|
41
|
-
pb =
|
41
|
+
opt[:bordered] or ret = ""
|
42
|
+
pb = keep_rows_together(cell, rowmax, totalrows, opt) ? "avoid" : "auto"
|
42
43
|
"#{ret}page-break-after:#{pb};"
|
43
44
|
end
|
44
45
|
|
46
|
+
def keep_rows_together(cell, rowmax, totalrows, opt)
|
47
|
+
opt[:header] and return true
|
48
|
+
table_line_count(cell.parent.parent) > 15 and return false
|
49
|
+
(totalrows <= 10 && rowmax < totalrows)
|
50
|
+
end
|
51
|
+
|
52
|
+
def table_line_count(tbody)
|
53
|
+
sum = 0
|
54
|
+
tbody.xpath(ns(".//tr")).each do |r|
|
55
|
+
i = 1
|
56
|
+
r.xpath(ns(".//td | .//th")).each do |c|
|
57
|
+
n = c.xpath(ns(".//li | .//p | .//br")).size
|
58
|
+
n > i and i = n
|
59
|
+
end
|
60
|
+
sum += i
|
61
|
+
end
|
62
|
+
sum
|
63
|
+
end
|
64
|
+
|
45
65
|
def table_attrs(node)
|
46
66
|
c = node["class"]
|
47
67
|
bordered = "border-spacing:0;border-width:1px;"
|
48
68
|
(%w(modspec).include?(c) || !c) or bordered = nil
|
49
69
|
ret = {
|
50
|
-
summary: node["summary"],
|
51
|
-
width: node["width"],
|
70
|
+
summary: node["summary"], width: node["width"],
|
52
71
|
style: "mso-table-anchor-horizontal:column;mso-table-overlap:never;" \
|
53
72
|
"#{bordered}#{keep_style(node)}",
|
54
|
-
class: (node.text.length > 4000 ? "MsoISOTableBig" : "MsoISOTable")
|
55
|
-
}
|
73
|
+
class: (node.text.length > 4000 ? "MsoISOTableBig" : "MsoISOTable") }
|
56
74
|
bordered or ret.delete(:class)
|
57
75
|
super.merge(attr_code(ret))
|
58
76
|
end
|
@@ -61,7 +79,7 @@ module IsoDoc
|
|
61
79
|
colgroup = node.at(ns("./colgroup")) or return
|
62
80
|
table.colgroup do |cg|
|
63
81
|
colgroup.xpath(ns("./col")).each do |c|
|
64
|
-
cg.col
|
82
|
+
cg.col width: c["width"]
|
65
83
|
end
|
66
84
|
end
|
67
85
|
end
|
@@ -69,7 +87,7 @@ module IsoDoc
|
|
69
87
|
def table_parse(node, out)
|
70
88
|
@in_table = true
|
71
89
|
table_title_parse(node, out)
|
72
|
-
out.div
|
90
|
+
out.div align: "center", class: "table_container" do |div|
|
73
91
|
div.table **table_attrs(node) do |t|
|
74
92
|
colgroup(node, t)
|
75
93
|
thead_parse(node, t)
|
@@ -4,10 +4,12 @@ module IsoDoc
|
|
4
4
|
module XrefGen
|
5
5
|
module Anchor
|
6
6
|
class SeenAnchor
|
7
|
-
|
8
|
-
|
9
|
-
def initialize
|
7
|
+
def initialize(xmldoc)
|
10
8
|
@seen = {}
|
9
|
+
# ignore all metanorma-extension ids
|
10
|
+
xmldoc.xpath("//xmlns:metanorma-extension//*[@id]").each do |x|
|
11
|
+
add(x["id"])
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
15
|
def seen(elem)
|
data/lib/isodoc/xref/xref_gen.rb
CHANGED
@@ -92,14 +92,15 @@ module IsoDoc
|
|
92
92
|
SECTIONS_XPATH
|
93
93
|
end
|
94
94
|
|
95
|
-
|
95
|
+
def child_asset_path(asset)
|
96
96
|
"./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and " \
|
97
|
-
"not(self::xmlns:terms) and not(self::xmlns:definitions)]//xmlns:
|
98
|
-
"./xmlns:
|
97
|
+
"not(self::xmlns:terms) and not(self::xmlns:definitions)]//xmlns:X | " \
|
98
|
+
"./xmlns:X".gsub("X", asset)
|
99
|
+
end
|
99
100
|
|
100
101
|
def note_anchor_names(sections)
|
101
102
|
sections.each do |s|
|
102
|
-
notes = s.xpath(
|
103
|
+
notes = s.xpath(child_asset_path("note")) -
|
103
104
|
s.xpath(ns(".//figure//note | .//table//note"))
|
104
105
|
note_anchor_names1(notes, Counter.new)
|
105
106
|
note_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
|
@@ -116,17 +117,28 @@ module IsoDoc
|
|
116
117
|
end
|
117
118
|
end
|
118
119
|
|
119
|
-
CHILD_EXAMPLES_XPATH =
|
120
|
-
"./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and " \
|
121
|
-
"not(self::xmlns:terms) and not(self::xmlns:definitions)]//" \
|
122
|
-
"xmlns:example | ./xmlns:example".freeze
|
123
|
-
|
124
120
|
CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | " \
|
125
121
|
"./references".freeze
|
126
122
|
|
123
|
+
def admonition_anchor_names(sections)
|
124
|
+
sections.each do |s|
|
125
|
+
notes = s.xpath(child_asset_path("admonition[@type = 'box']"))
|
126
|
+
admonition_anchor_names1(notes, Counter.new)
|
127
|
+
admonition_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def admonition_anchor_names1(notes, counter)
|
132
|
+
notes.noblank.each do |n|
|
133
|
+
@anchors[n["id"]] ||=
|
134
|
+
anchor_struct(increment_label(notes, n, counter), n,
|
135
|
+
@labels["box"], "admonition", n["unnumbered"])
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
127
139
|
def example_anchor_names(sections)
|
128
140
|
sections.each do |s|
|
129
|
-
notes = s.xpath(
|
141
|
+
notes = s.xpath(child_asset_path("example"))
|
130
142
|
example_anchor_names1(notes, Counter.new)
|
131
143
|
example_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
|
132
144
|
end
|
@@ -154,7 +166,8 @@ module IsoDoc
|
|
154
166
|
end
|
155
167
|
end
|
156
168
|
|
157
|
-
def list_item_anchor_names(list, list_anchor, depth, prev_label,
|
169
|
+
def list_item_anchor_names(list, list_anchor, depth, prev_label,
|
170
|
+
refer_list)
|
158
171
|
c = Counter.new(list["start"] ? list["start"].to_i - 1 : 0)
|
159
172
|
list.xpath(ns("./li")).each do |li|
|
160
173
|
label = c.increment(li).listlabel(list, depth)
|
@@ -45,6 +45,7 @@ module IsoDoc
|
|
45
45
|
termexample_anchor_names(doc)
|
46
46
|
note_anchor_names(doc.xpath(ns("//table | //figure")))
|
47
47
|
note_anchor_names(doc.xpath(ns(sections_xpath)))
|
48
|
+
admonition_anchor_names(doc.xpath(ns(sections_xpath)))
|
48
49
|
example_anchor_names(doc.xpath(ns(sections_xpath)))
|
49
50
|
list_anchor_names(doc.xpath(ns(sections_xpath)))
|
50
51
|
deflist_anchor_names(doc.xpath(ns(sections_xpath)))
|
data/lib/isodoc/xref.rb
CHANGED
@@ -49,7 +49,6 @@ module IsoDoc
|
|
49
49
|
return nil if ident.nil? || ident.empty?
|
50
50
|
|
51
51
|
if warning && !@anchors[ident]
|
52
|
-
@seen ||= SeenAnchor.instance
|
53
52
|
@seen.seen(ident) or warn "No label has been processed for ID #{ident}"
|
54
53
|
@seen.add(ident)
|
55
54
|
return "[#{ident}]"
|
@@ -59,6 +58,7 @@ module IsoDoc
|
|
59
58
|
|
60
59
|
# extract names for all anchors, xref and label
|
61
60
|
def parse(docxml)
|
61
|
+
@seen = SeenAnchor.new(docxml)
|
62
62
|
amend_preprocess(docxml) if @parse_settings.empty?
|
63
63
|
initial_anchor_names(docxml)
|
64
64
|
back_anchor_names(docxml)
|
data/lib/isodoc.rb
CHANGED
@@ -7,10 +7,10 @@ require "base64"
|
|
7
7
|
require "mime/types"
|
8
8
|
require "image_size"
|
9
9
|
require "set"
|
10
|
-
require "pp"
|
11
10
|
require "html2doc"
|
12
11
|
require "liquid"
|
13
12
|
require "htmlentities"
|
13
|
+
require "relaton-render"
|
14
14
|
|
15
15
|
require "isodoc/common"
|
16
16
|
require "isodoc/convert"
|
@@ -24,6 +24,7 @@ require "isodoc/presentation_xml_convert"
|
|
24
24
|
require "isodoc/xref"
|
25
25
|
require "isodoc/i18n"
|
26
26
|
require "metanorma/output"
|
27
|
+
require "relaton/render-isodoc/general"
|
27
28
|
|
28
29
|
module IsoDoc
|
29
30
|
end
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isodoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciimath
|
@@ -480,6 +480,7 @@ files:
|
|
480
480
|
- lib/isodoc/word_function/inline.rb
|
481
481
|
- lib/isodoc/word_function/postprocess.rb
|
482
482
|
- lib/isodoc/word_function/postprocess_cover.rb
|
483
|
+
- lib/isodoc/word_function/postprocess_table.rb
|
483
484
|
- lib/isodoc/word_function/postprocess_toc.rb
|
484
485
|
- lib/isodoc/word_function/table.rb
|
485
486
|
- lib/isodoc/xref.rb
|
@@ -493,8 +494,8 @@ files:
|
|
493
494
|
- lib/metanorma/output/base.rb
|
494
495
|
- lib/metanorma/output/utils.rb
|
495
496
|
- lib/metanorma/output/xslfo.rb
|
496
|
-
- lib/relaton/render/config.yml
|
497
|
-
- lib/relaton/render/general.rb
|
497
|
+
- lib/relaton/render-isodoc/config.yml
|
498
|
+
- lib/relaton/render-isodoc/general.rb
|
498
499
|
homepage: https://github.com/metanorma/isodoc
|
499
500
|
licenses:
|
500
501
|
- BSD-2-Clause
|