isodoc 2.4.1 → 2.4.2

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.
@@ -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'>&#xA0;</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>&#xA0;</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) ? %(&quot;#{x}&quot;) : 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'>&#xA0;</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'>&#xA0;</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'>&#xA0;</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
@@ -26,7 +26,8 @@ module IsoDoc
26
26
  rowmax = cell["rowspan"] ? row + cell["rowspan"].to_i - 1 : row
27
27
  style += make_tr_attr_style(row, rowmax, totalrows, header, bordered)
28
28
  { rowspan: cell["rowspan"], colspan: cell["colspan"],
29
- valign: cell["valign"], align: cell["align"], style: style }
29
+ valign: cell["valign"], align: cell["align"], style: style,
30
+ class: cell["class"] }
30
31
  end
31
32
 
32
33
  def make_tr_attr_style(row, rowmax, totalrows, header, bordered)
@@ -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
- next if @anchors[n["id"]] || blank?(n["id"])
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.1
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-19 00:00:00.000000000 Z
11
+ date: 2022-12-30 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,7 @@ 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_toc.rb
481
484
  - lib/isodoc/word_function/table.rb
482
485
  - lib/isodoc/xref.rb
483
486
  - lib/isodoc/xref/xref_anchor.rb