isodoc 2.12.6 → 2.12.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48457f7d76baef2d4d349f569e3ee43049253bc9955d50f5c6584d9e8fa2367b
4
- data.tar.gz: d87899d14231920e9f2709f2ed5101049e3f0132e2f43f76a67e704c82b91309
3
+ metadata.gz: 5f9a52529adbedd3c9bfc375db556ea9402a7fcd7e384ccff66c70a2aeb2c964
4
+ data.tar.gz: 11533489300d99ed35875d79d7327e9acf918ffb4b7bd48552e870b303ce9be5
5
5
  SHA512:
6
- metadata.gz: c9f54cf72607cca29215845a2f36ca6de3a74d91a97f002157cf8c09a5baeaf37b2b71dddf2eb91eef3b1ea1c4677ebfc3f3cbfc4fee7bc97cc5d1537b43f925
7
- data.tar.gz: f0923719cd684e18c2879de8d1477c17b05fb5b3c5e2597a8189371db49aa59c531a863f96808dcc546b5bd709f3799b3dedac6dc3cf9b96ce5aeef25dda4c19
6
+ metadata.gz: 1fce7b6367b473390f95f062965d6c456c684e5eb5b3ad65622e3cb880e7aa3230f33ea11f7dd4d471c6125843747831e03742b2e17abc220ea9ed0995ee5c14
7
+ data.tar.gz: a3d34d1c3e98b88451073fe6cd585bbcec1e7c40964bd31cba17494934c864460269ca2c77db9803461448405019800ce731fbff7fef8c560bdb05196c35cc97
data/isodoc.gemspec CHANGED
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.add_dependency "mn2pdf", ">= 2.08"
38
38
  spec.add_dependency "mn-requirements", "~> 0.4.0"
39
39
 
40
- spec.add_dependency "relaton-render", "~> 0.8.0"
40
+ spec.add_dependency "relaton-render", "~> 0.9.0"
41
41
  spec.add_dependency "roman-numerals"
42
42
  spec.add_dependency "rouge", "~> 4.0"
43
43
  spec.add_dependency "thread_safe"
@@ -9,7 +9,7 @@ module IsoDoc
9
9
  def pref_ref_code(bib)
10
10
  bib["suppress_identifier"] == "true" and return nil
11
11
  ret = bib.xpath(ns("./docidentifier[@scope = 'biblio-tag']"))
12
- ret.empty? or return ret.map(&:text)
12
+ ret.empty? or return ret.map { |x| to_xml(x.children) }
13
13
  ret = pref_ref_code_parse(bib) or return nil
14
14
  ins = bib.at(ns("./docidentifier[last()]"))
15
15
  ret.reverse_each do |r|
@@ -50,14 +50,14 @@ module IsoDoc
50
50
 
51
51
  def bracket_if_num(num)
52
52
  num.nil? and return nil
53
- num = num.text.sub(/^\[/, "").sub(/\]$/, "")
53
+ num = to_xml(num.children).sub(/^\[/, "").sub(/\]$/, "")
54
54
  /^\d+$/.match?(num) and return "[#{num}]"
55
55
  num
56
56
  end
57
57
 
58
58
  def unbracket1(ident)
59
59
  ident.nil? and return nil
60
- ident.is_a?(String) or ident = ident.text
60
+ ident.is_a?(String) or ident = to_xml(ident.children)
61
61
  ident.sub(/^\[/, "").sub(/\]$/, "")
62
62
  end
63
63
 
@@ -3,11 +3,23 @@ require "metanorma-utils"
3
3
  module IsoDoc
4
4
  class PresentationXMLConvert < ::IsoDoc::Convert
5
5
  def citeas(xmldoc)
6
- xmldoc.xpath(ns("//eref | //origin | //quote//source")).each do |e|
6
+ xmldoc.xpath(ns("//eref | //origin | //quote//source | //link"))
7
+ .each do |e|
7
8
  e["bibitemid"] && e["citeas"] or next
8
- a = @xrefs.anchor(e["bibitemid"], :xref, false) and
9
- e["citeas"] = a.gsub(%r{</?[^>]+>}, "")
9
+ a = @xrefs.anchor(e["bibitemid"], :xref, false) or next
10
+ e["citeas"] = citeas_cleanup(a)
11
+ # link generated in collection postprocessing from eref
12
+ e.name == "link" && e.text.empty? and e.children = e["citeas"]
13
+ end
14
+ end
15
+
16
+ def citeas_cleanup(ref)
17
+ if /</.match?(ref)
18
+ xml = Nokogiri::XML("<root>#{ref}</root>")
19
+ xml.xpath("//semx").each { |x| x.replace(x.children) }
20
+ ref = to_xml(xml.at("//root").children)
10
21
  end
