isodoc 2.4.0 → 2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/isodoc.gemspec +1 -0
- data/lib/isodoc/base_style/all.css +29 -0
- data/lib/isodoc/base_style/metanorma_word.css +9 -0
- data/lib/isodoc/base_style/metanorma_word.scss +11 -0
- data/lib/isodoc/base_style/reset.css +29 -0
- data/lib/isodoc/base_style/reset.scss +34 -0
- data/lib/isodoc/base_style/rouge.css +39 -0
- data/lib/isodoc/base_style/typography.scss +6 -3
- data/lib/isodoc/convert.rb +7 -4
- data/lib/isodoc/function/blocks.rb +26 -16
- data/lib/isodoc/function/inline.rb +17 -17
- data/lib/isodoc/function/references.rb +38 -52
- data/lib/isodoc/function/table.rb +22 -13
- data/lib/isodoc/function/to_word_html.rb +1 -4
- data/lib/isodoc/function/utils.rb +5 -1
- data/lib/isodoc/html_function/html.rb +13 -34
- data/lib/isodoc/html_function/postprocess.rb +14 -1
- data/lib/isodoc/html_function/postprocess_cover.rb +6 -9
- data/lib/isodoc/metadata.rb +5 -0
- data/lib/isodoc/presentation_function/block.rb +15 -46
- data/lib/isodoc/presentation_function/refs.rb +75 -3
- data/lib/isodoc/presentation_function/sourcecode.rb +114 -0
- data/lib/isodoc/presentation_function/terms.rb +29 -37
- data/lib/isodoc/presentation_function/xrefs.rb +9 -6
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +16 -16
- data/lib/isodoc/word_function/postprocess.rb +47 -43
- data/lib/isodoc/word_function/postprocess_cover.rb +29 -157
- data/lib/isodoc/word_function/postprocess_toc.rb +165 -0
- data/lib/isodoc/word_function/table.rb +25 -13
- data/lib/isodoc/xref/xref_gen.rb +2 -4
- metadata +19 -2
@@ -0,0 +1,165 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
module WordFunction
|
3
|
+
module Postprocess
|
4
|
+
def insert_toc(intro, docxml, level)
|
5
|
+
toc = ""
|
6
|
+
toc += make_WordToC(docxml, level)
|
7
|
+
toc += make_table_word_toc(docxml)
|
8
|
+
toc += make_figure_word_toc(docxml)
|
9
|
+
toc += make_recommendation_word_toc(docxml)
|
10
|
+
intro.sub(/WORDTOC/, toc)
|
11
|
+
end
|
12
|
+
|
13
|
+
def word_toc_entry(toclevel, heading)
|
14
|
+
bookmark = bookmarkid # Random.rand(1000000000)
|
15
|
+
<<~TOC
|
16
|
+
<p class="MsoToc#{toclevel}"><span class="MsoHyperlink"><span lang="EN-GB" style='mso-no-proof:yes'>
|
17
|
+
<a href="#_Toc#{bookmark}">#{heading}<span lang="EN-GB" class="MsoTocTextSpan">
|
18
|
+
<span style='mso-tab-count:1 dotted'>. </span>
|
19
|
+
</span><span lang="EN-GB" class="MsoTocTextSpan">
|
20
|
+
<span style='mso-element:field-begin'></span></span>
|
21
|
+
<span lang="EN-GB" class="MsoTocTextSpan"> PAGEREF _Toc#{bookmark} \\h </span>
|
22
|
+
<span lang="EN-GB" class="MsoTocTextSpan"><span style='mso-element:field-separator'></span></span><span
|
23
|
+
lang="EN-GB" class="MsoTocTextSpan">1</span>
|
24
|
+
<span lang="EN-GB" class="MsoTocTextSpan"></span><span
|
25
|
+
lang="EN-GB" class="MsoTocTextSpan"><span style='mso-element:field-end'></span></span></a></span></span></p>
|
26
|
+
|
27
|
+
TOC
|
28
|
+
end
|
29
|
+
|
30
|
+
def word_toc_preface(level)
|
31
|
+
<<~TOC
|
32
|
+
<span lang="EN-GB"><span style='mso-element:field-begin'></span><span
|
33
|
+
style='mso-spacerun:yes'> </span>TOC \\o "1-#{level}" \\h \\z \\u <span
|
34
|
+
style='mso-element:field-separator'></span></span>
|
35
|
+
TOC
|
36
|
+
end
|
37
|
+
|
38
|
+
WORD_TOC_SUFFIX1 = <<~TOC.freeze
|
39
|
+
<p class="MsoToc1"><span lang="EN-GB"><span
|
40
|
+
style='mso-element:field-end'></span></span><span
|
41
|
+
lang="EN-GB"><o:p> </o:p></span></p>
|
42
|
+
TOC
|
43
|
+
|
44
|
+
def make_WordToC(docxml, level)
|
45
|
+
toc = ""
|
46
|
+
# docxml.xpath("//h1 | //h2[not(ancestor::*[@class = 'Section3'])]").
|
47
|
+
xpath = (1..level).each.map { |i| "//h#{i}" }.join (" | ")
|
48
|
+
docxml.xpath(xpath).each do |h|
|
49
|
+
toc += word_toc_entry(h.name[1].to_i, header_strip(h))
|
50
|
+
end
|
51
|
+
toc.sub(/(<p class="MsoToc1">)/,
|
52
|
+
%{\\1#{word_toc_preface(level)}}) + WORD_TOC_SUFFIX1
|
53
|
+
end
|
54
|
+
|
55
|
+
# inheriting gems need to add native Word name of style, if different
|
56
|
+
# including both CSS style name and human readable style name.
|
57
|
+
# Any human readable style name needs to come first for the Word template
|
58
|
+
# to work in regenerating the ToC
|
59
|
+
def table_toc_class
|
60
|
+
%w(TableTitle tabletitle)
|
61
|
+
end
|
62
|
+
|
63
|
+
def figure_toc_class
|
64
|
+
%w(FigureTitle figuretitle)
|
65
|
+
end
|
66
|
+
|
67
|
+
def reqt_toc_class
|
68
|
+
%w(RecommendationTitle RecommendationTestTitle
|
69
|
+
recommendationtitle recommendationtesttitle)
|
70
|
+
end
|
71
|
+
|
72
|
+
def toc_word_class_list(classes)
|
73
|
+
classes.map do |x|
|
74
|
+
/ /.match?(x) ? %("#{x}") : x
|
75
|
+
end.join(",")
|
76
|
+
end
|
77
|
+
|
78
|
+
def word_toc_reqt_preface1
|
79
|
+
<<~TOC
|
80
|
+
<span lang="EN-GB"><span style='mso-element:field-begin'></span><span
|
81
|
+
style='mso-spacerun:yes'> </span>TOC \\h \\z \\t #{toc_word_class_list reqt_toc_class}
|
82
|
+
<span style='mso-element:field-separator'></span></span>
|
83
|
+
TOC
|
84
|
+
end
|
85
|
+
|
86
|
+
def word_toc_table_preface1
|
87
|
+
<<~TOC
|
88
|
+
<span lang="EN-GB"><span style='mso-element:field-begin'></span><span style='mso-spacerun:yes'> </span>TOC
|
89
|
+
\\h \\z \\t #{toc_word_class_list table_toc_class} <span style='mso-element:field-separator'></span></span>
|
90
|
+
TOC
|
91
|
+
end
|
92
|
+
|
93
|
+
def word_toc_figure_preface1
|
94
|
+
<<~TOC
|
95
|
+
<span lang="EN-GB"><span style='mso-element:field-begin'></span><span style='mso-spacerun:yes'> </span>TOC
|
96
|
+
\\h \\z \\t #{toc_word_class_list figure_toc_class} <span style='mso-element:field-separator'></span></span>
|
97
|
+
TOC
|
98
|
+
end
|
99
|
+
|
100
|
+
def table_toc_xpath
|
101
|
+
attr = table_toc_class.map { |x| "@class = '#{x}'" }
|
102
|
+
"//p[#{attr.join(' or ')}]"
|
103
|
+
end
|
104
|
+
|
105
|
+
def make_table_word_toc(docxml)
|
106
|
+
(docxml.at(table_toc_xpath) && @toctablestitle) or return ""
|
107
|
+
toc = %{<p class="TOCTitle">#{@toctablestitle}</p>}
|
108
|
+
docxml.xpath(table_toc_xpath).each do |h|
|
109
|
+
toc += word_toc_entry(1, header_strip(h))
|
110
|
+
end
|
111
|
+
toc.sub(/(<p class="MsoToc1">)/,
|
112
|
+
%{\\1#{word_toc_table_preface1}}) + WORD_TOC_SUFFIX1
|
113
|
+
end
|
114
|
+
|
115
|
+
def figure_toc_xpath
|
116
|
+
attr = figure_toc_class.map { |x| "@class = '#{x}'" }
|
117
|
+
"//p[#{attr.join(' or ')}]"
|
118
|
+
end
|
119
|
+
|
120
|
+
def make_figure_word_toc(docxml)
|
121
|
+
(docxml.at(figure_toc_xpath) && @tocfigurestitle) or return ""
|
122
|
+
toc = %{<p class="TOCTitle">#{@tocfigurestitle}</p>}
|
123
|
+
docxml.xpath(figure_toc_xpath).each do |h|
|
124
|
+
toc += word_toc_entry(1, header_strip(h))
|
125
|
+
end
|
126
|
+
toc.sub(/(<p class="MsoToc1">)/,
|
127
|
+
%{\\1#{word_toc_figure_preface1}}) + WORD_TOC_SUFFIX1
|
128
|
+
end
|
129
|
+
|
130
|
+
def reqt_toc_xpath
|
131
|
+
attr = reqt_toc_class.map { |x| "@class = '#{x}'" }
|
132
|
+
"//p[#{attr.join(' or ')}]"
|
133
|
+
end
|
134
|
+
|
135
|
+
def make_recommendation_word_toc(docxml)
|
136
|
+
(docxml.at(reqt_toc_xpath) && @tocrecommendationstitle) or return ""
|
137
|
+
toc = %{<p class="TOCTitle">#{@tocrecommendationstitle}</p>}
|
138
|
+
docxml.xpath(reqt_toc_xpath).sort_by do |h|
|
139
|
+
recommmendation_sort_key(h.text)
|
140
|
+
end.each do |h|
|
141
|
+
toc += word_toc_entry(1, header_strip(h))
|
142
|
+
end
|
143
|
+
toc.sub(/(<p class="MsoToc1">)/,
|
144
|
+
%{\\1#{word_toc_reqt_preface1}}) + WORD_TOC_SUFFIX1
|
145
|
+
end
|
146
|
+
|
147
|
+
def recommmendation_sort_key(header)
|
148
|
+
m = /^([^0-9]+) (\d+)/.match(header) || /^([^:]+)/.match(header)
|
149
|
+
m ||= [header, nil]
|
150
|
+
ret = "#{recommmendation_sort_key1(m[1])}::"
|
151
|
+
m[2] and ret += ("%04d" % m[2].to_i).to_s
|
152
|
+
ret
|
153
|
+
end
|
154
|
+
|
155
|
+
def recommmendation_sort_key1(type)
|
156
|
+
case type&.downcase
|
157
|
+
when "requirement" then "04"
|
158
|
+
when "recommendation" then "05"
|
159
|
+
when "permission" then "06"
|
160
|
+
else type
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -15,39 +15,51 @@ module IsoDoc
|
|
15
15
|
table.at(".//tr").xpath("./td | ./th").each do |td|
|
16
16
|
cols += (td["colspan"] ? td["colspan"].to_i : 1)
|
17
17
|
end
|
18
|
-
style = "border-top:0pt;mso-border-top-alt:0pt;"\
|
18
|
+
style = "border-top:0pt;mso-border-top-alt:0pt;" \
|
19
19
|
"border-bottom:#{SW1} 1.5pt;mso-border-bottom-alt:#{SW1} 1.5pt;"
|
20
20
|
tfoot.add_child("<tr><td colspan='#{cols}' style='#{style}'/></tr>")
|
21
21
|
tfoot.xpath(".//td").last
|
22
22
|
end
|
23
23
|
|
24
|
-
def make_tr_attr(
|
25
|
-
style =
|
26
|
-
rowmax =
|
27
|
-
style +=
|
24
|
+
def make_tr_attr(cell, row, totalrows, header, bordered)
|
25
|
+
style = cell.name == "th" ? "font-weight:bold;" : ""
|
26
|
+
rowmax = cell["rowspan"] ? row + cell["rowspan"].to_i - 1 : row
|
27
|
+
style += make_tr_attr_style(row, rowmax, totalrows, header, bordered)
|
28
|
+
{ rowspan: cell["rowspan"], colspan: cell["colspan"],
|
29
|
+
valign: cell["valign"], align: cell["align"], style: style,
|
30
|
+
class: cell["class"] }
|
31
|
+
end
|
32
|
+
|
33
|
+
def make_tr_attr_style(row, rowmax, totalrows, header, bordered)
|
34
|
+
ret = <<~STYLE.gsub(/\n/, "")
|
28
35
|
border-top:#{row.zero? ? "#{SW1} 1.5pt;" : 'none;'}
|
29
36
|
mso-border-top-alt:#{row.zero? ? "#{SW1} 1.5pt;" : 'none;'}
|
30
|
-
border-bottom:#{SW1} #{rowmax
|
31
|
-
mso-border-bottom-alt:#{SW1} #{rowmax
|
37
|
+
border-bottom:#{SW1} #{rowmax >= totalrows ? '1.5' : '1.0'}pt;
|
38
|
+
mso-border-bottom-alt:#{SW1} #{rowmax >= totalrows ? '1.5' : '1.0'}pt;
|
32
39
|
STYLE
|
33
|
-
|
34
|
-
|
40
|
+
bordered or ret = ""
|
41
|
+
pb = header || (totalrows <= 10 && rowmax < totalrows) ? "avoid" : "auto"
|
42
|
+
"#{ret}page-break-after:#{pb};"
|
35
43
|
end
|
36
44
|
|
37
45
|
def table_attrs(node)
|
46
|
+
c = node["class"]
|
47
|
+
bordered = "border-spacing:0;border-width:1px;"
|
48
|
+
(%w(modspec).include?(c) || !c) or bordered = nil
|
38
49
|
ret = {
|
39
50
|
summary: node["summary"],
|
40
51
|
width: node["width"],
|
41
|
-
style: "mso-table-anchor-horizontal:column;mso-table-overlap:never;"\
|
42
|
-
"
|
52
|
+
style: "mso-table-anchor-horizontal:column;mso-table-overlap:never;" \
|
53
|
+
"#{bordered}#{keep_style(node)}",
|
43
54
|
class: (node.text.length > 4000 ? "MsoISOTableBig" : "MsoISOTable"),
|
44
55
|
}
|
56
|
+
bordered or ret.delete(:class)
|
45
57
|
super.merge(attr_code(ret))
|
46
58
|
end
|
47
59
|
|
48
|
-
def colgroup(node,
|
60
|
+
def colgroup(node, table)
|
49
61
|
colgroup = node.at(ns("./colgroup")) or return
|
50
|
-
|
62
|
+
table.colgroup do |cg|
|
51
63
|
colgroup.xpath(ns("./col")).each do |c|
|
52
64
|
cg.col **{ width: c["width"] }
|
53
65
|
end
|
data/lib/isodoc/xref/xref_gen.rb
CHANGED
@@ -133,10 +133,8 @@ module IsoDoc
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def example_anchor_names1(notes, counter)
|
136
|
-
notes.each do |n|
|
137
|
-
|
138
|
-
|
139
|
-
@anchors[n["id"]] =
|
136
|
+
notes.noblank.each do |n|
|
137
|
+
@anchors[n["id"]] ||=
|
140
138
|
anchor_struct(increment_label(notes, n, counter), n,
|
141
139
|
@labels["example_xref"], "example", n["unnumbered"])
|
142
140
|
end
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciimath
|
@@ -178,6 +178,20 @@ dependencies:
|
|
178
178
|
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rouge
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '4.0'
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '4.0'
|
181
195
|
- !ruby/object:Gem::Dependency
|
182
196
|
name: thread_safe
|
183
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -402,6 +416,7 @@ files:
|
|
402
416
|
- lib/isodoc/base_style/nav.scss
|
403
417
|
- lib/isodoc/base_style/reset.css
|
404
418
|
- lib/isodoc/base_style/reset.scss
|
419
|
+
- lib/isodoc/base_style/rouge.css
|
405
420
|
- lib/isodoc/base_style/scripts.html
|
406
421
|
- lib/isodoc/base_style/typography.css
|
407
422
|
- lib/isodoc/base_style/typography.scss
|
@@ -451,6 +466,7 @@ files:
|
|
451
466
|
- lib/isodoc/presentation_function/math.rb
|
452
467
|
- lib/isodoc/presentation_function/refs.rb
|
453
468
|
- lib/isodoc/presentation_function/section.rb
|
469
|
+
- lib/isodoc/presentation_function/sourcecode.rb
|
454
470
|
- lib/isodoc/presentation_function/terms.rb
|
455
471
|
- lib/isodoc/presentation_function/xrefs.rb
|
456
472
|
- lib/isodoc/presentation_xml_convert.rb
|
@@ -464,6 +480,7 @@ files:
|
|
464
480
|
- lib/isodoc/word_function/inline.rb
|
465
481
|
- lib/isodoc/word_function/postprocess.rb
|
466
482
|
- lib/isodoc/word_function/postprocess_cover.rb
|
483
|
+
- lib/isodoc/word_function/postprocess_toc.rb
|
467
484
|
- lib/isodoc/word_function/table.rb
|
468
485
|
- lib/isodoc/xref.rb
|
469
486
|
- lib/isodoc/xref/xref_anchor.rb
|