metanorma-jis 0.0.2 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff66d75cdb79e4e5c5ac3ce3710fa330b966cb593b3091445a7a40e74c06d524
4
- data.tar.gz: f85726ebe333f7d1195689ca2028f4cde3c2a4dc948a1de9307ebd5d5e0943bd
3
+ metadata.gz: 6bf51e10fbc568a6c14c9e8b4192e16f90b5dd093aff54cdc0fbdb9ef11566bb
4
+ data.tar.gz: 060bddc60dd35141b7143e36a1cd66bc4ef89b9db9fc0b5d385ea9171d3baa8b
5
5
  SHA512:
6
- metadata.gz: 6f6554baeda3c8ab8e82da6f36e6500eb89d5d639dbaaba3e3970845e3d9e0ec007c931d8f5ca4a1b1b8060bf11ef46eb4d3ab4a9074d77e042fbaedb3141140
7
- data.tar.gz: 7e3e2a87a2070fb32c477b6cb1dc678ef110f349a32a227f79a11b5b495e264adebab14babbfe6ac68602c5431c4d5f9be3aaa573ca113b0ec3d7f447b7a6096
6
+ metadata.gz: fa5e35fcdff0101c14bd5f3d713560aa8e5236e055288e328b4024268bc9e62b1fbd399d75a388b337a7779be50939fc96438cedf691106f6ef77aca56921dd6
7
+ data.tar.gz: 55665ed144401a91526a924d27a8b2134b818581627663e371fec91fe1ccf60afb384838364dfd3986798f093e03818cd9e0e9983f6371227d9b427f9b1aab5d
@@ -9,7 +9,7 @@ class Html2Doc
9
9
  end
10
10
 
11
11
  def style_list(elem, level, liststyle, listnumber)
12
- return unless liststyle
12
+ liststyle or return
13
13
  elem["level"] = level
14
14
  super
15
15
  end
@@ -24,20 +24,14 @@ class Html2Doc
24
24
  def list2para_nest(item, level, list)
25
25
  item["class"] = list2para_style(list.name, level)
26
26
  item.xpath("./p").each do |p|
27
- p["class"] = list2para_style(list.name, level)
27
+ p["class"] = list2para_class(list.name, level)
28
28
  p["style"] = item["style"]
29
+ (a = list2para_style(list.name, level)) && !a.empty? and
30
+ p["style"] = "#{a};#{p['style']}"
29
31
  p["id"] = item["id"]
30
32
  end
31
33
  item.at("./p") or return
32
34
  item.replace(item.children)
33
- =begin
34
- prev = p1.xpath("./preceding-sibling::* | ./preceding-sibling::text()")
35
- if prev[-1].name == "span" && prev[-1]["style"] == "mso-tab-count:1" &&
36
- prev.size == 2
37
- p1.children.first.previous = prev[1]
38
- p1.children.first.previous = prev[0]
39
- end
40
- =end
41
35
  end
42
36
 
43
37
  def list2para_unnest_para(para, first_p, last_p)
@@ -56,17 +50,50 @@ class Html2Doc
56
50
  end
57
51
  end
58
52
 
59
- def list2para_style(listtype, depth)
53
+ def list2para_class(listtype, depth)
60
54
  case listtype
61
- when "ul", "ol"
55
+ when "ol" then "MsoList"
56
+ when "ul"
62
57
  case depth
63
- when "1" then "MsoList"
64
- when "2", "3", "4", "5" then "MsoList#{depth}"
65
- else "MsoList6"
58
+ when "1" then "MsoListBullet"
59
+ when "2", "3", "4", "5" then "MsoListBullet#{depth}"
60
+ else "MsoListBullet6"
66
61
  end
67
62
  end
68
63
  end
69
64
 