22
+ ref
11
23
  end
12
24
 
13
25
  def expand_citeas(text)
@@ -0,0 +1,180 @@
1
+ module IsoDoc
2
+ class PresentationXMLConvert < ::IsoDoc::Convert
3
+ def enable_indexsect
4
+ false
5
+ end
6
+
7
+ def add_id
8
+ %(id="_#{UUIDTools::UUID.random_create}")
9
+ end
10
+
11
+ def strip_index(docxml)
12
+ docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove)
13
+ end
14
+
15
+ def index(xml)
16
+ if enable_indexsect && xml.at(ns("//index"))
17
+ i = xml.at(ns("//indexsect")) ||
18
+ xml.root.add_child("<indexsect #{add_id}><title>#{@i18n.index}" \
19
+ "</title></indexsect>").first
20
+ index = sort_indexterms(xml.xpath(ns("//index")),
21
+ xml.xpath(ns("//index-xref[@also = 'false']")),
22
+ xml.xpath(ns("//index-xref[@also = 'true']")))
23
+ index1(xml, i, index)
24
+ else strip_index(xml)
25
+ end
26
+ end
27
+
28
+ def index1(docxml, indexsect, index)
29
+ c = indexsect.add_child("<ul></ul>").first
30
+ index.keys.sort.each do |k|
31
+ words = index[k].keys.each_with_object({}) do |w, v|
32
+ v[sortable(w).downcase] = w
33
+ end
34
+ words.keys.localize(@lang.to_sym).sort.to_a.each do |w|
35
+ c.add_child index_entries(words, index[k], w)
36
+ end
37
+ end
38
+ index1_cleanup(docxml)
39
+ end
40
+
41
+ def index1_cleanup(docxml)
42
+ docxml.xpath(ns("//indexsect//xref")).each do |x|
43
+ x.children.remove
44
+ end
45
+ @xrefs.bookmark_anchor_names(docxml)
46
+ end
47
+
48
+ def sortable(str)
49
+ str or return " "
50
+ HTMLEntities.new.decode(Nokogiri::XML.fragment(str).text)
51
+ end
52
+
53
+ def index_entries_opt
54
+ { xref_lbl: ", ", see_lbl: ", #{see_lbl}", also_lbl: ", #{also_lbl}" }
55
+ end
56
+
57
+ def index_entries(words, index, primary)
58
+ ret = index_entries_head(words[primary],
59
+ index.dig(words[primary], nil, nil),
60
+ index_entries_opt)
61
+ words2 = index[words[primary]]&.keys&.compact
62
+ &.each_with_object({}) { |w, v| v[w.downcase] = w }
63
+ unless words2.empty?
64
+ ret += "<ul>"
65
+ words2.keys.localize(@lang.to_sym).sort.to_a.each do |w|
66
+ ret += index_entries2(words2, index[words[primary]], w)
67
+ end
68
+ ret += "</ul>"
69
+ end
70
+ "#{ret}</li>"
71
+ end
72
+
73
+ def index_entries2(words, index, secondary)
74
+ ret = index_entries_head(words[secondary],
75
+ index.dig(words[secondary], nil),
76
+ index_entries_opt)
77
+ words3 = index[words[secondary]]&.keys&.compact
78
+ &.each_with_object({}) { |w, v| v[w.downcase] = w }
79
+ unless words3.empty?
80
+ ret += "<ul>"
81
+ words3.keys.localize(@lang.to_sym).sort.to_a.each do |w|
82
+ ret += (index_entries_head(words3[w],
83
+ index[words[secondary]][words3[w]],
84
+ index_entries_opt) + "</li>")
85
+ end
86
+ ret += "</ul>"
87
+ end
88
+ "#{ret}</li>"
89
+ end
90
+
91
+ def index_entries_head(head, entries, opt)
92
+ ret = "<li>#{head}"
93
+ xref = entries&.dig(:xref)&.join(", ")
94
+ see = index_entries_see(entries, :see)
95
+ also = index_entries_see(entries, :also)
96
+ ret += "#{opt[:xref_lbl]} #{xref}" if xref
97
+ ret += "#{opt[:see_lbl]} #{see}" if see
98
+ ret += "#{opt[:also_lbl]} #{also}" if also
99
+ ret
100
+ end
101
+
102
+ def index_entries_see(entries, label)
103
+ see_sort = entries&.dig(label) or return nil
104
+ x = see_sort.each_with_object({}) do |w, v|
105
+ v[sortable(w).downcase] = w
106
+ end
107
+ x.keys.localize(@lang.to_sym).sort.to_a.map do |k|
108
+ # see_sort[k]
109
+ x[k]
110
+ end.join(", ")
111
+ end
112
+
113
+ def see_lbl
114
+ @lang == "en" ? @i18n.see : "<em>#{@i18n.see}</em>"
115
+ end
116
+
117
+ def also_lbl
118
+ @lang == "en" ? @i18n.see_also : "<em>#{@i18n.see_also}</em>"
119
+ end
120
+
121
+ def sort_indexterms(terms, see, also)
122
+ index = extract_indexterms(terms)
123
+ index = extract_indexsee(index, see, :see)
124
+ index = extract_indexsee(index, also, :also)
125
+ index.keys.sort.each_with_object({}) do |k, v|
126
+ v[sortable(k)[0].upcase.transliterate] ||= {}
127
+ v[sortable(k)[0].upcase.transliterate][k] = index[k]
128
+ end
129
+ end
130
+
131
+ def extract_indexsee(val, terms, label)
132
+ terms.each_with_object(val) do |t, v|
133
+ term, term2, term3 = extract_indexterms_init(t)
134
+ term_hash_init(v, term, term2, term3, label)
135
+ v[term][term2][term3][label] << to_xml(t.at(ns("./target"))&.children)
136
+ t.remove
137
+ end
138
+ end
139
+
140
+ def xml_encode_attr(str)
141
+ HTMLEntities.new.encode(str, :basic, :hexadecimal)
142
+ .gsub(/&#x([^;]+);/) do |_x|
143
+ "&#x#{$1.upcase};"
144
+ end
145
+ end
146
+
147
+ # attributes are decoded into UTF-8,
148
+ # elements in extract_indexsee are still in entities
149
+ def extract_indexterms(terms)
150
+ terms.each_with_object({}) do |t, v|
151
+ term, term2, term3 = extract_indexterms_init(t)
152
+ to = t["to"] ? "to='#{t['to']}' " : ""
153
+ index2bookmark(t)
154
+ term_hash_init(v, term, term2, term3, :xref)
155
+ v[term][term2][term3][:xref] << "<xref target='#{t['id']}' " \
156
+ "#{to}pagenumber='true'/>"
157
+ end
158
+ end
159
+
160
+ def extract_indexterms_init(term)
161
+ %w(primary secondary tertiary).each_with_object([]) do |x, m|
162
+ m << to_xml(term.at(ns("./#{x}"))&.children)
163
+ end
164
+ end
165
+
166
+ def term_hash_init(hash, term, term2, term3, label)
167
+ hash[term] ||= {}
168
+ hash[term][term2] ||= {}
169
+ hash[term][term2][term3] ||= {}
170
+ hash[term][term2][term3][label] ||= []
171
+ end
172
+
173
+ def index2bookmark(node)
174
+ node.name = "bookmark"
175
+ node.children.each(&:remove)
176
+ node["id"] = "_#{UUIDTools::UUID.random_create}"
177
+ node.delete("to")
178
+ end
179
+ end
180
+ end
@@ -100,24 +100,27 @@ module IsoDoc
100
100
  implicit_reference(bibitem) ||
101
101
  bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) ||
