Skip to content

Commit 97288bd

Browse files
authored
Merge pull request #251 from metanorma/feature/presxml-autonum
Feature/presxml autonum
2 parents 78b74e7 + 92604ac commit 97288bd

26 files changed

+4602
-3110
lines changed

Gemfile.devel

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "feature/presxml-autonum"
2+
gem "metanorma-iso", git: "https://github.com/metanorma/metanorma-iso", branch: "feature/presxml-autonum"
3+
gem "isodoc-i18n", git: "https://github.com/metanorma/isodoc-i18n", branch: "fix/markup-connectives"
4+
gem "mn-requirements", git: "https://github.com/metanorma/mn-requirements", branch: "feature/presxml-autonum"
5+

lib/isodoc/jis/base_convert.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
module IsoDoc
55
module Jis
66
module BaseConvert
7-
def termnote_parse(node, out)
7+
# KILL
8+
def termnote_parsex(node, out)
89
name = node.at(ns("./name"))&.remove
910
out.div **note_attrs(node) do |div|
1011
div.p do |p|
@@ -30,7 +31,7 @@ def annex(node, out)
3031
page_break(out)
3132
out.div **attr_code(annex_attrs(node)) do |s|
3233
node.elements.each do |c1|
33-
if c1.name == "title" then annex_name(node, c1, s)
34+
if c1.name == "fmt-title" then annex_name(node, c1, s)
3435
else parse(c1, s) end
3536
end
3637
end
@@ -41,7 +42,7 @@ def commentary(node, out)
4142
page_break(out)
4243
out.div **attr_code(annex_attrs(node)) do |s|
4344
node.elements.each do |c1|
44-
if c1.name == "title" then annex_name(node, c1, s)
45+
if c1.name == "fmt-title" then annex_name(node, c1, s)
4546
else parse(c1, s)
4647
end
4748
end
@@ -50,7 +51,7 @@ def commentary(node, out)
5051

5152
def table_parse(node, out)
5253
cols = table_cols_count(node)
53-
name = node.at(ns("./name"))
54+
name = node.at(ns("./fmt-name"))
5455
thead = table_thead_pt(node, name)
5556
table_name(name, thead, cols)
5657
super

