metanorma-jis 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -49,6 +49,13 @@ module IsoDoc
49
49
  end
50
50
 
51
51
  PART_LABEL = { en: "Part", ja: "その" }.freeze
52
+
53
+ def docid(isoxml, _out)
54
+ id = isoxml.at(ns("//bibdata/docidentifier[@type = 'JIS']"))&.text or
55
+ return
56
+ set(:docnumber, id)
57
+ set(:docnumber_undated, id.sub(/:\d{4}$/, ""))
58
+ end
52
59
  end
53
60
  end
54
61
  end
@@ -4,6 +4,175 @@ 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.chars.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 admits(elem)
37
+ elem.children.first.previous = @i18n.l10n("#{@i18n.admitted}: ")
38
+ end
39
+
40
+ def block(docxml)
41
+ super
42
+ dl docxml
43
+ end
44
+
45
+ def dl(docxml)
46
+ docxml.xpath(ns("//table//dl | //figure//dl")).each do |l|
47
+ l.at(ns("./dl")) || l.at("./ancestor::xmlns:dl") and next
48
+ dl_to_para(l)
49
+ end
50
+ end
51
+
52
+ def dt_dd?(node)
53
+ %w{dt dd}.include? node.name
54
+ end
55
+
56
+ def dl_to_para(node)
57
+ ret = dl_to_para_name(node)
58
+ ret += dl_to_para_terms(node)
59
+ node.elements.reject { |n| %w(dt dd name).include?(n.name) }.each do |x|
60
+ ret += x.to_xml
61
+ end
62
+ dl_id_insert(node, ret)
63
+ end
64
+
65
+ def dl_id_insert(node, ret)
66
+ a = node.replace(ret)
67
+ p = a.at("./descendant-or-self::xmlns:p")
68
+ node["id"] and p << "<bookmark id='#{node['id']}'/>"
69
+ a.xpath("./descendant-or-self::*[@id = '']").each { |x| x.delete("id") }
70
+ end
71
+
72
+ def dl_to_para_name(node)
73
+ e = node.at(ns("./name"))
74
+ "<p class='ListTitle'>#{e&.children&.to_xml || @i18n.key}</p>"
75
+ end
76
+
77
+ def dl_to_para_terms(node)
78
+ ret = ""
79
+ node.elements.select { |n| dt_dd?(n) }.each_slice(2) do |dt, dd|
80
+ term = strip_para(dt)
81
+ defn = strip_para(dd)
82
+ bkmk = dd["id"] ? "<bookmark id='#{dd['id']}'/>" : ""
83
+ ret += "<p class='dl' id='#{dt['id']}'>#{term}: #{bkmk}#{defn}</p>"
84
+ end
85
+ ret
86
+ end
87
+
88
+ def strip_para(node)
89
+ node.children.to_xml.gsub(%r{</?p( [^>]*)?>}, "")
90
+ end
91
+
92
+ def table1(node)
93
+ super
94
+ cols = table_cols_count(node)
95
+ name = node.at(ns("./name"))
96
+ thead = table_thead_pt(node, name)
97
+ table_unit_note(node, thead, cols)
98
+ table_name(name, thead, cols)
99
+ end
100
+
101
+ def table_thead_pt(node, name)
102
+ node.at(ns("./thead")) ||
103
+ name&.after("<thead> </thead>")&.next ||
104
+ node.elements.first.before("<thead> </thead>").previous
105
+ end
106
+
107
+ def table_cols_count(node)
108
+ cols = 0
109
+ node.at(ns(".//tr")).xpath(ns("./td | ./th")).each do |x|
110
+ cols += x["colspan"]&.to_i || 1
111
+ end
112
+ cols
113
+ end
114
+
115
+ def table_unit_note(node, thead, cols)
116
+ unit_note = node.at(ns(".//note[@type = 'units']")) or return
117
+ thead.children.first.previous = full_row(cols, unit_note.remove.to_xml)
118
+ end
119
+
120
+ def table_name(name, thead, cols)
121
+ name or return
122
+ thead.children.first.previous =
123
+ full_row(cols, "<p class='TableTitle' style='text-align:center;'> " \
124
+ "#{name.remove.children.to_xml}</p>")
125
+ end
126
+
127
+ def full_row(cols, elem)
128
+ "<tr><td border='0' colspan='#{cols}'>#{elem}</td></tr>"
129
+ end
130
+
131
+ def annex1(elem)
132
+ elem["commentary"] == "true" and return
133
+ lbl = @xrefs.anchor(elem["id"], :label)
134
+ if t = elem.at(ns("./title"))
135
+ t.children = "<strong>#{to_xml(t.children)}</strong>"
136
+ end
137
+ prefix_name(elem, "<br/>", lbl, "title")
138
+ end
139
+
140
+ def annex(docxml)
141
+ super
142
+ move_commentaries_to_end(docxml)
143
+ end
144
+
145
+ def move_commentaries_to_end(docxml)
146
+ docxml.at(ns("//annex[@commentary = 'true']")) or return
147
+ b = docxml.at(ns("//bibliography")) ||
148
+ docxml.at(ns("//annex[last()]")).after(" ").next
149
+ docxml.xpath(ns("//annex[@commentary = 'true']")).reverse.each do |x|
150
+ b.next = x.remove
151
+ end
152
+ end
153
+
154
+ def display_order(docxml)
155
+ i = 0
156
+ i = display_order_xpath(docxml, "//preface/*", i)
157
+ i = display_order_at(docxml, "//clause[@type = 'scope']", i)
158
+ i = display_order_at(docxml, @xrefs.klass.norm_ref_xpath, i)
159
+ i = display_order_at(docxml, "//sections/terms | " \
160
+ "//sections/clause[descendant::terms]", i)
161
+ i = display_order_at(docxml, "//sections/definitions", i)
162
+ i = display_order_xpath(docxml, @xrefs.klass.middle_clause(docxml), i)
163
+ i = display_order_xpath(docxml, "//annex[not(@commentary = 'true')]", i)
164
+ i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i)
165
+ i = display_order_xpath(docxml, "//annex[@commentary = 'true']", i)
166
+ i = display_order_xpath(docxml, "//indexsect", i)
167
+ display_order_xpath(docxml, "//colophon/*", i)
168
+ end
169
+
170
+ def tablesource(elem)
171
+ while elem&.next_element&.name == "source"
172
+ elem << "; #{to_xml(elem.next_element.remove.children)}"
173
+ end
174
+ elem.children = l10n("#{@i18n.source}: #{to_xml(elem.children).strip}")
175
+ end
7
176
 