102
102
  bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
103
+ bibitem["suppress_identifier"] == "true" ||
103
104
  bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
104
105
  end
105
106
 
106
107
  def bibliography_bibitem_number(docxml)
107
108
  i = 0
108
- docxml.xpath(ns("//references[@normative = 'false']/bibitem")).each do |b|
109
- i = bibliography_bibitem_number1(b, i)
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
110
113
  end
111
114
  reference_names docxml
112
115
  bibliography_bibitem_tag(docxml)
113
116
  end
114
117
 
115
- def bibliography_bibitem_number1(bibitem, idx)
118
+ def bibliography_bibitem_number1(bibitem, idx, normative)
116
119
  ins = bibliography_bibitem_number_insert_pt(bibitem)
117
120
  mn = bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) and
118
- /^\[?\d+\]?$/.match?(mn.text) and
119
- mn.remove # ignore numbers already inserted
120
- unless bibliography_bibitem_number_skip(bibitem)
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
121
124
  idx += 1
122
125
  ins.next =
123
126
  "<docidentifier type='metanorma-ordinal'>[#{idx}]</docidentifier>"
@@ -126,10 +129,10 @@ module IsoDoc
126
129
  end
127
130
 
128
131
  def bibliography_bibitem_number_insert_pt(bibitem)
