isodoc 2.4.1 → 2.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +1 -1
- data/lib/isodoc/convert.rb +10 -3
- data/lib/isodoc/function/blocks.rb +29 -16
- data/lib/isodoc/function/inline.rb +13 -13
- data/lib/isodoc/function/inline_simple.rb +1 -1
- data/lib/isodoc/function/references.rb +17 -38
- data/lib/isodoc/function/table.rb +1 -1
- data/lib/isodoc/function/to_word_html.rb +0 -4
- data/lib/isodoc/function/utils.rb +6 -2
- data/lib/isodoc/html_function/html.rb +13 -13
- data/lib/isodoc/html_function/postprocess.rb +14 -1
- data/lib/isodoc/metadata.rb +1 -1
- data/lib/isodoc/presentation_function/bibdata.rb +3 -3
- data/lib/isodoc/presentation_function/block.rb +1 -98
- data/lib/isodoc/presentation_function/math.rb +15 -4
- data/lib/isodoc/presentation_function/sourcecode.rb +122 -0
- data/lib/isodoc/presentation_function/terms.rb +14 -27
- data/lib/isodoc/presentation_xml_convert.rb +38 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +19 -19
- 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 +25 -118
- data/lib/isodoc/word_function/postprocess_cover.rb +29 -157
- data/lib/isodoc/word_function/postprocess_table.rb +85 -0
- data/lib/isodoc/word_function/postprocess_toc.rb +165 -0
- data/lib/isodoc/word_function/table.rb +34 -15
- data/lib/isodoc/xref/xref_gen.rb +2 -4
- metadata +6 -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
|
@@ -24,34 +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
|
-
valign: cell["valign"], align: cell["align"], style: style
|
30
|
+
valign: cell["valign"], align: cell["align"], style: style,
|
31
|
+
class: cell["class"] }
|
30
32
|
end
|
31
33
|
|
32
|
-
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;"
|
33
37
|
ret = <<~STYLE.gsub(/\n/, "")
|
34
|
-
border-top:#{
|
35
|
-
mso-border-
|
36
|
-
border-bottom:#{SW1} #{rowmax >= totalrows ? '1.5' : '1.0'}pt;
|
37
|
-
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}
|
38
40
|
STYLE
|
39
|
-
bordered or ret = ""
|
40
|
-
pb =
|
41
|
+
opt[:bordered] or ret = ""
|
42
|
+
pb = keep_rows_together(cell, rowmax, totalrows, opt) ? "avoid" : "auto"
|
41
43
|
"#{ret}page-break-after:#{pb};"
|
42
44
|
end
|
43
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
|
+
|
44
65
|
def table_attrs(node)
|
45
66
|
c = node["class"]
|
46
67
|
bordered = "border-spacing:0;border-width:1px;"
|
47
68
|
(%w(modspec).include?(c) || !c) or bordered = nil
|
48
69
|
ret = {
|
49
|
-
summary: node["summary"],
|
50
|
-
width: node["width"],
|
70
|
+
summary: node["summary"], width: node["width"],
|
51
71
|
style: "mso-table-anchor-horizontal:column;mso-table-overlap:never;" \
|
52
72
|
"#{bordered}#{keep_style(node)}",
|
53
|
-
class: (node.text.length > 4000 ? "MsoISOTableBig" : "MsoISOTable")
|
54
|
-
}
|
73
|
+
class: (node.text.length > 4000 ? "MsoISOTableBig" : "MsoISOTable") }
|
55
74
|
bordered or ret.delete(:class)
|
56
75
|
super.merge(attr_code(ret))
|
57
76
|
end
|
@@ -60,7 +79,7 @@ module IsoDoc
|
|
60
79
|
colgroup = node.at(ns("./colgroup")) or return
|
61
80
|
table.colgroup do |cg|
|
62
81
|
colgroup.xpath(ns("./col")).each do |c|
|
63
|
-
cg.col
|
82
|
+
cg.col width: c["width"]
|
64
83
|
end
|
65
84
|
end
|
66
85
|
end
|
@@ -68,7 +87,7 @@ module IsoDoc
|
|
68
87
|
def table_parse(node, out)
|
69
88
|
@in_table = true
|
70
89
|
table_title_parse(node, out)
|
71
|
-
out.div
|
90
|
+
out.div align: "center", class: "table_container" do |div|
|
72
91
|
div.table **table_attrs(node) do |t|
|
73
92
|
colgroup(node, t)
|
74
93
|
thead_parse(node, t)
|
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.3
|
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-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciimath
|
@@ -416,6 +416,7 @@ files:
|
|
416
416
|
- lib/isodoc/base_style/nav.scss
|
417
417
|
- lib/isodoc/base_style/reset.css
|
418
418
|
- lib/isodoc/base_style/reset.scss
|
419
|
+
- lib/isodoc/base_style/rouge.css
|
419
420
|
- lib/isodoc/base_style/scripts.html
|
420
421
|
- lib/isodoc/base_style/typography.css
|
421
422
|
- lib/isodoc/base_style/typography.scss
|
@@ -465,6 +466,7 @@ files:
|
|
465
466
|
- lib/isodoc/presentation_function/math.rb
|
466
467
|
- lib/isodoc/presentation_function/refs.rb
|
467
468
|
- lib/isodoc/presentation_function/section.rb
|
469
|
+
- lib/isodoc/presentation_function/sourcecode.rb
|
468
470
|
- lib/isodoc/presentation_function/terms.rb
|
469
471
|
- lib/isodoc/presentation_function/xrefs.rb
|
470
472
|
- lib/isodoc/presentation_xml_convert.rb
|
@@ -478,6 +480,8 @@ files:
|
|
478
480
|
- lib/isodoc/word_function/inline.rb
|
479
481
|
- lib/isodoc/word_function/postprocess.rb
|
480
482
|
- lib/isodoc/word_function/postprocess_cover.rb
|
483
|
+
- lib/isodoc/word_function/postprocess_table.rb
|
484
|
+
- lib/isodoc/word_function/postprocess_toc.rb
|
481
485
|
- lib/isodoc/word_function/table.rb
|
482
486
|
- lib/isodoc/xref.rb
|
483
487
|
- lib/isodoc/xref/xref_anchor.rb
|