isodoc 2.10.0 → 3.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/isodoc.gemspec +9 -4
- data/lib/isodoc/base_style/all.css +96 -0
- data/lib/isodoc/base_style/reset.css +96 -0
- data/lib/isodoc/base_style/reset.scss +75 -0
- data/lib/isodoc/base_style/scripts.html +45 -14
- data/lib/isodoc/class_utils.rb +4 -2
- data/lib/isodoc/convert.rb +0 -21
- data/lib/isodoc/css.rb +2 -4
- data/lib/isodoc/function/blocks.rb +37 -52
- data/lib/isodoc/function/blocks_example_note.rb +75 -29
- data/lib/isodoc/function/cleanup.rb +9 -44
- data/lib/isodoc/function/inline.rb +67 -13
- data/lib/isodoc/function/lists.rb +20 -14
- data/lib/isodoc/function/references.rb +9 -126
- data/lib/isodoc/function/reqt.rb +4 -3
- data/lib/isodoc/function/section.rb +30 -35
- data/lib/isodoc/function/section_titles.rb +22 -11
- data/lib/isodoc/function/table.rb +3 -3
- data/lib/isodoc/function/terms.rb +49 -26
- data/lib/isodoc/function/to_word_html.rb +46 -16
- data/lib/isodoc/function/utils.rb +11 -12
- data/lib/isodoc/gem_tasks.rb +1 -1
- data/lib/isodoc/html_function/footnotes.rb +2 -1
- data/lib/isodoc/html_function/html.rb +5 -7
- data/lib/isodoc/html_function/postprocess.rb +25 -6
- data/lib/isodoc/html_function/postprocess_cover.rb +13 -7
- data/lib/isodoc/html_function/postprocess_footnotes.rb +52 -47
- data/lib/isodoc/init.rb +31 -0
- data/lib/isodoc/metadata.rb +20 -13
- data/lib/isodoc/metadata_contributor.rb +5 -10
- data/lib/isodoc/metadata_date.rb +1 -1
- data/lib/isodoc/presentation_function/autonum.rb +153 -0
- data/lib/isodoc/presentation_function/bibdata.rb +4 -5
- data/lib/isodoc/presentation_function/block.rb +107 -40
- data/lib/isodoc/presentation_function/concepts.rb +184 -19
- data/lib/isodoc/presentation_function/docid.rb +78 -0
- data/lib/isodoc/presentation_function/erefs.rb +55 -31
- data/lib/isodoc/presentation_function/image.rb +64 -19
- data/lib/isodoc/presentation_function/index.rb +180 -0
- data/lib/isodoc/presentation_function/inline.rb +47 -16
- data/lib/isodoc/presentation_function/math.rb +128 -71
- data/lib/isodoc/presentation_function/metadata.rb +29 -66
- data/lib/isodoc/presentation_function/refs.rb +75 -28
- data/lib/isodoc/presentation_function/reqt.rb +7 -4
- data/lib/isodoc/presentation_function/section.rb +51 -129
- data/lib/isodoc/presentation_function/sourcecode.rb +52 -19
- data/lib/isodoc/presentation_function/terms.rb +107 -118
- data/lib/isodoc/presentation_function/title.rb +107 -0
- data/lib/isodoc/presentation_function/xrefs.rb +37 -17
- data/lib/isodoc/presentation_xml_convert.rb +24 -10
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +9 -37
- data/lib/isodoc/word_function/comments.rb +0 -1
- data/lib/isodoc/word_function/footnotes.rb +1 -1
- data/lib/isodoc/word_function/lists.rb +13 -9
- data/lib/isodoc/word_function/postprocess.rb +6 -0
- data/lib/isodoc/word_function/postprocess_cover.rb +6 -4
- data/lib/isodoc/word_function/postprocess_table.rb +1 -1
- data/lib/isodoc/word_function/postprocess_toc.rb +10 -6
- data/lib/isodoc/word_function/table.rb +2 -2
- data/lib/isodoc/xref/clause_order.rb +41 -0
- data/lib/isodoc/xref/xref_anchor.rb +31 -16
- data/lib/isodoc/xref/xref_counter.rb +18 -3
- data/lib/isodoc/xref/xref_counter_types.rb +14 -0
- data/lib/isodoc/xref/xref_gen.rb +61 -37
- data/lib/isodoc/xref/xref_gen_seq.rb +148 -81
- data/lib/isodoc/xref/xref_sect_gen.rb +84 -88
- data/lib/isodoc/xref/xref_util.rb +53 -4
- data/lib/isodoc/xref.rb +29 -10
- data/lib/isodoc/xslfo_convert.rb +14 -9
- data/lib/isodoc-yaml/i18n-ar.yaml +17 -13
- data/lib/isodoc-yaml/i18n-de.yaml +17 -13
- data/lib/isodoc-yaml/i18n-en.yaml +18 -17
- data/lib/isodoc-yaml/i18n-es.yaml +17 -13
- data/lib/isodoc-yaml/i18n-fr.yaml +17 -13
- data/lib/isodoc-yaml/i18n-ja.yaml +56 -52
- data/lib/isodoc-yaml/i18n-ru.yaml +17 -16
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +17 -13
- data/lib/nokogiri/xml/node.rb +14 -0
- data/lib/relaton/render-isodoc/config.yml +1 -1
- metadata +90 -13
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require_relative "docid"
|
|
2
|
+
|
|
1
3
|
module IsoDoc
|
|
2
4
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
|
3
5
|
def references(docxml)
|
|
@@ -5,27 +7,49 @@ module IsoDoc
|
|
|
5
7
|
renderings = references_render(docxml)
|
|
6
8
|
docxml.xpath(ns("//references/bibitem")).each do |x|
|
|
7
9
|
bibitem(x, renderings)
|
|
10
|
+
reference_name(x)
|
|
8
11
|
end
|
|
9
12
|
hidden_items(docxml)
|
|
10
13
|
move_norm_ref_to_sections(docxml)
|
|
11
|
-
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def reference_names(docxml)
|
|
17
|
+
docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
|
|
18
|
+
reference_name(ref)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def reference_name(ref)
|
|
23
|
+
ids = bibitem_ref_code(ref)
|
|
24
|
+
identifiers = render_identifier(ids)
|
|
25
|
+
reference = docid_l10n(identifiers[:metanorma] || identifiers[:sdo] ||
|
|
26
|
+
identifiers[:ordinal] || identifiers[:doi])
|
|
27
|
+
@xrefs.get[ref["id"]] = { xref: reference }
|
|
12
28
|
end
|
|
13
29
|
|
|
14
30
|
def move_norm_ref_to_sections(docxml)
|
|
15
31
|
docxml.at(ns(@xrefs.klass.norm_ref_xpath)) or return
|
|
16
|
-
s = docxml
|
|
17
|
-
docxml.at(ns("//preface"))&.after("<sections/>")&.next_element ||
|
|
18
|
-
docxml.at(ns("//annex | //bibliography"))&.before("<sections/>")
|
|
19
|
-
&.previous_element or return
|
|
32
|
+
s = move_norm_ref_to_sections_insert_pt(docxml) or return
|
|
20
33
|
docxml.xpath(ns(@xrefs.klass.norm_ref_xpath)).each do |r|
|
|
34
|
+
r.at("./ancestor::xmlns:bibliography") or next
|
|
21
35
|
s << r.remove
|
|
22
36
|
end
|
|
23
37
|
end
|
|
24
38
|
|
|
39
|
+
def move_norm_ref_to_sections_insert_pt(docxml)
|
|
40
|
+
s = docxml.at(ns("//sections")) and return s
|
|
41
|
+
s = docxml.at(ns("//preface")) and
|
|
42
|
+
return s.after("<sections/>").next_element
|
|
43
|
+
docxml.at(ns("//annex | //bibliography"))&.before("<sections/>")
|
|
44
|
+
&.previous_element
|
|
45
|
+
end
|
|
46
|
+
|
|
25
47
|
def hidden_items(docxml)
|
|
26
48
|
docxml.xpath(ns("//references[bibitem/@hidden = 'true']")).each do |x|
|
|
27
49
|
x.at(ns("./bibitem[not(@hidden = 'true')]")) and next
|
|
28
|
-
x.elements.map(&:name).any?
|
|
50
|
+
x.elements.map(&:name).any? do |n|
|
|
51
|
+
!%w(title bibitem).include?(n)
|
|
52
|
+
end and next
|
|
29
53
|
x["hidden"] = "true"
|
|
30
54
|
end
|
|
31
55
|
end
|
|
@@ -48,7 +72,7 @@ module IsoDoc
|
|
|
48
72
|
end
|
|
49
73
|
|
|
50
74
|
def bibitem(xml, renderings)
|
|
51
|
-
|
|
75
|
+
implicit_reference(xml) and xml["hidden"] = "true"
|
|
52
76
|
bibrender_item(xml, renderings)
|
|
53
77
|
end
|
|
54
78
|
|
|
@@ -73,27 +97,30 @@ module IsoDoc
|
|
|
73
97
|
end
|
|
74
98
|
|
|
75
99
|
def bibliography_bibitem_number_skip(bibitem)
|
|
76
|
-
|
|
100
|
+
implicit_reference(bibitem) ||
|
|
77
101
|
bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) ||
|
|
78
102
|
bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
|
|
103
|
+
bibitem["suppress_identifier"] == "true" ||
|
|
79
104
|
bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
|
|
80
105
|
end
|
|
81
106
|
|
|
82
107
|
def bibliography_bibitem_number(docxml)
|
|
83
108
|
i = 0
|
|
84
|
-
docxml.xpath(ns("//references
|
|
85
|
-
|
|
109
|
+
docxml.xpath(ns("//references")).each do |r|
|
|
110
|
+
r.xpath(ns("./bibitem")).each do |b|
|
|
111
|
+
i = bibliography_bibitem_number1(b, i, r["normative"] == "true")
|
|
112
|
+
end
|
|
86
113
|
end
|
|
87
|
-
|
|
114
|
+
reference_names docxml
|
|
88
115
|
bibliography_bibitem_tag(docxml)
|
|
89
116
|
end
|
|
90
117
|
|
|
91
|
-
def bibliography_bibitem_number1(bibitem, idx)
|
|
118
|
+
def bibliography_bibitem_number1(bibitem, idx, normative)
|
|
92
119
|
ins = bibliography_bibitem_number_insert_pt(bibitem)
|
|
93
120
|
mn = bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) and
|
|
94
|
-
/^\[?\d+\]?$/.match?(mn.text) and
|
|
95
|
-
|
|
96
|
-
|
|
121
|
+
/^\[?\d+\]?$/.match?(mn.text) and mn.remove # ignore numbers already inserted
|
|
122
|
+
if !bibliography_bibitem_number_skip(bibitem) && (!normative || mn)
|
|
123
|
+
# respect numeric ids in normative only if already inserted
|
|
97
124
|
idx += 1
|
|
98
125
|
ins.next =
|
|
99
126
|
"<docidentifier type='metanorma-ordinal'>[#{idx}]</docidentifier>"
|
|
@@ -102,17 +129,16 @@ module IsoDoc
|
|
|
102
129
|
end
|
|
103
130
|
|
|
104
131
|
def bibliography_bibitem_number_insert_pt(bibitem)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
132
|
+
bibitem.children.empty? and bibitem.add_child(" ")
|
|
133
|
+
unless d = bibitem.at(ns(".//docidentifier"))
|
|
134
|
+
d = bibitem.children.first
|
|
135
|
+
d.previous = " " and return d.previous
|
|
108
136
|
end
|
|
109
|
-
ins
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
def docid_prefixes(docxml)
|
|
113
|
-
docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
|
|
114
|
-
i.children = @xrefs.klass.docid_prefix(i["type"], to_xml(i.children))
|
|
137
|
+
unless ins = d.previous_element
|
|
138
|
+
d.previous = " "
|
|
139
|
+
ins = d.previous
|
|
115
140
|
end
|
|
141
|
+
ins
|
|
116
142
|
end
|
|
117
143
|
|
|
118
144
|
def bibliography_bibitem_tag(docxml)
|
|
@@ -126,17 +152,18 @@ module IsoDoc
|
|
|
126
152
|
|
|
127
153
|
def bibliography_bibitem_tag1(ref, idx, norm)
|
|
128
154
|
ref.xpath(ns("./bibitem")).each do |b|
|
|
129
|
-
|
|
155
|
+
implicit_reference(b) and next
|
|
156
|
+
b["suppress_identifier"] == "true" and next
|
|
130
157
|
idx += 1 unless b["hidden"]
|
|
131
|
-
insert_biblio_tag(b, idx, !norm,
|
|
158
|
+
insert_biblio_tag(b, idx, !norm, standard?(b))
|
|
132
159
|
end
|
|
133
160
|
idx
|
|
134
161
|
end
|
|
135
162
|
|
|
136
163
|
def insert_biblio_tag(bib, ordinal, biblio, standard)
|
|
137
164
|
datefn = date_note_process(bib)
|
|
138
|
-
ids =
|
|
139
|
-
idents =
|
|
165
|
+
ids = bibitem_ref_code(bib)
|
|
166
|
+
idents = render_identifier(ids)
|
|
140
167
|
ret = if biblio then biblio_ref_entry_code(ordinal, idents, ids,
|
|
141
168
|
standard, datefn, bib)
|
|
142
169
|
else norm_ref_entry_code(ordinal, idents, ids, standard, datefn,
|
|
@@ -186,5 +213,25 @@ module IsoDoc
|
|
|
186
213
|
ret = bib.at(ns("./docidentifier//fn")) or return ""
|
|
187
214
|
to_xml(ret.remove)
|
|
188
215
|
end
|
|
216
|
+
|
|
217
|
+
# reference not to be rendered because it is deemed implicit
|
|
218
|
+
# in the standards environment
|
|
219
|
+
def implicit_reference(bib)
|
|
220
|
+
bib["hidden"] == "true"
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
SKIP_DOCID = <<~XPATH.strip.freeze
|
|
224
|
+
@type = 'DOI' or @type = 'doi' or @type = 'ISSN' or @type = 'issn' or @type = 'ISBN' or @type = 'isbn' or starts-with(@type, 'ISSN.') or starts-with(@type, 'ISBN.') or starts-with(@type, 'issn.') or starts-with(@type, 'isbn.')
|
|
225
|
+
XPATH
|
|
226
|
+
|
|
227
|
+
def standard?(bib)
|
|
228
|
+
ret = false
|
|
229
|
+
bib.xpath(ns("./docidentifier")).each do |id|
|
|
230
|
+
id["type"].nil? ||
|
|
231
|
+
id.at(".//self::*[#{SKIP_DOCID} or @type = 'metanorma']") and next
|
|
232
|
+
ret = true
|
|
233
|
+
end
|
|
234
|
+
ret
|
|
235
|
+
end
|
|
189
236
|
end
|
|
190
237
|
end
|
|
@@ -2,26 +2,29 @@ module IsoDoc
|
|
|
2
2
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
|
3
3
|
def recommendation(docxml)
|
|
4
4
|
docxml.xpath(ns("//recommendation")).each do |f|
|
|
5
|
-
recommendation1(f, lower2cap(
|
|
5
|
+
recommendation1(f, lower2cap(f["class"]) ||
|
|
6
|
+
lower2cap(@i18n.recommendation))
|
|
6
7
|
end
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
def requirement(docxml)
|
|
10
11
|
docxml.xpath(ns("//requirement")).each do |f|
|
|
11
|
-
recommendation1(f, lower2cap(
|
|
12
|
+
recommendation1(f, lower2cap(f["class"]) ||
|
|
13
|
+
lower2cap(@i18n.requirement))
|
|
12
14
|
end
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def permission(docxml)
|
|
16
18
|
docxml.xpath(ns("//permission")).each do |f|
|
|
17
|
-
recommendation1(f, lower2cap(
|
|
19
|
+
recommendation1(f, lower2cap(f["class"]) ||
|
|
20
|
+
lower2cap(@i18n.permission))
|
|
18
21
|
end
|
|
19
22
|
end
|
|
20
23
|
|
|
21
24
|
def recommendation1(elem, type)
|
|
22
25
|
lbl = @reqt_models.model(elem["model"])
|
|
23
26
|
.recommendation_label(elem, type, xrefs)
|
|
24
|
-
prefix_name(elem,
|
|
27
|
+
prefix_name(elem, {}, l10n(lbl), "name")
|
|
25
28
|
end
|
|
26
29
|
|
|
27
30
|
def requirement_render_preprocessing(docxml); end
|
|
@@ -1,54 +1,42 @@
|
|
|
1
1
|
require_relative "refs"
|
|
2
|
+
require_relative "title"
|
|
2
3
|
|
|
3
4
|
module IsoDoc
|
|
4
5
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
|
5
|
-
def middle_title(docxml)
|
|
6
|
-
s = docxml.at(ns("//sections")) or return
|
|
7
|
-
t = @meta.get[:doctitle]
|
|
8
|
-
t.nil? || t.empty? and return
|
|
9
|
-
s.children.first.previous =
|
|
10
|
-
"<p class='zzSTDTitle1'>#{t}</p>"
|
|
11
|
-
end
|
|
12
|
-
|
|
13
6
|
def clause(docxml)
|
|
14
|
-
docxml.xpath(ns("//clause | " \
|
|
15
|
-
"//
|
|
7
|
+
docxml.xpath(ns("//clause | //terms | //definitions | //references | " \
|
|
8
|
+
"//introduction | //foreword | //preface/abstract | " \
|
|
9
|
+
"//acknowledgements | //colophon | //indexsect "))
|
|
16
10
|
.each do |f|
|
|
17
11
|
f.parent.name == "annex" &&
|
|
18
12
|
@xrefs.klass.single_term_clause?(f.parent) and next
|
|
19
|
-
|
|
20
13
|
clause1(f)
|
|
21
14
|
end
|
|
22
15
|
end
|
|
23
16
|
|
|
24
|
-
def
|
|
25
|
-
level = @xrefs.anchor(elem["id"], :level, false) ||
|
|
26
|
-
(elem.ancestors("clause, annex").size + 1)
|
|
27
|
-
t = elem.at(ns("./title")) and t["depth"] = level
|
|
17
|
+
def unnumbered_clause?(elem)
|
|
28
18
|
!elem.ancestors("boilerplate, metanorma-extension").empty? ||
|
|
29
|
-
@suppressheadingnumbers || elem["unnumbered"]
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"//preface/abstract | //acknowledgements | //terms | " \
|
|
38
|
-
"//definitions | //references | //colophon | //indexsect"
|
|
39
|
-
docxml.xpath(ns(p)).each do |f|
|
|
40
|
-
floattitle1(f)
|
|
41
|
-
end
|
|
42
|
-
# top-level
|
|
43
|
-
docxml.xpath(ns("//sections | //preface | //colophon"))
|
|
44
|
-
.each { |f| floattitle1(f) }
|
|
19
|
+
@suppressheadingnumbers || elem["unnumbered"] ||
|
|
20
|
+
elem.at("./ancestor::*[@unnumbered = 'true']")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def clausedelim
|
|
24
|
+
ret = super
|
|
25
|
+
ret && !ret.empty? or return ret
|
|
26
|
+
"<span class='fmt-autonum-delim'>#{ret}</span>"
|
|
45
27
|
end
|
|
46
28
|
|
|
47
|
-
def
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
def clause1(elem)
|
|
30
|
+
level = @xrefs.anchor(elem["id"], :level, false) ||
|
|
31
|
+
(elem.ancestors("clause, annex").size + 1)
|
|
32
|
+
lbl = @xrefs.anchor(elem["id"], :label, !unnumbered_clause?(elem))
|
|
33
|
+
if unnumbered_clause?(elem) || !lbl
|
|
34
|
+
prefix_name(elem, {}, nil, "title")
|
|
35
|
+
else
|
|
36
|
+
prefix_name(elem, { caption: "<tab/>" }, "#{lbl}#{clausedelim}",
|
|
37
|
+
"title")
|
|
51
38
|
end
|
|
39
|
+
t = elem.at(ns("./fmt-title")) and t["depth"] = level
|
|
52
40
|
end
|
|
53
41
|
|
|
54
42
|
def annex(docxml)
|
|
@@ -61,11 +49,19 @@ module IsoDoc
|
|
|
61
49
|
end
|
|
62
50
|
|
|
63
51
|
def annex1(elem)
|
|
64
|
-
lbl = @xrefs.anchor(elem["id"], :label)
|
|
65
|
-
|
|
52
|
+
lbl = @xrefs.anchor(elem["id"], :label, false)
|
|
53
|
+
# TODO: do not alter title, alter semx/@element = title
|
|
54
|
+
t = elem.at(ns("./title")) and
|
|
66
55
|
t.children = "<strong>#{to_xml(t.children)}</strong>"
|
|
56
|
+
if unnumbered_clause?(elem)
|
|
57
|
+
prefix_name(elem, {}, nil, "title")
|
|
58
|
+
else
|
|
59
|
+
prefix_name(elem, { caption: annex_delim(elem) }, lbl, "title")
|
|
67
60
|
end
|
|
68
|
-
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def annex_delim(_elem)
|
|
64
|
+
"<br/><br/>"
|
|
69
65
|
end
|
|
70
66
|
|
|
71
67
|
def single_term_clause_retitle(elem)
|
|
@@ -80,28 +76,18 @@ module IsoDoc
|
|
|
80
76
|
t = elem.at(ns("./terms | ./definitions | ./references"))
|
|
81
77
|
t.xpath(ns(".//clause | .//terms | .//definitions | .//references"))
|
|
82
78
|
.each do |c|
|
|
83
|
-
tit = c.at(ns("./title")) or
|
|
79
|
+
tit = c.at(ns("./fmt-title")) or next
|
|
84
80
|
tit["depth"] = tit["depth"].to_i - 1 unless tit["depth"] == "1"
|
|
85
81
|
end
|
|
86
82
|
end
|
|
87
83
|
|
|
88
|
-
def
|
|
89
|
-
|
|
90
|
-
term1(f)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def term1(elem)
|
|
95
|
-
lbl = @xrefs.anchor(elem["id"], :label) or return
|
|
96
|
-
prefix_name(elem, "", "#{lbl}#{clausedelim}", "name")
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def index(docxml)
|
|
100
|
-
docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove)
|
|
84
|
+
def skip_display_order?(node)
|
|
85
|
+
node.name == "floating-title"
|
|
101
86
|
end
|
|
102
87
|
|
|
103
88
|
def display_order_at(docxml, xpath, idx)
|
|
104
89
|
c = docxml.at(ns(xpath)) or return idx
|
|
90
|
+
skip_display_order?(c) and return idx
|
|
105
91
|
idx += 1
|
|
106
92
|
idx = preceding_floating_titles(c, idx)
|
|
107
93
|
c["displayorder"] = idx
|
|
@@ -110,6 +96,7 @@ module IsoDoc
|
|
|
110
96
|
|
|
111
97
|
def display_order_xpath(docxml, xpath, idx)
|
|
112
98
|
docxml.xpath(ns(xpath)).each do |c|
|
|
99
|
+
skip_display_order?(c) and next
|
|
113
100
|
idx += 1
|
|
114
101
|
idx = preceding_floating_titles(c, idx)
|
|
115
102
|
c["displayorder"] = idx
|
|
@@ -117,19 +104,6 @@ module IsoDoc
|
|
|
117
104
|
idx
|
|
118
105
|
end
|
|
119
106
|
|
|
120
|
-
def preceding_floating_titles(node, idx)
|
|
121
|
-
out = node.xpath("./preceding-sibling::*")
|
|
122
|
-
.reverse.each_with_object([]) do |p, m|
|
|
123
|
-
%w(note admonition p).include?(p.name) or break m
|
|
124
|
-
m << p
|
|
125
|
-
end
|
|
126
|
-
out.reject { |c| c["displayorder"] }.reverse.each do |c|
|
|
127
|
-
c["displayorder"] = idx
|
|
128
|
-
idx += 1
|
|
129
|
-
end
|
|
130
|
-
idx
|
|
131
|
-
end
|
|
132
|
-
|
|
133
107
|
def display_order(docxml)
|
|
134
108
|
i = 0
|
|
135
109
|
d = @xrefs.clause_order(docxml)
|
|
@@ -143,98 +117,46 @@ module IsoDoc
|
|
|
143
117
|
end
|
|
144
118
|
end
|
|
145
119
|
|
|
146
|
-
def clausetitle(docxml)
|
|
147
|
-
cjk_extended_title(docxml)
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
def cjk_search
|
|
151
|
-
lang = %w(zh ja ko).map { |x| "@language = '#{x}'" }.join(" or ")
|
|
152
|
-
%(Hans Hant Jpan Hang Kore).include?(@script) and
|
|
153
|
-
lang += " or not(@language)"
|
|
154
|
-
lang
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def cjk_extended_title(docxml)
|
|
158
|
-
l = cjk_search
|
|
159
|
-
docxml.xpath(ns("//bibdata/title[#{l}] | //floating-title[#{l}] | " \
|
|
160
|
-
"//title[@depth = '1' or not(@depth)][#{l}]")).each do |t|
|
|
161
|
-
t.text.size < 4 or next
|
|
162
|
-
t.elements.empty? or next # can't be bothered
|
|
163
|
-
t.children = @i18n.cjk_extend(t.text)
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
120
|
def preface_rearrange(doc)
|
|
168
|
-
preface_move(doc.
|
|
121
|
+
preface_move(doc.xpath(ns("//preface/abstract")),
|
|
169
122
|
%w(foreword introduction clause acknowledgements), doc)
|
|
170
|
-
preface_move(doc.
|
|
123
|
+
preface_move(doc.xpath(ns("//preface/foreword")),
|
|
171
124
|
%w(introduction clause acknowledgements), doc)
|
|
172
|
-
preface_move(doc.
|
|
125
|
+
preface_move(doc.xpath(ns("//preface/introduction")),
|
|
173
126
|
%w(clause acknowledgements), doc)
|
|
174
|
-
preface_move(doc.
|
|
127
|
+
preface_move(doc.xpath(ns("//preface/acknowledgements")),
|
|
175
128
|
%w(), doc)
|
|
176
129
|
end
|
|
177
130
|
|
|
178
|
-
def preface_move(
|
|
179
|
-
|
|
180
|
-
preface =
|
|
131
|
+
def preface_move(clauses, after, _doc)
|
|
132
|
+
clauses.empty? and return
|
|
133
|
+
preface = clauses.first.parent
|
|
134
|
+
clauses.each do |clause|
|
|
181
135
|
float = preceding_floats(clause)
|
|
182
|
-
prev = nil
|
|
183
136
|
xpath = after.map { |n| "./self::xmlns:#{n}" }.join(" | ")
|
|
184
137
|
xpath.empty? and xpath = "./self::*[not(following-sibling::*)]"
|
|
185
|
-
preface_move1(clause, preface, float,
|
|
138
|
+
preface_move1(clause, preface, float, nil, xpath)
|
|
139
|
+
end
|
|
186
140
|
end
|
|
187
141
|
|
|
188
142
|
def preface_move1(clause, preface, float, prev, xpath)
|
|
189
143
|
preface.elements.each do |x|
|
|
190
144
|
((x.name == "floating-title" || x.at(xpath)) &&
|
|
191
145
|
xpath != "./self::*[not(following-sibling::*)]") or prev = x
|
|
192
|
-
# after.include?(x.name) or next
|
|
193
146
|
x.at(xpath) or next
|
|
194
147
|
clause == prev and break
|
|
195
148
|
prev ||= preface.children.first
|
|
196
|
-
|
|
149
|
+
prev.next = clause
|
|
197
150
|
float.each { |n| prev.next = n }
|
|
198
151
|
break
|
|
199
152
|
end
|
|
200
153
|
end
|
|
201
154
|
|
|
202
|
-
def preceding_floats(clause)
|
|
203
|
-
ret = []
|
|
204
|
-
p = clause
|
|
205
|
-
while prev = p.previous_element
|
|
206
|
-
if prev.name == "floating-title"
|
|
207
|
-
ret << prev
|
|
208
|
-
p = prev
|
|
209
|
-
else break
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
ret
|
|
213
|
-
end
|
|
214
|
-
|
|
215
155
|
def rearrange_clauses(docxml)
|
|
216
156
|
preface_rearrange(docxml) # feeds toc_title
|
|
217
157
|
toc_title(docxml)
|
|
218
158
|
end
|
|
219
159
|
|
|
220
|
-
def toc_title(docxml)
|
|
221
|
-
docxml.at(ns("//preface/clause[@type = 'toc']")) and return
|
|
222
|
-
ins = toc_title_insert_pt(docxml) or return
|
|
223
|
-
id = UUIDTools::UUID.random_create.to_s
|
|
224
|
-
ins.previous = <<~CLAUSE
|
|
225
|
-
<clause type = 'toc' id='_#{id}'><title depth='1'>#{@i18n.table_of_contents}</title></clause>
|
|
226
|
-
CLAUSE
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
def toc_title_insert_pt(docxml)
|
|
230
|
-
ins = docxml.at(ns("//preface")) ||
|
|
231
|
-
docxml.at(ns("//sections | //annex | //bibliography"))
|
|
232
|
-
&.before("<preface> </preface>")
|
|
233
|
-
&.previous_element or return nil
|
|
234
|
-
ins.children.empty? and ins << " "
|
|
235
|
-
ins.children.first
|
|
236
|
-
end
|
|
237
|
-
|
|
238
160
|
def toc(docxml)
|
|
239
161
|
toc_refs(docxml)
|
|
240
162
|
end
|
|
@@ -242,7 +164,7 @@ module IsoDoc
|
|
|
242
164
|
def toc_refs(docxml)
|
|
243
165
|
docxml.xpath(ns("//toc//xref[text()]")).each do |x|
|
|
244
166
|
lbl = @xrefs.anchor(x["target"], :label) or next
|
|
245
|
-
x.
|
|
167
|
+
x.add_first_child "#{lbl}<span class='fmt-caption-delim'><tab/></span>"
|
|
246
168
|
end
|
|
247
169
|
end
|
|
248
170
|
end
|
|
@@ -34,7 +34,7 @@ module IsoDoc
|
|
|
34
34
|
|
|
35
35
|
def callouts(elem)
|
|
36
36
|
elem.xpath(ns(".//callout")).each do |c|
|
|
37
|
-
@callouts[c["target"]] = c.children
|
|
37
|
+
@callouts[c["target"]] = to_xml(c.children)
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
@@ -42,36 +42,66 @@ module IsoDoc
|
|
|
42
42
|
sourcehighlighter_css(docxml)
|
|
43
43
|
@highlighter = sourcehighlighter
|
|
44
44
|
@callouts = {}
|
|
45
|
-
docxml.xpath(ns("//sourcecode"))
|
|
45
|
+
(docxml.xpath(ns("//sourcecode")) -
|
|
46
|
+
docxml.xpath(ns("//metanorma-extension//sourcecode")))
|
|
47
|
+
.each do |f|
|
|
46
48
|
sourcecode1(f)
|
|
47
49
|
end
|
|
48
50
|
end
|
|
49
51
|
|
|
50
52
|
def sourcecode1(elem)
|
|
51
|
-
|
|
53
|
+
ret1 = semx_fmt_dup(elem)
|
|
54
|
+
#sourcecode_annot_id(elem)
|
|
52
55
|
source_label(elem)
|
|
56
|
+
source_highlight(ret1, elem["linenums"] == "true", elem["lang"])
|
|
53
57
|
callouts(elem)
|
|
54
|
-
annotations(elem)
|
|
58
|
+
annotations(elem, ret1)
|
|
59
|
+
fmt_sourcecode(elem, ret1)
|
|
55
60
|
end
|
|
56
61
|
|
|
57
|
-
def
|
|
62
|
+
def fmt_sourcecode(elem, ret1)
|
|
63
|
+
ret = Nokogiri::XML::Node.new("fmt-#{elem.name}", elem.document)
|
|
64
|
+
elem.attributes.each_key { |x| x != "id" and ret[x] = elem[x] }
|
|
65
|
+
ret1.xpath(ns("./name")).each(&:remove)
|
|
66
|
+
ret << ret1.children
|
|
67
|
+
elem << ret
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# KILL
|
|
71
|
+
def sourcecode_annot_id(elem)
|
|
72
|
+
elem.xpath(ns("./annotation")).each do |a|
|
|
73
|
+
if a["original-id"]
|
|
74
|
+
a["id"] = a["original-id"]
|
|
75
|
+
a.delete("original-id")
|
|
76
|
+
end
|
|
77
|
+
a.xpath(".//*[@original-id]").each do |n|
|
|
78
|
+
n["id"] = n["original-id"]
|
|
79
|
+
n.delete("original-id")
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def annotations(elem, fmt_elem)
|
|
58
85
|
elem.at(ns("./annotation")) or return
|
|
59
86
|
ret = ""
|
|
60
87
|
elem.xpath(ns("./annotation")).each do |a|
|
|
61
|
-
a
|
|
88
|
+
id = a['original-id']
|
|
89
|
+
dd = semx_fmt_dup(a)
|
|
90
|
+
dd["source"] = a["id"]
|
|
62
91
|
ret += <<~OUT
|
|
63
|
-
<dt id='#{
|
|
64
|
-
<dd>#{
|
|
92
|
+
<dt id='#{id}'><span class='c'>#{@callouts[id]}</span></dt>
|
|
93
|
+
<dd>#{to_xml dd}</dd>
|
|
65
94
|
OUT
|
|
66
95
|
end
|
|
67
|
-
|
|
96
|
+
fmt_elem.xpath(ns("./annotation")).each(&:remove)
|
|
97
|
+
fmt_elem << "<dl><name>#{@i18n.key}</name>#{ret}</dl>"
|
|
68
98
|
end
|
|
69
99
|
|
|
70
|
-
def source_highlight(elem)
|
|
100
|
+
def source_highlight(elem, linenums, lang)
|
|
71
101
|
@highlighter or return
|
|
72
102
|
markup = source_remove_markup(elem)
|
|
73
|
-
p = source_lex(elem)
|
|
74
|
-
elem.children = if
|
|
103
|
+
p = source_lex(elem, lang)
|
|
104
|
+
elem.children = if linenums
|
|
75
105
|
r = sourcecode_table_to_elem(elem, p)
|
|
76
106
|
source_restore_markup_table(r, markup)
|
|
77
107
|
else
|
|
@@ -140,9 +170,9 @@ module IsoDoc
|
|
|
140
170
|
r
|
|
141
171
|
end
|
|
142
172
|
|
|
143
|
-
def source_lex(elem)
|
|
144
|
-
lexer =
|
|
145
|
-
|
|
173
|
+
def source_lex(elem, lang)
|
|
174
|
+
lexer = Rouge::Lexer.find(lang || "plaintext") ||
|
|
175
|
+
Rouge::Lexer.find("plaintext")
|
|
146
176
|
l = Rouge::Lexers::Escape.new(start: "{^^{", end: "}^^}", lang: lexer)
|
|
147
177
|
source = to_xml(elem.children).gsub(/</, "{^^{<").gsub(/>/, ">}^^}")
|
|
148
178
|
l.lang.reset!
|
|
@@ -150,10 +180,13 @@ module IsoDoc
|
|
|
150
180
|
end
|
|
151
181
|
|
|
152
182
|
def source_label(elem)
|
|
153
|
-
labelled_ancestor(elem)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
183
|
+
if !labelled_ancestor(elem) && # do not number if labelled_ancestor
|
|
184
|
+
lbl = @xrefs.anchor(elem["id"], :label, false)
|
|
185
|
+
#a = autonum(elem["id"], lbl)
|
|
186
|
+
#s = "<span class='fmt-element-name'>#{lower2cap @i18n.figure}</span> #{a}"
|
|
187
|
+
s = labelled_autonum(lower2cap(@i18n.figure), elem["id"], lbl)&.strip
|
|
188
|
+
end
|
|
189
|
+
prefix_name(elem, { caption: block_delim }, s, "name")
|
|
157
190
|
end
|
|
158
191
|
end
|
|
159
192
|
end
|