132
+ bibitem.children.empty? and bibitem.add_child(" ")
129
133
  unless d = bibitem.at(ns(".//docidentifier"))
130
134
  d = bibitem.children.first
131
- d.previous = " "
132
- return d.previous
135
+ d.previous = " " and return d.previous
133
136
  end
134
137
  unless ins = d.previous_element
135
138
  d.previous = " "
@@ -150,6 +153,7 @@ module IsoDoc
150
153
  def bibliography_bibitem_tag1(ref, idx, norm)
151
154
  ref.xpath(ns("./bibitem")).each do |b|
152
155
  implicit_reference(b) and next
156
+ b["suppress_identifier"] == "true" and next
153
157
  idx += 1 unless b["hidden"]
154
158
  insert_biblio_tag(b, idx, !norm, standard?(b))
155
159
  end
@@ -29,7 +29,7 @@ module IsoDoc
29
29
  def clause1(elem)
30
30
  level = @xrefs.anchor(elem["id"], :level, false) ||
31
31
  (elem.ancestors("clause, annex").size + 1)
32
- lbl = @xrefs.anchor(elem["id"], :label, elem.parent.name != "sections")
32
+ lbl = @xrefs.anchor(elem["id"], :label, !unnumbered_clause?(elem))
33
33
  if unnumbered_clause?(elem) || !lbl
34
34
  prefix_name(elem, {}, nil, "title")
35
35
  else
@@ -49,7 +49,7 @@ module IsoDoc
49
49
  end
50
50
 
51
51
  def annex1(elem)
52
- lbl = @xrefs.anchor(elem["id"], :label)
52
+ lbl = @xrefs.anchor(elem["id"], :label, false)
53
53
  # TODO: do not alter title, alter semx/@element = title
54
54
  t = elem.at(ns("./title")) and
55
55
  t.children = "<strong>#{to_xml(t.children)}</strong>"
@@ -81,10 +81,6 @@ module IsoDoc
81
81
  end
82
82
  end
83
83
 
84
- def index(docxml)
85
- docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove)
86
- end
87
-
88
84
  def skip_display_order?(node)
89
85
  node.name == "floating-title"
90
86
  end
@@ -21,7 +21,7 @@ module IsoDoc
21
21
  node["style"] == "id" and
22
22
  return anchor_id_postproc(node)
23
23
  node["citeas"].nil? && node["bibitemid"] and
24
- return @xrefs.anchor(node["bibitemid"], :xref) || "???"
24
+ return citeas_cleanup(@xrefs.anchor(node["bibitemid"], :xref)) || "???"
25
25
  node.at(ns("./location")) and
26
26
  return combine_xref_locations(node) || "???"
27
27
  node["target"] && node["droploc"] and
@@ -7,6 +7,7 @@ require_relative "presentation_function/erefs"
7
7
  require_relative "presentation_function/inline"
8
8
  require_relative "presentation_function/math"
9
9
  require_relative "presentation_function/section"
10
+ require_relative "presentation_function/index"
10
11
  require_relative "presentation_function/bibdata"
11
12
  require_relative "presentation_function/metadata"
12
13
 
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.12.6".freeze
2
+ VERSION = "2.12.7".freeze
3
3
  end
@@ -15,6 +15,9 @@ termsdefsymbols: المصطلحات والتعريفات والرموز
15
15
  termsdefabbrev: المصطلحات والتعريفات والاختصارات
16
16
  normref: المراجع المعيارية
17
17
  bibliography: بيبليوغرافيا
18
+ index: الفهرس
19
+ see: انظر
20
+ see_also: انظر أيضًا
18
21
  clause: فقرة
19
22
  annex: ملحق
20
23
  appendix: تذييل
@@ -15,6 +15,9 @@ termsdefsymbols: Begriffe, Definitionen und Symbole
15
15
  termsdefabbrev: Begriffe, Definitionen und abgekürzte Begriffe
16
16
  normref: Normative Verweise
17
17
  bibliography: Bibliographie
18
+ index: Index
19
+ see: schau
20
+ see_also: siehe auch
18
21
  clause: Klausel
19
22
  annex: Anhang