8
177
  include Init
9
178
  end
@@ -0,0 +1,58 @@
1
+ module IsoDoc
2
+ module JIS
3
+ class WordConvert < IsoDoc::Iso::WordConvert
4
+ def make_table_footnote_target(out, fnid, fnref)
5
+ attrs = { id: fnid, class: "TableFootnoteRef" }
6
+ out.span do |s|
7
+ s << @i18n.table_footnote
8
+ out.span **attrs do |a|
9
+ a << "#{fnref})"
10
+ end
11
+ insert_tab(s, 1)
12
+ end
13
+ end
14
+
15
+ def table_title_parse(node, out); end
16
+
17
+ def table_attrs(node)
18
+ { id: node["id"], title: node["alt"],
19
+ summary: node["summary"], width: node["width"],
20
+ class: (node.text.length > 4000 ? "MsoTableGridBig" : "MsoTableGrid"),
21
+ style: "border-collapse:collapse;" \
22
+ "mso-table-anchor-horizontal:column;mso-table-overlap:never;" \
23
+ "border:none;mso-padding-alt: " \
24
+ "0cm 5.4pt 0cm 5.4pt;mso-border-insideh:none;" \
25
+ "mso-border-insidev:none;#{keep_style(node)}",
26
+ border: 0, cellspacing: 0, cellpadding: 0 }
27
+ end
28
+
29
+ def make_tr_attr_style(cell, row, rowmax, totalrows, opt)
30
+ top = row.zero? ? "#{SW1} 1.5pt;" : "none;"
31
+ bottom = "#{SW1} #{rowmax >= totalrows ? '1.5' : '1.0'}pt;"
32
+ ret = <<~STYLE.gsub(/\n/, "")
33
+ border-top:#{top}mso-border-top-alt:#{top}
34
+ border-left:#{bottom}mso-border-top-alt:#{bottom}
35
+ border-right:#{bottom}mso-border-top-alt:#{bottom}
36
+ border-bottom:#{bottom}mso-border-bottom-alt:#{bottom}
37
+ STYLE
38
+ opt[:bordered] or ret = ""
39
+ pb = keep_rows_together(cell, rowmax, totalrows, opt) ? "avoid" : "auto"
40
+ "#{ret}page-break-after:#{pb};"
41
+ end
42
+
43
+ def new_fullcolspan_row(table, tfoot)
44
+ # how many columns in the table?
45
+ cols = 0
46
+ table.at(".//tr").xpath("./td | ./th").each do |td|
47
+ cols += (td["colspan"] ? td["colspan"].to_i : 1)
48
+ end
49
+ style = "border-top:0pt;mso-border-top-alt:0pt;" \
50
+ "border-bottom:#{SW1} 1.5pt;mso-border-bottom-alt:#{SW1} 1.5pt;" \
51
+ "border-left:#{SW1} 1.5pt;mso-border-left-alt:#{SW1} 1.5pt;" \
52
+ "border-right:#{SW1} 1.5pt;mso-border-right-alt:#{SW1} 1.5pt;"
53
+ tfoot.add_child("<tr><td colspan='#{cols}' style='#{style}'/></tr>")
54
+ tfoot.xpath(".//td").last
55
+ end
56
+ end
57
+ end
58
+ 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.remove)
25
+ source = docxml.at("//div[@type = 'contributors']")
26
+ dest = docxml.at("//div[@id = 'boilerplate-contributors']")
27
+ source && dest and dest.replace(source.remove)
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.parent.xpath("./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 |n|
131
+ n.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,9 @@
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
+ require_relative "figure"
6
+ require_relative "table"
5
7
 
6
8
  module IsoDoc
7
9
  module JIS
@@ -14,6 +16,11 @@ module IsoDoc
14
16
 
15
17
  def init_dis(opt); end
16
18
 
19
+ def clause_attrs(node)
20
+ # capture the type of clause
21
+ { id: node["id"], type: node["type"] }
22
+ end
23
+
17
24
  def convert(input_filename, file = nil, debug = false,
18
25
  output_filename = nil)
19
26
  file = File.read(input_filename, encoding: "utf-8") if file.nil?
@@ -56,85 +63,10 @@ module IsoDoc
56
63
  olstyle: "l8" }