lib/isodoc/jis/figure.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def figure_components(node)
1414
{ units: node.at(ns("./note[@type = 'units']")),
1515
notes_etc: figure_notes_examples_paras(node
1616
.xpath(ns("./note[not(@type = 'units')] | ./example | ./p"))),
17-
name: node.at(ns("./name")),
17+
name: node.at(ns("./fmt-name")),
1818
key: node.xpath(ns("./p[@class = 'ListTitle' or @class = 'dl']")),
1919
img: node.at(ns("./image")),
2020
aside: node.at(ns("./aside")),

lib/isodoc/jis/html/isodoc.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ div.Note table.dl {
13521352
margin-left: 1.0cm;
13531353
}
13541354

1355-
span.note_label, span.example_label, td.example_label, td.note_label
1355+
span.note_label, span.example_label, td.example_label, td.note_label, span.termnote_label, td.termnote_label
13561356
{
13571357
font-size: $smallerfontsize;
13581358
font-family:$headerfont;

lib/isodoc/jis/init.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@ def i18n_init(lang, script, locale, i18nyaml = nil)
2020
end
2121

2222
def bibrenderer(options = {})
23-
::Relaton::Render::Jis::General.new(options.merge(language: @lang,
24-
i18nhash: @i18n.get))
23+
::Relaton::Render::Jis::General.new(options
24+
.merge(language: @lang, i18nhash: @i18n.get))
2525
end
2626

2727
def std_docid_semantic(text)
2828
text
2929
end
30+
31+
def convert_i18n_init1(docxml)
32+
b = docxml.at("//xmlns:bibdata") or return
33+
lang = docxml.at("//xmlns:bibdata/xmlns:language") ||
34+
(docxml << "<language/>")
35+
%w(en ja).include?(lang&.text) or lang.content = "ja"
36+
super
37+
end
3038
end
3139
end
3240
end

lib/isodoc/jis/presentation_section.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def annex1(elem)
1010
if t = elem.at(ns("./title"))
1111
t.children = "<strong>#{to_xml(t.children)}</strong>"
1212
end
13-
prefix_name(elem, "<br/>", lbl, "title")
13+
prefix_name(elem, { caption: "<br/>" }, lbl, "title")
1414
end
1515

1616
def annex(docxml)
@@ -31,6 +31,7 @@ def commentary(elem)
3131
t = elem.elements.first
3232
commentary_title_hdr(t)
3333
middle_title_main(t, "CommentaryStandardName")
34+
prefix_name(elem, {}, nil, "title")
3435
end
3536

3637
def commentary_title_hdr(elem)

lib/isodoc/jis/presentation_xml_convert.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def dt_dd?(node)
6060
def dl_to_para(node)
6161
ret = dl_to_para_name(node)
6262
ret += dl_to_para_terms(node)
63-
node.elements.reject { |n| %w(dt dd name).include?(n.name) }.each do |x|
63+
node.elements.reject { |n| %w(dt dd name fmt-name).include?(n.name) }
64+
.each do |x|
6465
ret += x.to_xml
6566
end
6667
dl_id_insert(node, ret)
@@ -74,7 +75,7 @@ def dl_id_insert(node, ret)
7475
end
7576

7677
def dl_to_para_name(node)
77-
e = node.at(ns("./name")) or return ""
78+
e = node.at(ns("./fmt-name")) or return ""
7879
"<p class='ListTitle'>#{e.children.to_xml}</p>"
7980
end
8081

@@ -96,8 +97,9 @@ def strip_para(node)
9697
def table1(node)
9798
super
9899
cols = table_cols_count(node)
99-
name = node.at(ns("./name"))
100-
thead = table_thead_pt(node, name)
100+
ins = node.at(ns("./fmt-xref-label")) ||
101+
node.at(ns("./fmt-name"))
102+
thead = table_thead_pt(node, ins)
101103
table_unit_note(node, thead, cols)
102104
end
103105

lib/isodoc/jis/table.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def make_table_footnote_target(out, fnid, fnref)
66
out.span do |s|
77
s << @i18n.table_footnote
88
out.span **attrs do |a|
9-
a << "#{fnref})"
9+
a << fnref.sub(/(?!<\))$/, ")") # TODO TO Presentation XML
1010
end
1111
insert_tab(s, 1)
1212
end

lib/isodoc/jis/word_convert.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ def default_file_locations(_options)
6666
def norm_ref(node, out)
6767
node["hidden"] != "true" or return
6868
out.div class: "normref_div" do |div|
69-
clause_name(node, node.at(ns("./title")), div, nil)
69+
clause_name(node, node.at(ns("./fmt-title")), div, nil)
7070
if node.name == "clause"
71-
node.elements.each { |e| parse(e, div) unless e.name == "title" }
71+
node.elements.each { |e| parse(e, div) unless e.name == "fmt-title" }
7272
else biblio_list(node, div, false)
7373
end
7474
end
@@ -79,7 +79,7 @@ def bibliography(node, out)
7979
page_break(out)
8080
out.div class: "bibliography" do |div|
8181
div.h1 class: "Section3" do |h1|
82-
node.at(ns("./title"))&.children&.each { |c2| parse(c2, h1) }
82+
node.at(ns("./fmt-title"))&.children&.each { |c2| parse(c2, h1) }
8383
end
8484
biblio_list(node, div, true)
8585
end
@@ -101,10 +101,10 @@ def preface_attrs(node)
101101

102102
def introduction(clause, out)
103103
out.div class: "Section3", id: clause["id"] do |div|
104-
clause_name(clause, clause.at(ns("./title")), div,
104+
clause_name(clause, clause.at(ns("./fmt-title")), div,
105105
{ class: "IntroTitle" })
106106
clause.elements.each do |e|
107-
parse(e, div) unless e.name == "title"
107+
parse(e, div) unless e.name == "fmt-title"
108108
end
109109
end
110110
end
@@ -150,7 +150,7 @@ def commentary(node, out)
150150
def render_annex(out, clause)
151151
out.div **attr_code(annex_attrs(clause)) do |s|
152152
clause.elements.each do |c1|
153-
if c1.name == "title" then annex_name(clause, c1, s)
153+
if c1.name == "fmt-title" then annex_name(clause, c1, s)
154154
else parse(c1, s)
155155
end
156156
end

lib/isodoc/jis/xref.rb

+72-34
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,63 @@ def listlabel(_list, depth)
2424
class Xref < IsoDoc::Iso::Xref
2525
attr_accessor :autonumbering_style
2626

27-
def clause_sep
27+
def clausesep
2828
@autonumbering_style == :japanese ? "\u30fb" : "."
2929
end
3030

31-
def clause_counter(num, opts)
31+
def clause_counter(num, opts = { })
3232
opts[:numerals] ||= @autonumbering_style
33-
opts[:separator] ||= clause_sep
33+
opts[:separator] ||= clausesep
3434
super
3535
end
3636

37-
def list_counter(num, opts)
37+
def list_counter(num, opts = { })
3838
opts[:numerals] ||= @autonumbering_style
39-
opts[:separator] ||= clause_sep
39+
opts[:separator] ||= clausesep
4040
IsoDoc::Jis::Counter.new(num, opts)
4141
end
4242

4343
def hierfigsep
4444
@lang == "ja" ? "の" : super
4545
end
4646

47-
def subfigure_label(subfignum)
47+
def hierreqtsep
48+
@lang == "ja" ? "の" : super
49+
end
50+
51+
# KILL
52+
def subfigure_labelx(subfignum)
4853
subfignum.zero? and return ""
4954
sep = @lang == "ja" ? "の" : " "
5055
"#{sep}#{(subfignum + 96).chr})"
5156
end
5257

53-
def annex_name_lbl(clause, num)
58+
def subfigure_label(subfignum)
59+
subfignum.zero? and return
60+
(subfignum + 96).chr
61+
end
62+
63+
def subfigure_delim
64+
")"
65+
end
66+
67+
# taken from isodoc to override ISO
68+
def subfigure_anchor(elem, sublabel, label, klass, container: false)
69+
figlabel = fig_subfig_label(label, sublabel)
70+
@anchors[elem["id"]] = anchor_struct(
71+
figlabel, elem, @labels[klass] || klass.capitalize, klass,
72+
{ unnumb: elem["unnumbered"], container: }
73+
)
74+
if elem["unnumbered"] != "true"
75+
x = semx(elem, sublabel)
76+
@anchors[elem["id"]][:label] = x
77+
@anchors[elem["id"]][:xref] = @anchors[elem.parent["id"]][:xref] +
78+
subfigure_separator(markup: true) + x + delim_wrap(subfigure_delim)
79+
end
80+
end
81+
82+
# KILL
83+
def annex_name_lblx(clause, num)
5484
obl = "(#{@labels['inform_annex']})"
5585
clause["obligation"] == "normative" and
5686
obl = "(#{@labels['norm_annex']})"
@@ -59,19 +89,16 @@ def annex_name_lbl(clause, num)
5989
"#{title} #{num}<br/>#{obl}"
6090
end
6191

62-
def annex_name_anchors1(clause, num, level)
63-
@anchors[clause["id"]] =
64-
{ xref: num, label: num, level: level,
65-
subtype: "annex" }
92+
def annex_name_lbl(clause, num)
93+
super.gsub(%r{</?strong>}, "")
6694
end
6795

68-
def annex_names1(clause, num, level)
69-
annex_name_anchors1(clause, num, level)
70-
i = clause_counter(0, prefix: num)
71-
clause.xpath(ns(SUBCLAUSES)).each do |c|
72-
annex_names1(c, i.increment(c).print, level + 1)
73-
end
74-
end
96+
def annex_name_anchors1(clause, num, level)
97+
super
98+
# undo ISO "Clause A.2" in favour of "A.2"
99+
level == 2 and
100+
@anchors[clause["id"]][:xref] = semx(clause, num)
101+
end
75102

76103
def clause_order_main(docxml)
77104
[
@@ -128,31 +155,34 @@ def back_clauses_anchor_names(xml)
128155
end
129156

130157
def commentary_names(clause)
158+
#require "debug" ; binding.b
131159
preface_name_anchors(clause, 1, clause_title(clause))
132160
clause.xpath(ns(SUBCLAUSES))
133161
.each_with_object(clause_counter(0, {})) do |c, i|
134-
commentary_names1(c, clause["id"], i.increment(c).print, 2)
162+
commentary_names1(c, clause["id"], nil, i.increment(c).print, 2)
135163
end
136164
end
137165

138-
def commentary_names1(clause, root, num, level)
139-
commentary_name_anchors(clause, num, root, level)
166+
def commentary_names1(clause, root, parentnum, num, level)
167+
lbl = clause_number_semx(parentnum, clause, num)
168+
commentary_name_anchors(clause, lbl, root, level)
140169
clause.xpath(ns(SUBCLAUSES))
141-
.each_with_object(clause_counter(0, prefix: num)) do |c, i|
142-
commentary_names1(c, root, i.increment(c).print,
170+
.each_with_object(clause_counter(0)) do |c, i|
171+
commentary_names1(c, root, lbl, i.increment(c).print,
143172
level + 1)
144173
end
145174
end
146175

147176
def commentary_name_anchors(clause, num, root, level)
148177
@anchors[clause["id"]] =
149-
{ label: num, xref: l10n("#{@labels['clause']} #{num}"),
178+
{ label: num, xref: labelled_autonum(@labels["clause"], num),
150179
container: root,
151180
title: clause_title(clause), level: level, type: "clause",
152181
elem: @labels["clause"] }
153182
end
154183

155-
def list_item_anchor_names(list, list_anchor, depth, prev_label,
184+
# KILL ?
185+
def list_item_anchor_namesx(list, list_anchor, depth, prev_label,
156186
refer_list)
157187
c = list_counter(list["start"] ? list["start"].to_i - 1 : 0, {})
158188
list.xpath(ns("./li")).each do |li|
@@ -161,10 +191,11 @@ def list_item_anchor_names(list, list_anchor, depth, prev_label,
161191
{ list_anchor: list_anchor,
162192
prev_label: prev_label,
163193
refer_list: depth == 1 ? refer_list : nil })
164-
li["id"] and @anchors[li["id"]] =
194+
li["id"] ||= "_#{UUIDTools::UUID.random_create}"
195+
@anchors[li["id"]] =
165196
{ label: bare_label,
166197
bare_xref: "#{bare_label})",
167-
xref: "#{label})", type: "listitem",
198+
xref: "#{label}#{list_item_delim}", type: "listitem",
168199
refer_list: refer_list,
169200
container: list_anchor[:container] }
170201
(li.xpath(ns(".//ol")) - li.xpath(ns(".//ol//ol"))).each do |ol|
@@ -174,16 +205,23 @@ def list_item_anchor_names(list, list_anchor, depth, prev_label,
174205
end
175206
end
176207

208+
# KILL
209+
def list_anchor_names(s)
210+
super
211+
#require "debug"; binding.b
212+
end
213+
177214
def list_item_value(entry, counter, depth, opts)
178-
label1 = counter.increment(entry).listlabel(entry.parent, depth)
179215
if depth > 2
180-
base = @c.decode(opts[:prev_label]).split(/\)\s*/) # List a) 1.1.1
181-
label1 = "#{base[-1].sub(/^の/,'')}#{clause_sep}#{label1}"
182-
[label1, list_item_anchor_label(label1, opts[:list_anchor],
183-
base[0].sub(/[\p{Zs})]+$/, ""), opts[:refer_list])]
216+
# require 'debug'; binding.b
217+
label = counter.increment(entry).listlabel(entry.parent, depth)
218+
s = semx(entry, label)
219+
base = @c.decode(opts[:prev_label].gsub(%r{<[^>]+>}, "")).split(/\)\s*/) # List a) 1.1.1
220+
label = "#{base[-1].sub(/^の/,'')}#{clausesep}#{label}"
221+
#[label, J=list_item_anchor_label(opts[:prev_label] + delim_wrap(clause_sep) + s, opts[:list_anchor], base[0].sub(/[\p{Zs})]+$/, ""), opts[:refer_list])]
222+
[label, opts[:prev_label] + delim_wrap(clausesep) + s]
184223
else
185-
[label1, list_item_anchor_label(label1, opts[:list_anchor], opts[:prev_label],
186-
opts[:refer_list])]
224+
super
187225
end
188226
end
189227
end

lib/metanorma/jis/isodoc.rng

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
these elements; we just want one namespace for any child grammars
1818
of this.
1919
-->
20-
<!-- VERSION v1.4.0 -->
20+
<!-- VERSION v1.4.1 -->
2121
<grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
2222
<include href="reqt.rng"/>
2323
<include href="basicdoc.rng">

lib/relaton/render-jis/general.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def render1(doc)
2020
r = doc.relation.select { |x| x.type == "hasRepresentation" }
2121
.map { |x| @i18n.also_pub_as + render_single_bibitem(x.bibitem) }
2222
out = [render_single_bibitem(doc)] + r
23-
@i18n.l10n(out.join(". ").gsub(".. ", ". ").sub(/\.\s*$/, ""))
23+
@i18n.l10n(out.join(". ").gsub(/[.。]\. /, ". ").sub(/[.。]\s*$/, ""))
2424
end
2525

2626
def render_all(bib, type: "author-date")

0 commit comments

Comments
 (0)