metanorma-plateau 0.2.2 → 1.0.0

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.
@@ -79,6 +79,88 @@ module IsoDoc
79
79
  @iso.ol_depth(node)
80
80
  end
81
81
 
82
+ # how many columns in the table?
83
+ def table_col_count(table)
84
+ cols = 0
85
+ table&.at(ns(".//tr"))&.xpath(ns("./td | ./th"))&.each do |td|
86
+ cols += (td["colspan"] ? td["colspan"].to_i : 1)
87
+ end
88
+ cols
89
+ end
90
+
91
+ # if there is already a full-row cell at the start of tfoot, use that to move content into
92
+ # else create a full-row cell at the start of tfoot
93
+ def initial_tfoot_cell(node)
94
+ colspan = table_col_count(node)
95
+ tfoot_start = node.at(ns("./tfoot/tr/td"))
96
+ if !tfoot_start
97
+ node.at(ns("./tbody")).after("<tfoot><tr><td colspan='#{colspan}'> </td></tr></tfoot>").first
98
+ tfoot_start = node.at(ns("./tfoot/tr/td"))
99
+ end
100
+ if tfoot_start["colspan"] != colspan.to_s
101
+ tfoot_start.parent.previous = "<tr><td colspan='#{colspan}'> </td></tr>"
102
+ tfoot_start = node.at(ns("./tfoot/tr/td"))
103
+ end
104
+ tfoot_start
105
+ end
106
+
107
+ # if there is already a full-row cell at the end of tfoot, use that to move content into
108
+ # else create a full-row cell at the end of tfoot
109
+ def final_tfoot_cell(node)
110
+ colspan = table_col_count(node)
111
+ tfoot_start = node.at(ns("./tfoot/tr[last()]/td"))
112
+ if !tfoot_start
113
+ node.at(ns("./tbody")).after("<tfoot><tr><td colspan='#{colspan}'> </td></tr></tfoot>").first
114
+ tfoot_start = node.at(ns("./tfoot/tr[last()]/td"))
115
+ end
116
+ if tfoot_start["colspan"] != colspan.to_s
117
+ tfoot_start.parent.next = "<tr><td colspan='#{colspan}'> </td></tr>"
118
+ tfoot_start = node.at(ns("./tfoot/tr[last()]/td"))
119
+ end
120
+ tfoot_start
121
+ end
122
+
123
+ def table1(node)
124
+ super
125
+ # move dl, notes, footnotes, source, fmt-footnote-container inside tfoot
126
+ if node.at(ns("./dl"))
127
+ tf = initial_tfoot_cell(node)
128
+ node.xpath(ns("./dl")).reverse_each do |x|
129
+ tf.children.first.previous = x.remove
130
+ end
131
+ end
132
+ if node.at(ns("./note | ./source | ./example | ./fmt-footnote-container"))
133
+ tf = final_tfoot_cell(node)
134
+ node.xpath(ns("./example")).each { |x| tf.children.last.next = x.remove }
135
+ node.xpath(ns("./note")).each { |x| tf.children.last.next = x.remove }
136
+ node.xpath(ns("./fmt-footnote-container")).each { |x| tf.children.last.next = x.remove }
137
+ node.xpath(ns("./source")).each do |x|
138
+ tf.children.last.next = x.remove
139
+ end
140
+ end
141
+ end
142
+
143
+ # Undo JIS encoding of figure and table dl as paragraphs
144
+ def dl(docxml)
145
+ docxml.xpath(ns("//dl")).each { |f| dl1(f) }
146
+ docxml.xpath(ns("//table//dl | //figure//dl")).each do |l|
147
+ l.at(ns("./dl")) || l.at("./ancestor::xmlns:dl") and next
148
+ table_key(l)
149
+ end
150
+ end
151
+
152
+ # Insert localised colon at start of dd in table and figure key,
153
+ # replacing JIS Word <p class='dl' id='#{dt['id']}'>#{term}: #{bkmk}#{defn}</p>
154
+ # with <dt>{term}</dt> <dd>: {defn}<dd>; the space should be stripped and
155
+ # the colon double-width for Japanese text
156
+ def table_key(node)
157
+ node.xpath(ns(".//dd")).each do |dd|
158
+ text_node = dd.xpath(".//text()[normalize-space()]").first or next
159
+ colon = %w(zh ja ko).include?(@lang) ? ":": ": "
160
+ text_node.previous = "<span class='fmt-dt-delim'>#{colon}</span>"
161
+ end
162
+ end
163
+
82
164
  include Init
83
165
  end
84
166
  end
@@ -33,6 +33,15 @@
33
33
  </zeroOrMore>
34
34
  </element>
35
35
  </define>
36
+ <define name="fn" combine="interleave">
37
+ <optional>
38
+ <attribute name="hiddenref">
39
+ <a:documentation>If true, number the footnote as normal, but suppress display of the footnote reference in the document body.
40
+ This is done if the footnote reference is already presented in some other form, e.g. within a figure image.</a:documentation>
41
+ <data type="boolean"/>
42
+ </attribute>
43
+ </optional>
44
+ </define>
36
45
  <define name="index-primary">
37
46
  <element name="primary">
38
47
  <oneOrMore>
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Plateau
3
- VERSION = "0.2.2".freeze
3
+ VERSION = "1.0.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-plateau
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-04 00:00:00.000000000 Z
11
+ date: 2025-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-jis