57
64
  end
58
65
 
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
66
  def norm_ref(isoxml, out, num)
135
67
  (f = isoxml.at(ns(norm_ref_xpath)) and f["hidden"] != "true") or
136
68
  return num
137
- out.div class: "normref" do |div|
69
+ out.div class: "normref_div" do |div|
138
70
  num += 1
139
71
  clause_name(f, f.at(ns("./title")), div, nil)
140
72
  if f.name == "clause"
@@ -167,24 +99,104 @@ module IsoDoc
167
99
  end
168
100
  end
169
101
 
170
- def new_styles(docxml)
102
+ def preface(isoxml, out)
103
+ isoxml.xpath(ns("//preface/clause | //preface/references | " \
104
+ "//preface/definitions | //preface/terms")).each do |f|
105
+ out.div **attr_code(class: "Section3", id: f["id"],
106
+ type: f["type"]) do |div|
107
+ clause_name(f, f&.at(ns("./title")), div, { class: "IntroTitle" })
108
+ f.elements.each do |e|
109
+ parse(e, div) unless e.name == "title"
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+ def introduction(isoxml, out)
116
+ f = isoxml.at(ns("//introduction")) || return
117
+ out.div class: "Section3", id: f["id"] do |div|
118
+ clause_name(f, f.at(ns("./title")), div, { class: "IntroTitle" })
119
+ f.elements.each do |e|
120
+ parse(e, div) unless e.name == "title"
121
+ end
122
+ end
123
+ end
124
+
125
+ def make_body2(body, docxml)
126
+ body.div class: "WordSection2" do |div2|
127
+ boilerplate docxml, div2
128
+ preface_block docxml, div2
129
+ abstract docxml, div2
130
+ foreword docxml, div2
131
+ preface docxml, div2
132
+ acknowledgements docxml, div2
133
+ div2.p { |p| p << "&#xa0;" } # placeholder
134
+ end
135
+ section_break(body)
136
+ end
137
+
138
+ def middle(isoxml, out)
139
+ middle_title(isoxml, out)
140
+ middle_admonitions(isoxml, out)
141
+ introduction isoxml, out
142
+ scope isoxml, out, 0
143
+ norm_ref isoxml, out, 0
144
+ clause_etc isoxml, out, 0
145
+ annex isoxml, out
146
+ bibliography isoxml, out
147
+ end
148
+
149
+ def make_body3(body, docxml)
171
150
  super