65
+ def list2para_style(listtype, depth)
66
+ case listtype
67
+ when "ol"
68
+ ret = case depth
69
+ when "1" then "margin-left: 36.0pt;"
70
+ when "2" then "margin-left: 54.0pt;"
71
+ when "3" then "margin-left: 72.0pt;"
72
+ when "4" then "margin-left: 90.0pt;"
73
+ when "5" then "margin-left: 108.0pt;"
74
+ when "6" then "margin-left: 126.0pt;"
75
+ when "7" then "margin-left: 144.0pt;"
76
+ when "8" then "margin-left: 162.0pt;"
77
+ else "margin-left: 180.0pt;"
78
+ end
79
+ "#{ret}text-indent:-18.0pt;"
80
+ when "ul"
81
+ ret = case depth
82
+ when "1" then "margin-left: 36.0pt;"
83
+ when "2" then "margin-left: 45.95pt;"
84
+ when "3" then "margin-left: 72.0pt;"
85
+ when "4" then "margin-left: 90.0pt;"
86
+ when "5" then "margin-left: 108.0pt;"
87
+ when "6" then "margin-left: 126.0pt;"
88
+ when "7" then "margin-left: 144.0pt;"
89
+ when "8" then "margin-left: 162.0pt;"
90
+ else "margin-left: 180.0pt;"
91
+ end
92
+ "#{ret}text-indent:-18.0pt;"
93
+
94
+ end
95
+ end
96
+
70
97
  def lists(docxml, liststyles)
71
98
  super
72
99
  docxml.xpath("//p[ol | ul]").each do |p|
@@ -77,11 +104,10 @@ class Html2Doc
77
104
  u.replace(u.children)
78
105
  end
79
106
  unnest_list_paras(docxml)
80
- indent_lists(docxml)
81
107
  end
82
108
 
83
109
  def unnest_list_paras(docxml)