20
23
  appendix: Appendix
@@ -14,6 +14,9 @@ termsdefsymbols: Terms, definitions and symbols
14
14
  termsdefabbrev: Terms, definitions and abbreviated terms
15
15
  normref: Normative references
16
16
  bibliography: Bibliography
17
+ index: Index
18
+ see: see
19
+ see_also: see also
17
20
  preface: Preface
18
21
  section: Section
19
22
  clause: Clause
@@ -14,6 +14,9 @@ termsdefsymbols: Términos, definiciones y símbolos
14
14
  termsdefabbrev: Términos, definiciones y términos abreviados
15
15
  normref: Referencias normativas
16
16
  bibliography: Bibliografía
17
+ index: Índice
18
+ see: ver
19
+ see_also: ver también
17
20
  section: Sección
18
21
  clause: Cláusula
19
22
  annex: Anexo
@@ -14,6 +14,9 @@ termsdefsymbols: Termes, définitions et symboles
14
14
  termsdefabbrev: Termes, définitions et termes abrégés
15
15
  normref: Références normatives
16
16
  bibliography: Bibliographie
17
+ index: Index
18
+ see: voir
19
+ see_also: voir aussi
17
20
  preface: Préface
18
21
  section: Section
19
22
  clause: Article
@@ -14,6 +14,9 @@ termsdefsymbols: 用語及び定義並びに記号
14
14
  termsdefabbrev: 用語及び定義並びに略語
15
15
  normref: 引用規格
16
16
  bibliography: 参考文献
17
+ index: 索引
18
+ see: 参照
19
+ see_also: 追加参照
17
20
  preface: 序文
18
21
  section: セクション
19
22
  clause: 箇条
@@ -14,6 +14,9 @@ termsdefsymbols: Термины, определения и символы
14
14
  termsdefabbrev: Термины, определения и сокращенные термины
15
15
  normref: Нормативные ссылки
16
16
  bibliography: Библиография
17
+ index: Алфавитный указатель
18
+ see: см.
19
+ see_also: см. также
17
20
  section: Раздел
18
21
  clause: Пункт
19
22
  annex: Дополнение
@@ -14,6 +14,9 @@ termsdefsymbols: 术语、定义、符号和代号
14
14
  termsdefabbrev: 术语、定义、符号和缩略语
15
15
  normref: 规范性引用文件
16
16
  bibliography: 参考文献
17
+ index: 索引
18
+ see: 见
19
+ see_also: 另见
17
20
  preface: 序言
18
21
  section: 条
19
22
  clause: 条
@@ -1,4 +1,4 @@
1
1
  template:
2
2
  # skip authoritative identifier, it is inserted in front of formattedref within metanorma
3
- standard: "{% if creatornames %}{{ creatornames }} ({{ role}}){%else%}{{publisher}}{%endif%} . <em>{{ title }}</em> . {{ labels['in'] | capitalize }}:_{{ series_title }}. {{ medium | capitalize }}. {{ edition | capitalize_first }}. {{date}}. {{place}}: {%if creatornames %}{{publisher}}{% endif %} . {{size}}. {{ extent }}. {{ uri }}. {{ labels['at'] | capitalize}}:_{{ access_location }}. [{{ labels['viewed'] }}:_{{date_accessed}}]."
3
+ standard: "{% if creatornames %}{{ creatornames }} ({{ role}}){%else%}{{publisher}}{%endif%} . <em>{{ title }}</em> . {{ medium | capitalize }}. {{ edition | capitalize_first }}. {{date}}. {{place}}: {%if creatornames %}{{publisher}}{% endif %} . {{size}}. {{ extent }}. {{ uri }}. {{ labels['at'] | capitalize}}:_{{ access_location }}. [{{ labels['viewed'] }}:_{{date_accessed}}]."
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.6
4
+ version: 2.12.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-11 00:00:00.000000000 Z
11
+ date: 2024-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.8.0
89
+ version: 0.9.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.8.0
96
+ version: 0.9.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: roman-numerals
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -439,6 +439,7 @@ files:
439
439
  - lib/isodoc/presentation_function/docid.rb
440
440
  - lib/isodoc/presentation_function/erefs.rb
441
441
  - lib/isodoc/presentation_function/image.rb
442
+ - lib/isodoc/presentation_function/index.rb
442
443
  - lib/isodoc/presentation_function/inline.rb
443
444
  - lib/isodoc/presentation_function/math.rb
444
445
  - lib/isodoc/presentation_function/metadata.rb