metanorma-jis 0.0.2 → 0.0.3

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.
@@ -4,6 +4,94 @@ require "isodoc"
4
4
  module IsoDoc
5
5
  module JIS
6
6
  class PresentationXMLConvert < IsoDoc::Iso::PresentationXMLConvert
7
+ def inline(docxml)
8
+ super
9
+ strong(docxml)
10
+ end
11
+
12
+ JPAN = "\\p{Hiragana}\\p{Katakana}\\p{Han}".freeze
13
+ JPAN_BOLD = "<span style='font-family:\"MS Gothic\"'>".freeze
14
+
15
+ def strong(docxml)
16
+ docxml.xpath(ns("//strong")).each do |x|
17
+ (x.children.size == 1 && x.children.first.text?) or next # too hard
18
+ x.replace(strong1(x.text))
19
+ end
20
+ end
21
+
22
+ def strong1(text)
23
+ jpan = /^[#{JPAN}]/o.match?(text[0])
24
+ ret = jpan ? JPAN_BOLD : "<strong>"
25
+ text.split("").each do |n|
26
+ new = /^[#{JPAN}]/o.match?(n)
27
+ jpan && !new and ret += "</span><strong>"
28
+ !jpan && new and ret += "</strong>#{JPAN_BOLD}"
29
+ ret += n
30
+ jpan = new
31
+ end
32
+ ret += /[#{JPAN}]/o.match?(text[-1]) ? "</span>" : "</strong>"
33
+ ret
34
+ end
35
+
36
+ def block(docxml)
37
+ super
38
+ dl docxml
39
+ end
40
+
41
+ def dl(docxml)
42
+ docxml.xpath(ns("//table//dl | //figure//dl")).each do |l|
43
+ l.at(ns("./dl")) || l.at("./ancestor::xmlns:dl") and next
44
+ dl_to_para(l)
45
+ end
46
+ end
47
+
48
+ def dt_dd?(node)
49
+ %w{dt dd}.include? node.name
50
+ end
51
+
52
+ def dl_to_para(node)
53
+ ret = ""
54
+ e = node.at(ns("./name")) and
55
+ ret += "<p class='ListTitle' id='#{dlist['id']}'>" \
56
+ "#{e.children.to_xml}</p>"
57
+ node.elements.select { |n| dt_dd?(n) }.each_slice(2) do |dt, dd|
58
+ term = dt.children.to_xml.gsub(%r{</?p( [^>]*)>}, "")
59
+ defn = dd.children.to_xml.gsub(%r{</?p( [^>]*)>}, "")
60
+ ret += "<p id='#{dt['id']}'>#{term}: " \
61
+ "<bookmark id='#{dd['id']}'/>#{defn}</p>"
62
+ end
63
+ node.elements.each do |x|
64
+ %w(dt dd name).include?(x.name) and next
65
+ ret += x.to_xml
66
+ end
67
+ node.replace(ret.gsub(/ id=''/, ""))
68
+ end
69
+
70
+ def table1(node)
71
+ super
72
+ cols = 0
73
+ node.at(ns(".//tr")).xpath(ns("./td | ./th")).each do |x|
74
+ cols += x["colspan"]&.to_i || 1
75
+ end
76
+ name = node.at(ns("./name"))
77
+ h = node.at(ns("./thead")) || name.after("<thead> </thead>").next
78
+ unit_note = node.at(ns(".//note[@type = 'units']"))&.remove
79
+ unit_note and h.children.first.previous = full_row(cols, unit_row.to_xml)
80
+ name and h.children.first.previous =
81
+ full_row(cols, "<p class='TableTitle' style='text-align:center;'>#{name.remove.children.to_xml}</p>")
82
+ end
83
+
84
+ def full_row(cols, elem)
85
+ "<tr><td border='0' colspan='#{cols}'>#{elem}</td></tr>"
86
+ end
87
+
88
+ def annex1(elem)
89
+ lbl = @xrefs.anchor(elem["id"], :label)
90
+ if t = elem.at(ns("./title"))
91
+ t.children = "<strong>#{to_xml(t.children)}</strong>"
92
+ end
93
+ prefix_name(elem, "<br/>", lbl, "title")
94
+ end
7
95
 
8
96
  include Init
9
97
  end
@@ -0,0 +1,143 @@
1
+ require_relative "../../html2doc/lists"
2
+
3
+ module IsoDoc
4
+ module JIS
5
+ class WordConvert < IsoDoc::Iso::WordConvert
6
+ def postprocess(result, filename, dir)
7
+ filename = filename.sub(/\.doc$/, "")
8
+ header = generate_header(filename, dir)
9
+ result = from_xhtml(cleanup(to_xhtml(textcleanup(result))))
10
+ toWord(result, filename, dir, header)
11
+ @files_to_delete.each { |f| FileUtils.rm_f f }
12
+ end
13
+
14
+ def word_cleanup(docxml)
15
+ word_note_cleanup(docxml)
16
+ boldface(docxml)
17
+ super
18
+ move_to_inner_cover(docxml)
19
+ end
20
+
21
+ def move_to_inner_cover(docxml)
22
+ source = docxml.at("//div[@type = 'inner-cover-note']")
23
+ dest = docxml.at("//div[@id = 'boilerplate-inner-cover-note']")
24
+ source && dest and dest.replace(source)
25
+ source = docxml.at("//div[@type = 'contributors']")
26
+ dest = docxml.at("//div[@id = 'boilerplate-contributors']")
27
+ source && dest and dest.replace(source)
28
+ docxml
29
+ end
30
+
31
+ def word_intro(docxml, level)
32
+ intro = insert_toc(File.read(@wordintropage, encoding: "UTF-8"),
33
+ docxml, level)
34
+ intro = populate_template(intro, :word)
35
+ introxml = to_word_xhtml_fragment(intro)
36
+ docxml.at('//div[@class="WordSection2"]') << introxml
37
+ .to_xml(encoding: "US-ASCII")
38
+ end
39
+
40
+ def word_note_cleanup(docxml)
41
+ docxml.xpath("//p[@class = 'Note']").each do |p|
42
+ p.xpath("//following-sibling::p").each do |p2|
43
+ p2["class"] == "Note" and
44
+ p2["class"] = "NoteCont"
45
+ end
46
+ end
47
+ end
48
+
49
+ def boldface(docxml)
50
+ docxml.xpath("//b").each do |b|
51
+ b.name = "span"
52
+ b["class"] = "Strong"
53
+ end
54
+ end
55
+
56
+ def toWord(result, filename, dir, header)
57
+ result = word_split(word_cleanup(to_xhtml(result)))
58
+ @wordstylesheet = wordstylesheet_update
59
+ result.each do |k, v|
60
+ to_word1(v, "#{filename}#{k}", dir, header)
61
+ end
62
+ header&.unlink
63
+ @wordstylesheet.unlink if @wordstylesheet.is_a?(Tempfile)
64
+ end
65
+
66
+ def to_word1(result, filename, dir, header)
67
+ result or return
68
+ result = from_xhtml(result).gsub(/-DOUBLE_HYPHEN_ESCAPE-/, "--")
69
+ ::Html2Doc::JIS.new(
70
+ filename: filename, imagedir: @localdir,
71
+ stylesheet: @wordstylesheet&.path,
72
+ header_file: header&.path, dir: dir,
73
+ asciimathdelims: [@openmathdelim, @closemathdelim],
74
+ liststyles: { ul: @ulstyle, ol: @olstyle }
75
+ ).process(result)
76
+ end
77
+
78
+ def word_split(xml)
79
+ b = xml.dup
80
+ { _cover: cover_split(xml), "": main_split(b) }
81
+ end
82
+
83
+ def cover_split(xml)
84
+ xml.at("//body").elements.each do |e|
85
+ e.name == "div" && e["class"] == "WordSection1" and next
86
+ e.remove
87
+ end
88
+ xml
89
+ end
90
+
91
+ def main_split(xml)
92
+ c = xml.at("//div[@class = 'WordSection1']")
93
+ c.next_element&.remove
94
+ c.remove
95
+ c = xml.at("//div[@class = 'WordSection2']")
96
+ c.elements.first.at("./br") and c.elements.first.remove
97
+ xml
98
+ end
99
+
100
+ STYLESMAP = {}.freeze
101
+
102
+ def style_cleanup(docxml)
103
+ new_styles(docxml)
104
+ index_cleanup(docxml)
105
+ end
106
+
107
+ def new_styles(docxml)
108
+ super
109
+ biblio_paras(docxml)
110
+ heading_to_para(docxml)
111
+ end
112
+
113
+ def biblio_paras(docxml)
114
+ docxml.xpath("//div[@class = 'normref_div']//" \
115
+ "p[not(@class) or @class = 'MsoNormal']").each do |p|
116
+ p["class"] = "NormRefText"
117
+ end
118
+ end
119
+
120
+ def heading_to_para(docxml)
121
+ docxml.xpath("//h1[@class = 'ForewordTitle']").each do |p|
122
+ p.name = "p"
123
+ p.xpath("../div/p[not(@class) or @class = 'MsoNormal']").each do |n|
124
+ n["class"] = "ForewordText"
125
+ end
126
+ end
127
+ docxml.xpath("//h1[@class = 'IntroTitle'] | //h1[@class = 'Annex'] | " \
128
+ "//h2[@class = 'Terms'] | " \
129
+ "//h3[@class = 'Terms'] | //h4[@class = 'Terms'] | " \
130
+ "//h5[@class = 'Terms'] | //h6[@class = 'Terms']").each do |p|
131
+ p.name = "p"
132
+ end
133
+ end
134
+
135
+ def word_annex_cleanup1(docxml, lvl)
136
+ docxml.xpath("//h#{lvl}[ancestor::*[@class = 'Section3']]").each do |h2|
137
+ h2.name = "p"
138
+ h2["class"] = ".h#{lvl}Annex"
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
@@ -1,7 +1,7 @@
1
- require_relative "../../html2doc/lists"
2
1
  require_relative "base_convert"
3
2
  require "isodoc"
4
3
  require_relative "init"
4
+ require_relative "word_cleanup"
5
5
 
6
6
  module IsoDoc
7
7
  module JIS
@@ -14,6 +14,11 @@ module IsoDoc
14
14
 
15
15
  def init_dis(opt); end
16
16
 
17
+ def clause_attrs(node)
18
+ # capture the type of clause
19
+ { id: node["id"], type: node["type"] }
20
+ end
21
+
17
22
  def convert(input_filename, file = nil, debug = false,
18
23
  output_filename = nil)
19
24
  file = File.read(input_filename, encoding: "utf-8") if file.nil?
@@ -56,85 +61,10 @@ module IsoDoc
56
61
  olstyle: "l8" }
57
62
  end
58
63
 
59
- def postprocess(result, filename, dir)
60
- filename = filename.sub(/\.doc$/, "")
61
- header = generate_header(filename, dir)
62
- result = from_xhtml(cleanup(to_xhtml(textcleanup(result))))
63
- toWord(result, filename, dir, header)
64
- @files_to_delete.each { |f| FileUtils.rm_f f }
65
- end
66
-
67
- def word_cleanup(docxml)
68
- word_note_cleanup(docxml)
69
- boldface(docxml)
70
- super
71
- end
72
-
73
- def word_note_cleanup(docxml)
74
- docxml.xpath("//p[@class = 'Note']").each do |p|
75
- p.xpath("//following-sibling::p").each do |p2|
76
- p2["class"] == "Note" and
77
- p2["class"] = "NoteCont"
78
- end
79
- end
80
- end
81
-
82
- def boldface(docxml)
83
- docxml.xpath("//h1 | h2 | h3 | h4 | h5 | h6").each do |h|
84
- h.children = "<b>#{to_xml(h.children)}</b>"
85
- end
86
- docxml.xpath("//b").each do |b|
87
- b.name = "span"
88
- b["class"] = "Strong"
89
- end
90
- end
91
-
92
- def toWord(result, filename, dir, header)
93
- result = word_split(word_cleanup(to_xhtml(result)))
94
- @wordstylesheet = wordstylesheet_update
95
- result.each do |k, v|
96
- to_word1(v, "#{filename}#{k}", dir, header)
97
- end
98
- header&.unlink
99
- @wordstylesheet.unlink if @wordstylesheet.is_a?(Tempfile)
100
- end
101
-
102
- def to_word1(result, filename, dir, header)
103
- result or return
104
- result = from_xhtml(result).gsub(/-DOUBLE_HYPHEN_ESCAPE-/, "--")
105
- ::Html2Doc::JIS.new(
106
- filename: filename, imagedir: @localdir,
107
- stylesheet: @wordstylesheet&.path,
108
- header_file: header&.path, dir: dir,
109
- asciimathdelims: [@openmathdelim, @closemathdelim],
110
- liststyles: { ul: @ulstyle, ol: @olstyle }
111
- ).process(result)
112
- end
113
-
114
- def word_split(xml)
115
- b = xml.dup
116
- { _cover: cover_split(xml), "": main_split(b) }
117
- end
118
-
119
- def cover_split(xml)
120
- xml.at("//body").elements.each do |e|
121
- e.name == "div" && e["class"] == "WordSection1" and next
122
- e.remove
123
- end
124
- xml
125
- end
126
-
127
- def main_split(xml)
128
- c = xml.at("//div[@class = 'WordSection1']")
129
- c.next_element&.remove
130
- c.remove
131
- xml
132
- end
133
-
134
64
  def norm_ref(isoxml, out, num)
135
65
  (f = isoxml.at(ns(norm_ref_xpath)) and f["hidden"] != "true") or
136
66
  return num
137
- out.div class: "normref" do |div|
67
+ out.div class: "normref_div" do |div|
138
68
  num += 1
139
69
  clause_name(f, f.at(ns("./title")), div, nil)
140
70
  if f.name == "clause"
@@ -167,26 +97,228 @@ module IsoDoc
167
97
  end
168
98
  end
169
99
 
170
- def new_styles(docxml)
171
- super
172
- biblio_paras(docxml)
173
- heading_to_para(docxml)
100
+ def preface(isoxml, out)
101
+ isoxml.xpath(ns("//preface/clause | //preface/references | " \
102
+ "//preface/definitions | //preface/terms")).each do |f|
103
+ out.div **attr_code(class: "Section3", id: f["id"],
104
+ type: f["type"]) do |div|
105
+ clause_name(f, f&.at(ns("./title")), div, { class: "IntroTitle" })
106
+ f.elements.each do |e|
107
+ parse(e, div) unless e.name == "title"
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ def introduction(isoxml, out)
114
+ f = isoxml.at(ns("//introduction")) || return
115
+ out.div class: "Section3", id: f["id"] do |div|
116
+ clause_name(f, f.at(ns("./title")), div, { class: "IntroTitle" })
117
+ f.elements.each do |e|
118
+ parse(e, div) unless e.name == "title"
119
+ end
120
+ end
121
+ end
122
+
123
+ def make_body2(body, docxml)
124
+ body.div class: "WordSection2" do |div2|
125
+ boilerplate docxml, div2
126
+ preface_block docxml, div2
127
+ abstract docxml, div2
128
+ foreword docxml, div2
129
+ preface docxml, div2
130
+ acknowledgements docxml, div2
131
+ div2.p { |p| p << "&#xa0;" } # placeholder
132
+ end
133
+ section_break(body)
134
+ end
135
+
136
+ def middle(isoxml, out)
137
+ middle_title(isoxml, out)
138
+ middle_admonitions(isoxml, out)
139
+ introduction isoxml, out
140
+ scope isoxml, out, 0
141
+ norm_ref isoxml, out, 0
142
+ terms_defs isoxml, out, 0
143
+ symbols_abbrevs isoxml, out, 0
144
+ clause isoxml, out
145
+ annex isoxml, out
146
+ bibliography isoxml, out
147
+ # colophon isoxml, out
148
+ end
149
+
150
+ def figure_attrs(node)
151
+ attr_code(id: node["id"], class: "MsoTableGrid",
152
+ style: "border-collapse:collapse;" \
153
+ "border:none;mso-padding-alt: " \
154
+ "0cm 5.4pt 0cm 5.4pt;mso-border-insideh:none;" \
155
+ "mso-border-insidev:none;#{keep_style(node)}",
156
+ border: 0, cellspacing: 0, cellpadding: 0)
157
+ end
158
+
159
+ def figure_components(node)
160
+ { units: node.at(ns("./note[@type = 'units']/p")),
161
+ notes_etc: figure_notes_examples_paras(node
162
+ .xpath(ns("./note[not(@type = 'units')] | ./example | ./p"))),
163
+ name: node.at(ns("./name")),
164
+ key: node.at(ns("./dl")),
165
+ img: node.at(ns("./image")),
166
+ aside: node.at(ns("./aside")),
167
+ subfigs: node.xpath(ns("./figure")).map { |n| figure_components(n) } }
168
+ end
169
+
170
+ def figure_notes_examples_paras(xpath)
171
+ xpath.empty? and return nil
172
+ curr = ""
173
+ xpath.each_with_object([]) do |e, m|
174
+ e.name == curr or m << []
175
+ curr = e.name
176
+ m[-1] << e
177
+ end
178
+ end
179
+
180
+ def figure_parse1(node, out)
181
+ c = figure_components(node)
182
+ out.table **figure_attrs(node) do |div|
183
+ %i(units img subfigs key notes_etc aside name).each do |key|
184
+ case key
185
+ when :subfigs
186
+ c[key].each do |n|
187
+ n[:subname] = n[:name]
188
+ figure_row(node, div, n, :img)
189
+ figure_row(node, div, n, :subname)
190
+ end
191
+ when :notes_etc
192
+ c[key].each do |n|
193
+ figure_row(node, div, n, :notes_etc)
194
+ end
195
+ else figure_row(node, div, c, key)
196
+ end
197
+ end
198
+ end
199
+ end
200
+
201
+ def figure_name_parse(_node, div, name)
202
+ name.nil? and return
203
+ div.p class: "Tabletitle", style: "text-align:center;" do |p|
204
+ name.children.each { |n| parse(n, p) }
205
+ end
206
+ end
207
+
208
+ def figure_row(node, table, hash, key)
209
+ key != :notes_etc && (
210
+ hash[key].nil? || (hash[key].is_a?(Array) && hash[key].empty?)) and
211
+ return
212
+ table.tr do |r|
213
+ r.td valign: "top", style: "padding:0cm 5.4pt 0cm 5.4pt" do |d|
214
+ figure_row1(node, d, hash, key)
215
+ end
216
+ end
217
+ end
218
+
219
+ def fig_para(klass, row, nodes)
220
+ row.td valign: "top", style: "padding:0cm 5.4pt 0cm 5.4pt" do |d|
221
+ d.p class: klass do |p|
222
+ nodes.each { |n| parse(n, p) }
223
+ end
224
+ end
225
+ end
226
+
227
+ def figure_row1(node, cell, hash, key)
228
+ case key
229
+ when :units
230
+ cell.p class: "UnitStatement" do |p|
231
+ hash[key].children.each { |n| parse(n, p) }
232
+ end
233
+ when :key
234
+ figure_key(cell)
235
+ parse(hash[key], cell)
236
+ when :notes_etc, :aside
237
+ hash.each { |n| parse(n, cell) }
238
+ when :name then figure_name_parse(node, cell, hash[key])
239
+ when :img
240
+ cell.p class: "Figure" do |p|
241
+ parse(hash[key], p)
242
+ end
243
+ when :subname
244
+ cell.p class: "SubfigureCaption" do |p|
245
+ hash[key].children.each { |n| parse(n, p) }
246
+ end
247
+ end
174
248
  end
175
249
 
176
- def biblio_paras(docxml)
177
- docxml.xpath("//div[@class = 'normref']//" \
178
- "p[not(@class) or @class = 'MsoNormal']").each do |p|
179
- p["class"] = "NormRefText"
250
+ def footnote_parse(node, out)
251
+ return table_footnote_parse(node, out) if @in_table || @in_figure # &&
252
+
253
+ # !node.ancestors.map(&:name).include?("name")
254
+
255
+ fn = node["reference"] || UUIDTools::UUID.random_create.to_s
256
+ return seen_footnote_parse(node, out, fn) if @seen_footnote.include?(fn)
257
+
258
+ @fn_bookmarks[fn] = bookmarkid
259
+ out.span style: "mso-bookmark:_Ref#{@fn_bookmarks[fn]}" do |s|
260
+ s.a class: "FootnoteRef", "epub:type": "footnote",
261
+ href: "#ftn#{fn}" do |a|
262
+ a.sup { |sup| sup << fn }
263
+ end
180
264
  end
265
+ @in_footnote = true
266
+ @footnotes << make_generic_footnote_text(node, fn)
267
+ @in_footnote = false
268
+ @seen_footnote << fn
181
269
  end
182
270
 
183
- def heading_to_para(docxml)
184
- docxml.xpath("//h1[@class = 'ForewordTitle']").each do |p|
185
- p.name = "p"
186
- p.xpath("../div/p[not(@class) or @class = 'MsoNormal']").each do |n|
187
- n["class"] = "ForewordText"
271
+ def make_table_footnote_target(out, fnid, fnref)
272
+ attrs = { id: fnid, class: "TableFootnoteRef" }
273
+ out.span do |s|
274
+ s << @i18n.table_footnote
275
+ out.span **attrs do |a|
276
+ a << "#{fnref})"
188
277
  end
278
+ insert_tab(s, 1)
279
+ end
280
+ end
281
+
282
+ def table_title_parse(node, out); end
283
+
284
+ def table_attrs(node)
285
+ { id: node["id"], title: node["alt"],
286
+ summary: node["summary"], width: node["width"],
287
+ class: (node.text.length > 4000 ? "MsoTableGridBig" : "MsoTableGrid"),
288
+ style: "border-collapse:collapse;" \
289
+ "mso-table-anchor-horizontal:column;mso-table-overlap:never;" \
290
+ "border:none;mso-padding-alt: " \
291
+ "0cm 5.4pt 0cm 5.4pt;mso-border-insideh:none;" \
292
+ "mso-border-insidev:none;#{keep_style(node)}",
293
+ border: 0, cellspacing: 0, cellpadding: 0 }
294
+ end
295
+
296
+ def make_tr_attr_style(cell, row, rowmax, totalrows, opt)
297
+ top = row.zero? ? "#{SW1} 1.5pt;" : "none;"
298
+ bottom = "#{SW1} #{rowmax >= totalrows ? '1.5' : '1.0'}pt;"
299
+ ret = <<~STYLE.gsub(/\n/, "")
300
+ border-top:#{top}mso-border-top-alt:#{top}
301
+ border-left:#{bottom}mso-border-top-alt:#{bottom}
302
+ border-right:#{bottom}mso-border-top-alt:#{bottom}
303
+ border-bottom:#{bottom}mso-border-bottom-alt:#{bottom}
304
+ STYLE
305
+ opt[:bordered] or ret = ""
306
+ pb = keep_rows_together(cell, rowmax, totalrows, opt) ? "avoid" : "auto"
307
+ "#{ret}page-break-after:#{pb};"
308
+ end
309
+
310
+ def new_fullcolspan_row(table, tfoot)
311
+ # how many columns in the table?
312
+ cols = 0
313
+ table.at(".//tr").xpath("./td | ./th").each do |td|
314
+ cols += (td["colspan"] ? td["colspan"].to_i : 1)
189
315
  end
316
+ style = "border-top:0pt;mso-border-top-alt:0pt;" \
317
+ "border-bottom:#{SW1} 1.5pt;mso-border-bottom-alt:#{SW1} 1.5pt;" \
318
+ "border-left:#{SW1} 1.5pt;mso-border-left-alt:#{SW1} 1.5pt;" \
319
+ "border-right:#{SW1} 1.5pt;mso-border-right-alt:#{SW1} 1.5pt;"
320
+ tfoot.add_child("<tr><td colspan='#{cols}' style='#{style}'/></tr>")
321
+ tfoot.xpath(".//td").last
190
322
  end
191
323
 
192
324
  include BaseConvert
@@ -1,6 +1,13 @@
1
1
  module IsoDoc
2
2
  module JIS
3
3
  class Xref < IsoDoc::Iso::Xref
4
+ def annex_name_lbl(clause, num)
5
+ obl = l10n("(#{@labels['inform_annex']})")
6
+ clause["obligation"] == "normative" and
7
+ obl = l10n("(#{@labels['norm_annex']})")
8
+ title = Common::case_with_markup(@labels["annex"], "capital", @script)
9
+ l10n("#{title} #{num}<br/>#{obl}")
10
+ end
4
11
  end
5
12
  end
6
13
  end
@@ -0,0 +1,42 @@
1
+ module Metanorma
2
+ module JIS
3
+ class Converter < ISO::Converter
4
+ def norm_ref_preface(ref)
5
+ if ref.at("./note[@type = 'boilerplate']")
6
+ unwrap_boilerplate_clauses(ref, ".")
7
+ else
8
+ pref = if ref_empty?(ref) then @i18n.norm_empty_pref
9
+ else @i18n.get[ref_dated(ref)]
10
+ end
11
+ ref.at("./title").next = "<p>#{pref}</p>"
12
+ end
13
+ end
14
+
15
+ def ref_empty?(ref)
16
+ ref.xpath(".//bibitem").empty?
17
+ end
18
+
19
+ def ref_dated(ref)
20
+ refs = ref.xpath("./bibitem").each_with_object({}) do |e, m|
21
+ if e.at("./date") then m[:dated] = true
22
+ else m[:undated] = true
23
+ end
24
+ end
25
+ refs[:dated] && refs[:undated] and return "norm_with_refs_pref"
26
+ refs[:dated] and return "norm_with_refs_pref_all_dated"
27
+ "norm_with_refs_pref_none_dated"
28
+ end
29
+
30
+ def table_footnote_renumber(xmldoc)
31
+ xmldoc.xpath("//table | //figure").each do |t|
32
+ seen = {}
33
+ i = 0
34
+ #t.xpath(".//fn[not(ancestor::name)]").each do |fn|
35
+ t.xpath(".//fn").each do |fn|
36
+ i, seen = table_footnote_renumber1(fn, i, seen)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,6 +1,8 @@
1
1
  require "asciidoctor"
2
2
  require "metanorma-iso"
3
3
  require_relative "./front"
4
+ require_relative "./validate"
5
+ require_relative "./cleanup"
4
6
 
5
7
  module Metanorma
6
8
  module JIS
@@ -16,6 +18,13 @@ module Metanorma
16
18
  super
17
19
  end
18
20
 
21
+ def doctype(node)
22
+ ret = node.attr("doctype")&.gsub(/\s+/, "-")&.downcase ||
23
+ "japanese-industrial-standard"
24
+ ret = "japanese-industrial-standard" if ret == "article"
25
+ ret
26
+ end
27
+
19
28
  def boilerplate_file(_x_orig)
20
29
  File.join(@libdir, "jis_intro_jp.xml")
21
30
  end
@@ -39,8 +48,6 @@ module Metanorma
39
48
  def pdf_converter(node)
40
49
  return if node.attr("no-pdf")
41
50
 
42
- return
43
-
44
51
  if node.nil?
45
52
  IsoDoc::JIS::PdfConvert.new({})
46
53
  else
@@ -55,19 +62,6 @@ module Metanorma
55
62
  IsoDoc::JIS::PresentationXMLConvert.new(doc_extract_attributes(node))
56
63
  end
57
64
  end
58
-
59
- def script_validate(xmldoc)
60
- script = xmldoc&.at("//bibdata/script")&.text
61
- %w(Jpan Latn).include?(script) or
62
- @log.add("Document Attributes", nil,
63
- "#{script} is not a recognised script")
64
- end
65
-
66
- def validate(doc)
67
- content_validate(doc)
68
- schema_validate(formattedstr_strip(doc.dup),
69
- File.join(File.dirname(__FILE__), "jis.rng"))
70
- end
71
65
  end
72
66
  end
73
67
  end