172
- biblio_paras(docxml)
173
- heading_to_para(docxml)
151
+ commentary docxml, body
152
+ end
153
+
154
+ def footnote_parse(node, out)
155
+ return table_footnote_parse(node, out) if @in_table || @in_figure # &&
156
+
157
+ # !node.ancestors.map(&:name).include?("name")
158
+
159
+ fn = node["reference"] || UUIDTools::UUID.random_create.to_s
160
+ return seen_footnote_parse(node, out, fn) if @seen_footnote.include?(fn)
161
+
162
+ @fn_bookmarks[fn] = bookmarkid
163
+ out.span style: "mso-bookmark:_Ref#{@fn_bookmarks[fn]}" do |s|
164
+ s.a class: "FootnoteRef", "epub:type": "footnote",
165
+ href: "#ftn#{fn}" do |a|
166
+ a.sup { |sup| sup << fn }
167
+ end
168
+ end
169
+ @in_footnote = true
170
+ @footnotes << make_generic_footnote_text(node, fn)
171
+ @in_footnote = false
172
+ @seen_footnote << fn
173
+ end
174
+
175
+ def annex(isoxml, out)
176
+ amd(isoxml) and @suppressheadingnumbers = @oldsuppressheadingnumbers
177
+ isoxml.xpath(ns("//annex[not(@commentary = 'true')]")).each do |c|
178
+ page_break(out)
179
+ render_annex(out, c)
180
+ end
181
+ amd(isoxml) and @suppressheadingnumbers = true
174
182
  end
175
183
 
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"
184
+ def commentary(isoxml, out)
185
+ isoxml.xpath(ns("//annex[@commentary = 'true']")).each do |c|
186
+ section_break(out)
187
+ out.div class: "WordSectionCommentary" do |div|
188
+ commentary_title(isoxml, div)
189
+ render_annex(div, c)
190
+ end
180
191
  end
181
192
  end
182
193
 
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"
194
+ def render_annex(out, clause)
195
+ out.div **attr_code(annex_attrs(clause)) do |s|
196
+ clause.elements.each do |c1|
197
+ if c1.name == "title" then annex_name(clause, c1, s)
198
+ else parse(c1, s)
199
+ end
188
200
  end
189
201
  end
190
202
  end
@@ -1,6 +1,58 @@
1
1
  module IsoDoc
2
2
  module JIS
3
+ class Counter < IsoDoc::XrefGen::Counter
4
+ end
5
+
3
6
  class Xref < IsoDoc::Iso::Xref
7
+ def annex_name_lbl(clause, num)
8
+ obl = l10n("(#{@labels['inform_annex']})")
9
+ clause["obligation"] == "normative" and
10
+ obl = l10n("(#{@labels['norm_annex']})")
11
+ title = Common::case_with_markup(@labels["annex"], "capital", @script)
12
+ l10n("#{title} #{num}<br/>#{obl}")
13
+ end
14
+
15
+ def back_anchor_names(xml)
16
+ if @parse_settings.empty? || @parse_settings[:clauses]
17
+ i = Counter.new("@")
18
+ xml.xpath(ns("//annex")).each do |c|
19
+ if c["commentary"] == "true"
20
+ commentary_names(c)
21
+ else
22
+ annex_names(c, i.increment(c).print)
23
+ end
24
+ end
25
+ xml.xpath(ns(@klass.bibliography_xpath)).each do |b|
26
+ preface_names(b)
27
+ end
28
+ xml.xpath(ns("//colophon/clause")).each { |b| preface_names(b) }
29
+ xml.xpath(ns("//indexsect")).each { |b| preface_names(b) }
30
+ end
31
+ references(xml) if @parse_settings.empty? || @parse_settings[:refs]
32
+ end
33
+
34
+ def commentary_names(clause)
35
+ preface_name_anchors(clause, 1, clause_title(clause))
36
+ clause.xpath(ns(SUBCLAUSES)).each_with_object(Counter.new) do |c, i|
37
+ commentary_names1(c, clause["id"], i.increment(c).print, 2)
38
+ end
39
+ end
40
+
41
+ def commentary_names1(clause, root, num, level)
42
+ commentary_name_anchors(clause, num, root, level)
43
+ clause.xpath(ns(SUBCLAUSES)).each_with_object(Counter.new) do |c, i|
44
+ commentary_names1(c, root, "#{num}.#{i.increment(c).print}",
45
+ level + 1)
46
+ end
47
+ end
48
+
49
+ def commentary_name_anchors(clause, num, root, level)
50
+ @anchors[clause["id"]] =
51
+ { label: num, xref: l10n("#{@labels['clause']} #{num}"),
52
+ container: root,
53
+ title: clause_title(clause), level: level, type: "clause",
54
+ elem: @labels["clause"] }
55
+ end
4
56
  end
5
57
  end
6
58
  end