84
- docxml.xpath("//p[@class = 'ListContinue1' or @class = 'ListNumber1']" \
110
+ docxml.xpath("//p[@class = 'MsoList' or @class = 'MsoListBullet']" \
85
111
  "[.//p]").each do |p|
86
112
  p.at("./p") and
87
113
  list2para_unnest_para(p, p.at("./p"),
@@ -93,24 +119,6 @@ class Html2Doc
93
119
  end
94
120
  end
95
121
 
96
- def indent_lists(docxml)
97
- docxml.xpath("//div[@class = 'Note' or @class = 'Example' or " \
98
- "@class = 'Quote']").each do |d|
99
- d.xpath(".//p").each do |p|
100
- indent_lists1(p)
101
- end
102
- end
103
- end
104
-
105
- def indent_lists1(para)
106
- m = /^(ListContinue|ListNumber|MsoListContinue|MsoListNumber)(\d)$/
107
- .match(para["class"]) or return
108
- base = m[1].sub(/^Mso/, "")
109
- level = m[2].to_i + 1
110
- level = 5 if level > 5
111
- para["class"] = "#{base}#{level}-"
112
- end
113
-
114
122
  def list_add(xpath, liststyles, listtype, level)
115
123
  xpath.each do |l|
116
124
  level == 1 and l["seen"] = true and @listnumber += 1
@@ -137,23 +145,6 @@ class Html2Doc
137
145
  end
138
146
  end
139
147
 
140
- def listlabel(listtype, idx, level)
141
- case listtype
142
- when :ul then "—"
143
- when :ol then "#{listidx(idx, level)})"
144
- end
145
- end
146
-
147
- def listidx(idx, level)
148
- case level
149
- when "a" then (96 + idx).chr.to_s
150
- when "1" then idx.to_s
151
- when "i" then RomanNumerals.to_roman(idx).downcase
152
- when "A" then (64 + idx).chr.to_s
153
- when "I" then RomanNumerals.to_roman(idx).upcase
154
- end
155
- end
156
-
157
148
  def cleanup(docxml)
158
149
  super
159
150
  docxml.xpath("//div[@class = 'Quote' or @class = 'Example' or " \
@@ -5,13 +5,32 @@ module IsoDoc
5
5
  module JIS
6
6
  module BaseConvert
7
7
  def middle_title(_isoxml, out)
8
- middle_title_main(out)
8
+ middle_title_hdr(out)
9
+ middle_title_main(out, "zzSTDTitle1")
9
10
  middle_subtitle_main(out)
10
11
  # middle_title_amd(out)
11
12
  end
12
13
 
13
- def middle_title_main(out)
14
- out.p(class: "zzSTDTitle1") do |p|
14
+ def middle_title_hdr(out)
15
+ out.p(class: "JapaneseIndustrialStandard") do |p|
16
+ p << @i18n.jis
17
+ @meta.get[:unpublished] and p << @i18n.l10n("(#{@i18n.draft_label})")
18
+ insert_tab(p, 7)
19
+ p << "<span class='JIS'>JIS</span>"
20
+ end
21
+ out.p(class: "StandardNumber") do |p|
22
+ insert_tab(p, 1)
23
+ p << @meta.get[:docnumber_undated]
24
+ if yr = @meta.get[:docyear]
25
+ p << ": "
26
+ p << "<span class='EffectiveYear'>#{yr}</span>"
27
+ end
28
+ end
29
+ out.p(class: "IDT")
30
+ end
31
+
32
+ def middle_title_main(out, style)
33
+ out.p(class: style) do |p|
15
34
  p << @meta.get[:doctitleintro]
16
35
  p << " &#x2014; " if @meta.get[:doctitleintro] && @meta.get[:doctitlemain]
17
36
  p << @meta.get[:doctitlemain]
@@ -36,6 +55,92 @@ module IsoDoc
36
55
  p << "<br/><b>#{a}</b>"
37
56
  end
38
57
  end
58
+
59
+ def commentary_title(_isoxml, out)
60
+ commentary_title_hdr(out)
61
+ middle_title_main(out, "CommentaryStandardName")
62
+ end
63
+
64
+ def commentary_title_hdr(out)
65
+ out.p(class: "CommentaryStandardNumber") do |p|
66
+ p << "JIS #{@meta.get[:docnumber_undated]}"
67
+ if yr = @meta.get[:docyear]
68
+ p << ": "
69
+ p << "<span class='CommentaryEffectiveYear'>#{yr}</span>"
70
+ end
71
+ end
72
+ end
73
+
74
+ def termnote_parse(node, out)
75
+ name = node.at(ns("./name"))&.remove
76
+ out.div **note_attrs(node) do |div|
77
+ div.p do |p|
78
+ if name
79
+ p.span class: "note_label" do |s|
80
+ name.children.each { |n| parse(n, s) }
81
+ end
82
+ p << termnote_delim
83
+ end
84
+ para_then_remainder(node.first_element_child, node, p, div)
85
+ end
86
+ end
87
+ end
88
+
89
+ def admonition_name_parse(_node, div, name)
90
+ div.span class: "note_label" do |s|
91
+ name.children.each { |n| parse(n, s) }
92
+ s << " &#x2014; "
93
+ end
94
+ end
95
+
96
+ def para_class(node)
97
+ super || node["class"]
98
+ end
99
+
100
+ def make_tr_attr(cell, row, totalrows, header, bordered)
101
+ cell["border"] == "0" and bordered = false
102
+ super
103
+ end
104
+
105
+ def middle(isoxml, out)
106
+ middle_title(isoxml, out)
107
+ middle_admonitions(isoxml, out)
108
+ scope isoxml, out, 0
109
+ norm_ref isoxml, out, 0
110
+ clause_etc isoxml, out, 0
111
+ annex isoxml, out
112
+ bibliography isoxml, out
113
+ commentary isoxml, out
114
+ indexsect isoxml, out
115
+ end
116
+
117
+ def annex(isoxml, out)
118
+ amd(isoxml) and @suppressheadingnumbers = @oldsuppressheadingnumbers
119
+ isoxml.xpath(ns("//annex[not(@commentary = 'true')]")).each do |c|
120
+ page_break(out)
121
+ out.div **attr_code(annex_attrs(c)) do |s|
122
+ c.elements.each do |c1|
123
+ if c1.name == "title" then annex_name(c, c1, s)
124
+ else parse(c1, s)
125
+ end
126
+ end
127
+ end
128
+ end
129
+ amd(isoxml) and @suppressheadingnumbers = true
130
+ end
131
+
132
+ def commentary(isoxml, out)
133
+ isoxml.xpath(ns("//annex[@commentary = 'true']")).each do |c|
134
+ page_break(out)
135
+ out.div **attr_code(annex_attrs(c)) do |s|
136
+ c.elements.each do |c1|
137
+ if c1.name == "title" then annex_name(c, c1, s)
138
+ else parse(c1, s)
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
39
144
  end
40
145
  end
41
146
  end
@@ -0,0 +1,99 @@
1
+ module IsoDoc
2
+ module JIS
3
+ class WordConvert < IsoDoc::Iso::WordConvert
4
+ def figure_attrs(node)
5
+ attr_code(id: node["id"], class: "MsoTableGrid",
6
+ style: "border-collapse:collapse;" \
7
+ "border:none;mso-padding-alt: " \
8
+ "0cm 5.4pt 0cm 5.4pt;mso-border-insideh:none;" \
9
+ "mso-border-insidev:none;#{keep_style(node)}",
10
+ border: 0, cellspacing: 0, cellpadding: 0)
11
+ end
12
+
13
+ def figure_components(node)
14
+ { units: node.at(ns("./note[@type = 'units']")),
15
+ notes_etc: figure_notes_examples_paras(node
16
+ .xpath(ns("./note[not(@type = 'units')] | ./example | ./p"))),
17
+ name: node.at(ns("./name")),
18
+ key: node.xpath(ns("./p[@class = 'ListTitle' or @class = 'dl']")),
19
+ img: node.at(ns("./image")),
20
+ aside: node.at(ns("./aside")),
21
+ source: node.at(ns("./source")),
22
+ subfigs: node.xpath(ns("./figure")).map { |n| figure_components(n) } }
23
+ end
24
+
25
+ def figure_notes_examples_paras(xpath)
26
+ xpath.empty? and return nil
27
+ curr = ""
28
+ xpath.each_with_object([]) do |e, m|
29
+ e.name == curr or m << []
30
+ curr = e.name
31
+ m[-1] << e
32
+ end
33
+ end
34
+
35
+ def figure_parse1(node, out)
36
+ c = figure_components(node)
37
+ out.table **figure_attrs(node) do |div|
38
+ %i(units img subfigs key notes_etc aside source name).each do |key|
39
+ case key
40
+ when :subfigs then figure_subfigs(node, div, c[key])
41
+ when :notes_etc, :key
42
+ c[key]&.each { |n| figure_row(node, div, n, key) }
43
+ else figure_row(node, div, c, key) end
44
+ end
45
+ end
46
+ end
47
+
48
+ def figure_subfigs(node, div, elem)
49
+ elem.each do |n|
50
+ n[:subname] = n[:name]
51
+ figure_row(node, div, n, :img)
52
+ figure_row(node, div, n, :subname)
53
+ end
54
+ end
55
+
56
+ def figure_name_parse(_node, div, name)
57
+ name.nil? and return
58
+ div.p class: "Tabletitle", style: "text-align:center;" do |p|
59
+ name.children.each { |n| parse(n, p) }
60
+ end
61
+ end
62
+
63
+ def figure_row(node, table, hash, key)
64
+ key != :notes_etc && (
65
+ hash[key].nil? || (hash[key].is_a?(Array) && hash[key].empty?)) and
66
+ return
67
+ table.tr do |r|
68
+ r.td valign: "top", style: "padding:0cm 5.4pt 0cm 5.4pt" do |d|
69
+ figure_row1(node, d, hash, key)
70
+ end
71
+ end
72
+ end
73
+
74
+ def figure_row1(node, cell, hash, key)
75
+ case key
76
+ when :units then units_render(hash[key], cell)
77
+ when :notes_etc, :aside, :key then hash.each { |n| parse(n, cell) }
78
+ when :source then parse(hash[key], cell)
79
+ when :name then figure_name_parse(node, cell, hash[key])
80
+ when :img
81
+ cell.p class: "Figure" do |p|
82
+ parse(hash[key], p)
83
+ end
84
+ when :subname
85
+ cell.p class: "SubfigureCaption" do |p|
86
+ hash[key].children.each { |n| parse(n, p) }
87
+ end
88
+ end
89
+ end
90
+
91
+ def units_render(note, cell)
92
+ para = note.at(ns("./p")) and note = para
93
+ cell.p class: "UnitStatement" do |p|
94
+ note.children.each { |n| parse(n, p) }
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end