isodoc 2.4.3 → 2.4.4

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: a0720c3026536785125b4c6c495e4f2573dfa7b2186094c0f36efa9c20a1fbd3
4
- data.tar.gz: 9ea3325d067e417956b865edd0baf70dff9a5cb80008e6dfe5fbfbdaaaf16ff4
3
+ metadata.gz: 9a2cc598b5e8c9690a42329b2af309d75d281db2767adc8fc00eb21a498f69cf
4
+ data.tar.gz: 1026ad146597f3e93b46f035506f648e7775bb0cf3e846d6f578d2af029dfb1a
5
5
  SHA512:
6
- metadata.gz: 2e97827c7adacaa26ef823222897672413056219fba5a3e0a6dee92079ac680cd50a9f1dde9cb7c40fddf23ef000fcb0478709a95916a4e6b222bf3d4e94ca54
7
- data.tar.gz: 888734821add95629f8709aac1e5ac8b95b372b6a33d43e366e78e0c4ec6a3957dc9264a86015501458ca2752b881f44053e1f7a3997c5d0fb1b43ec816abc74
6
+ metadata.gz: 5923a84bcb2fa4ba407eae39adf36202ebd07902ec425274641717d38b00daea3e035c9c8f12a936f1c6f4126e3d38db68a5184dfe63718adbe08b8c6ed4046d
7
+ data.tar.gz: 36a2d61a352858557db3c8f8f097b590842bf148b0ffaf48fcf3a5dd45f0781dcfe929000de3704427d9bde7c1a2c74458f931c0976356e4594bb510631c66c7
@@ -76,8 +76,11 @@ module IsoDoc
76
76
 
77
77
  # node is at the start of sentence in a Metanorma XML context
78
78
  def start_of_sentence(node)
79
- prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
80
- node.xpath("./preceding::text()")
79
+ prec = [] # all text nodes before node
80
+ nearest_block_parent(node).traverse do |x|
81
+ x == node and break
82
+ x.text? and prec << x
83
+ end
81
84
  prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map(&:text).join)
82
85
  end
83
86
  end
@@ -58,7 +58,7 @@ module IsoDoc
58
58
  num
59
59
  end
60
60
 
61
- TERM_CLAUSE = "//sections/terms | "\
61
+ TERM_CLAUSE = "//sections/terms | " \
62
62
  "//sections/clause[descendant::terms]".freeze
63
63
 
64
64
  def terms_defs(isoxml, out, num)
@@ -100,7 +100,7 @@ module IsoDoc
100
100
  def introduction(isoxml, out)
101
101
  f = isoxml.at(ns("//introduction")) || return
102
102
  page_break(out)
103
- out.div **{ class: "Section3", id: f["id"] } do |div|
103
+ out.div class: "Section3", id: f["id"] do |div|
104
104
  clause_name(nil, f.at(ns("./title")), div, { class: "IntroTitle" })
105
105
  f.elements.each do |e|
106
106
  parse(e, div) unless e.name == "title"
@@ -122,7 +122,7 @@ module IsoDoc
122
122
  f = isoxml.at(ns("//acknowledgements")) || return
123
123
  title_attr = { class: "IntroTitle" }
124
124
  page_break(out)
125
- out.div **{ class: "Section3", id: f["id"] } do |div|
125
+ out.div class: "Section3", id: f["id"] do |div|
126
126
  clause_name(nil, f&.at(ns("./title")), div, title_attr)
127
127
  f.elements.each do |e|
128
128
  parse(e, div) unless e.name == "title"
@@ -140,10 +140,10 @@ module IsoDoc
140
140
  end
141
141
 
142
142
  def preface(isoxml, out)
143
- isoxml.xpath(ns("//preface/clause | //preface/references | "\
143
+ isoxml.xpath(ns("//preface/clause | //preface/references | " \
144
144
  "//preface/definitions | //preface/terms")).each do |f|
145
145
  page_break(out)
146
- out.div **{ class: "Section3", id: f["id"] } do |div|
146
+ out.div class: "Section3", id: f["id"] do |div|
147
147
  clause_name(nil, f&.at(ns("./title")), div, { class: "IntroTitle" })
148
148
  f.elements.each do |e|
149
149
  parse(e, div) unless e.name == "title"
@@ -174,7 +174,7 @@ module IsoDoc
174
174
  def copyright_parse(node, out)
175
175
  return if @bare
176
176
 
177
- out.div **{ class: "boilerplate-copyright" } do |div|
177
+ out.div class: "boilerplate-copyright" do |div|
178
178
  node.children.each { |n| parse(n, div) }
179
179
  end
180
180
  end
@@ -182,7 +182,7 @@ module IsoDoc
182
182
  def license_parse(node, out)
183
183
  return if @bare
184
184
 
185
- out.div **{ class: "boilerplate-license" } do |div|
185
+ out.div class: "boilerplate-license" do |div|
186
186
  node.children.each { |n| parse(n, div) }
187
187
  end
188
188
  end
@@ -190,7 +190,7 @@ module IsoDoc
190
190
  def legal_parse(node, out)
191
191
  return if @bare
192
192
 
193
- out.div **{ class: "boilerplate-legal" } do |div|
193
+ out.div class: "boilerplate-legal" do |div|
194
194
  node.children.each { |n| parse(n, div) }
195
195
  end
196
196
  end
@@ -198,7 +198,7 @@ module IsoDoc
198
198
  def feedback_parse(node, out)
199
199
  return if @bare
200
200
 
201
- out.div **{ class: "boilerplate-feedback" } do |div|
201
+ out.div class: "boilerplate-feedback" do |div|
202
202
  node.children.each { |n| parse(n, div) }
203
203
  end
204
204
  end
@@ -15,8 +15,7 @@ module IsoDoc
15
15
  end
16
16
 
17
17
  def prefix_name(node, delim, number, elem)
18
- return if number.nil? || number.empty?
19
-
18
+ number.nil? || number.empty? and return
20
19
  unless name = node.at(ns("./#{elem}"))
21
20
  (node.children.empty? and node.add_child("<#{elem}></#{elem}>")) or
22
21
  node.children.first.previous = "<#{elem}></#{elem}>"
@@ -54,12 +53,12 @@ module IsoDoc
54
53
  end
55
54
 
56
55
  def note1(elem)
57
- elem.parent.name == "bibitem" || elem["notag"] == "true" and return
56
+ %w(bibdata bibitem).include?(elem.parent.name) ||
57
+ elem["notag"] == "true" and return
58
58
  n = @xrefs.get[elem["id"]]
59
- lbl = if n.nil? || n[:label].nil? || n[:label].empty?
60
- @i18n.note
61
- else l10n("#{@i18n.note} #{n[:label]}")
62
- end
59
+ lbl = @i18n.note
60
+ (n.nil? || n[:label].nil? || n[:label].empty?) or
61
+ lbl = l10n("#{lbl} #{n[:label]}")
63
62
  prefix_name(elem, "", lbl, "name")
64
63
  end
65
64
 
@@ -68,8 +67,18 @@ module IsoDoc
68
67
  end
69
68
 
70
69
  def admonition1(elem)
71
- elem.at(ns("./name")) || elem["notag"] == "true" and return
72
- prefix_name(elem, "", @i18n.admonition[elem["type"]]&.upcase, "name")
70
+ if elem["type"] == "box"
71
+ admonition_numbered1(elem)
72
+ else
73
+ elem["notag"] == "true" || elem.at(ns("./name")) and return
74
+ prefix_name(elem, "", @i18n.admonition[elem["type"]]&.upcase, "name")
75
+ end
76
+ end
77
+
78
+ def admonition_numbered1(elem)
79
+ elem["unnumbered"] && !elem.at(ns("./name")) and return
80
+ n = @xrefs.anchor(elem["id"], :label, false)
81
+ prefix_name(elem, block_delim, l10n("#{@i18n.box} #{n}"), "name")
73
82
  end
74
83
 
75
84
  def recommendation(docxml)
@@ -106,7 +106,7 @@ module IsoDoc
106
106
  def mathml_style_inherit(node)
107
107
  node.at("./ancestor::xmlns:strong") or return
108
108
  node.children =
109
- "<mstyle fontweight='bold'>#{node.children.to_xml}</mstyle>"
109
+ "<mstyle mathvariant='bold'>#{node.children.to_xml}</mstyle>"
110
110
  end
111
111
 
112
112
  def mathml_number_to_number(node)
@@ -1,5 +1,3 @@
1
- require_relative "../../relaton/render/general"
2
-
3
1
  module IsoDoc
4
2
  class PresentationXMLConvert < ::IsoDoc::Convert
5
3
  def references(docxml)
@@ -17,7 +17,7 @@ module IsoDoc
17
17
  level = @xrefs.anchor(elem["id"], :level, false) ||
18
18
  (elem.ancestors("clause, annex").size + 1)
19
19
  t = elem.at(ns("./title")) and t["depth"] = level
20
- return if !elem.ancestors("boilerplate").empty? ||
20
+ return if !elem.ancestors("boilerplate, metanorma-extension").empty? ||
21
21
  @suppressheadingnumbers || elem["unnumbered"]
22
22
 
23
23
  lbl = @xrefs.anchor(elem["id"], :label,
@@ -1,16 +1,23 @@
1
1
  module IsoDoc
2
2
  class PresentationXMLConvert < ::IsoDoc::Convert
3
3
  def sourcehighlighter_css(docxml)
4
- @sourcehighlighter or return
4
+ ret = custom_css(docxml)
5
+ ret.empty? and return
5
6
  ins = docxml.at(ns("//metanorma-extension")) ||
6
7
  docxml.at(ns("//bibdata")).after("<metanorma-extension/>").next_element
7
- ins << "<source-highlighter-css>#{sourcehighlighter_css_file}" \
8
+ ins << "<source-highlighter-css>#{ret}" \
8
9
  "</source-highlighter-css>"
9
10
  end
10
11
 
11
- def sourcehighlighter_css_file
12
- File.read(File.join(File.dirname(__FILE__), "..", "base_style",
13
- "rouge.css"))
12
+ def custom_css(docxml)
13
+ ret = ""
14
+ @sourcehighlighter and
15
+ ret += File.read(File.join(File.dirname(__FILE__), "..", "base_style",
16
+ "rouge.css"))
17
+ a = docxml.at(ns("//metanorma-extension/" \
18
+ "clause[title = 'user-css']/sourcecode")) and
19
+ ret += "\n#{to_xml(a.children)}"
20
+ ret
14
21
  end
15
22
 
16
23
  def sourcehighlighter
@@ -109,6 +116,7 @@ module IsoDoc
109
116
  Rouge::Lexer.find("plaintext"))
110
117
  l = Rouge::Lexers::Escape.new(start: "{^^{", end: "}^^}", lang: lexer)
111
118
  source = to_xml(elem.children).gsub(/</, "{^^{<").gsub(/>/, ">}^^}")
119
+ l.lang.reset!
112
120
  l.lex(@c.decode(source))
113
121
  end
114
122
 
@@ -56,23 +56,22 @@ module IsoDoc
56
56
  def concept1_ref(_node, ref, opts)
57
57
  ref.nil? and return
58
58
  opts[:ref] == "false" and return ref.remove
59
- r = concept1_ref_content(ref)
60
- ref = r.at("./descendant-or-self::xmlns:xref | " \
61
- "./descendant-or-self::xmlns:eref | " \
62
- "./descendant-or-self::xmlns:termref")
63
- %w(xref eref).include? ref&.name and get_linkend(ref)
64
- opts[:linkref] == "false" && %w(xref eref).include?(ref&.name) and
59
+ concept1_ref_content(ref)
60
+ %w(xref eref).include? ref.name and get_linkend(ref)
61
+ opts[:linkref] == "false" && %w(xref eref).include?(ref.name) and
65
62
  ref.replace(ref.children)
66
63
  end
67
64
 
68
65
  def concept1_ref_content(ref)
66
+ prev = "["
67
+ foll = "]"
69
68
  if non_locality_elems(ref).select do |c|
70
69
  !c.text? || /\S/.match(c)
71
70
  end.empty?
72
- ref.replace(@i18n.term_defined_in.sub(/%/,
73
- to_xml(ref)))
74
- else ref.replace("[#{to_xml(ref)}]")
71
+ prev, foll = @i18n.term_defined_in.split("%")
75
72
  end
73
+ ref.previous = prev
74
+ ref.next = foll
76
75
  end
77
76
 
78
77
  def related(docxml)
@@ -87,10 +87,11 @@ module IsoDoc
87
87
 
88
88
  def semantic_xml_insert(xml)
89
89
  @semantic_xml_insert or return
90
- embed = to_xml(embedable_semantic_xml(xml))
90
+ embed = embedable_semantic_xml(xml)
91
91
  ins = metanorma_extension_insert_pt(xml)
92
92
  ins = ins.at(ns("./metanorma")) || ins.add_child("<metanorma/>").first
93
- ins << "<source>#{embed}</source>"
93
+ ins = ins.add_child("<source/>").first
94
+ ins << embed
94
95
  end
95
96
 
96
97
  def metanorma_extension_insert_pt(xml)
@@ -107,14 +108,15 @@ module IsoDoc
107
108
  end
108
109
 
109
110
  def embedable_semantic_xml_tags(xml)
110
- Nokogiri::XML(to_xml(xml).gsub(%r{(</?)([[:alpha:]])},
111
- "\\1semantic__\\2")).root
111
+ Nokogiri::XML(to_xml(xml)
112
+ .sub(/ xmlns=['"][^"']+['"]/, "")
113
+ .gsub(%r{(</?)([[:alpha:]])}, "\\1semantic__\\2")).root
112
114
  end
113
115
 
114
116
  def embedable_semantic_xml_attributes(xml)
115
117
  Metanorma::Utils::anchor_attributes.each do |(tag_name, attr_name)|
116
118
  tag_name == "*" or tag_name = "semantic__#{tag_name}"
117
- xml.xpath(ns("//#{tag_name}[@#{attr_name}]")).each do |elem|
119
+ xml.xpath("//#{tag_name}[@#{attr_name}]").each do |elem|
118
120
  elem.attributes[attr_name].value =
119
121
  "semantic__#{elem.attributes[attr_name].value}"
120
122
  end
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.4.3".freeze
2
+ VERSION = "2.4.4".freeze
3
3
  end
@@ -4,10 +4,12 @@ module IsoDoc
4
4
  module XrefGen
5
5
  module Anchor
6
6
  class SeenAnchor
7
- include Singleton
8
-
9
- def initialize
7
+ def initialize(xmldoc)
10
8
  @seen = {}
9
+ # ignore all metanorma-extension ids
10
+ xmldoc.xpath("//xmlns:metanorma-extension//*[@id]").each do |x|
11
+ add(x["id"])
12
+ end
11
13
  end
12
14
 
13
15
  def seen(elem)
@@ -92,14 +92,15 @@ module IsoDoc
92
92
  SECTIONS_XPATH
93
93
  end
94
94
 
95
- CHILD_NOTES_XPATH =
95
+ def child_asset_path(asset)
96
96
  "./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and " \
97
- "not(self::xmlns:terms) and not(self::xmlns:definitions)]//xmlns:note | " \
98
- "./xmlns:note".freeze
97
+ "not(self::xmlns:terms) and not(self::xmlns:definitions)]//xmlns:X | " \
98
+ "./xmlns:X".gsub("X", asset)
99
+ end
99
100
 
100
101
  def note_anchor_names(sections)
101
102
  sections.each do |s|
102
- notes = s.xpath(CHILD_NOTES_XPATH) -
103
+ notes = s.xpath(child_asset_path("note")) -
103
104
  s.xpath(ns(".//figure//note | .//table//note"))
104
105
  note_anchor_names1(notes, Counter.new)
105
106
  note_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
@@ -116,17 +117,28 @@ module IsoDoc
116
117
  end
117
118
  end
118
119
 
119
- CHILD_EXAMPLES_XPATH =
120
- "./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and " \
121
- "not(self::xmlns:terms) and not(self::xmlns:definitions)]//" \
122
- "xmlns:example | ./xmlns:example".freeze
123
-
124
120
  CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | " \
125
121
  "./references".freeze
126
122
 
123
+ def admonition_anchor_names(sections)
124
+ sections.each do |s|
125
+ notes = s.xpath(child_asset_path("admonition[@type = 'box']"))
126
+ admonition_anchor_names1(notes, Counter.new)
127
+ admonition_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
128
+ end
129
+ end
130
+
131
+ def admonition_anchor_names1(notes, counter)
132
+ notes.noblank.each do |n|
133
+ @anchors[n["id"]] ||=
134
+ anchor_struct(increment_label(notes, n, counter), n,
135
+ @labels["box"], "admonition", n["unnumbered"])
136
+ end
137
+ end
138
+
127
139
  def example_anchor_names(sections)
128
140
  sections.each do |s|
129
- notes = s.xpath(CHILD_EXAMPLES_XPATH)
141
+ notes = s.xpath(child_asset_path("example"))
130
142
  example_anchor_names1(notes, Counter.new)
131
143
  example_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
132
144
  end
@@ -154,7 +166,8 @@ module IsoDoc
154
166
  end
155
167
  end
156
168
 
157
- def list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list)
169
+ def list_item_anchor_names(list, list_anchor, depth, prev_label,
170
+ refer_list)
158
171
  c = Counter.new(list["start"] ? list["start"].to_i - 1 : 0)
159
172
  list.xpath(ns("./li")).each do |li|
160
173
  label = c.increment(li).listlabel(list, depth)
@@ -45,6 +45,7 @@ module IsoDoc
45
45
  termexample_anchor_names(doc)
46
46
  note_anchor_names(doc.xpath(ns("//table | //figure")))
47
47
  note_anchor_names(doc.xpath(ns(sections_xpath)))
48
+ admonition_anchor_names(doc.xpath(ns(sections_xpath)))
48
49
  example_anchor_names(doc.xpath(ns(sections_xpath)))
49
50
  list_anchor_names(doc.xpath(ns(sections_xpath)))
50
51
  deflist_anchor_names(doc.xpath(ns(sections_xpath)))
data/lib/isodoc/xref.rb CHANGED
@@ -49,7 +49,6 @@ module IsoDoc
49
49
  return nil if ident.nil? || ident.empty?
50
50
 
51
51
  if warning && !@anchors[ident]
52
- @seen ||= SeenAnchor.instance
53
52
  @seen.seen(ident) or warn "No label has been processed for ID #{ident}"
54
53
  @seen.add(ident)
55
54
  return "[#{ident}]"
@@ -59,6 +58,7 @@ module IsoDoc
59
58
 
60
59
  # extract names for all anchors, xref and label
61
60
  def parse(docxml)
61
+ @seen = SeenAnchor.new(docxml)
62
62
  amend_preprocess(docxml) if @parse_settings.empty?
63
63
  initial_anchor_names(docxml)
64
64
  back_anchor_names(docxml)
@@ -55,6 +55,7 @@ table: جدول
55
55
  requirement: مطلب
56
56
  recommendation: توصية
57
57
  permission: إذن
58
+ box: الإطار
58
59
  key: مفتاح
59
60
  example: مثال
60
61
  example_xref: مثال
@@ -61,6 +61,7 @@ table: Tabelle
61
61
  requirement: Anforderung
62
62
  recommendation: Empfehlung
63
63
  permission: Erlaubnis
64
+ box: Kasten
64
65
  key: Taste
65
66
  example: BEISPIEL
66
67
  example_xref: Beispiel
@@ -61,6 +61,7 @@ table: Table
61
61
  requirement: Requirement
62
62
  recommendation: Recommendation
63
63
  permission: Permission
64
+ box: Box
64
65
  # Modspec
65
66
  recommendationtest: Recommendation test
66
67
  requirementtest: Requirement test
@@ -61,6 +61,7 @@ table: Tabla
61
61
  requirement: Requerimiento
62
62
  recommendation: Recomendación
63
63
  permission: Permiso
64
+ box: Recuadro
64
65
  key: Clave
65
66
  example: EJEMPLO
66
67
  example_xref: Ejemplo
@@ -58,6 +58,7 @@ table: Tableau
58
58
  requirement: Exigence
59
59
  recommendation: Recommandation
60
60
  permission: Autorisation
61
+ box: Encadré
61
62
  key: Légende
62
63
  example: EXEMPLE
63
64
  example_xref: Exemple
@@ -66,6 +66,7 @@ table: Таблица
66
66
  requirement: Требование
67
67
  recommendation: Рекомендация
68
68
  permission: Разрешение
69
+ box: Вставка
69
70
  key: Условные обозначения
70
71
  example: ПРИМЕР
71
72
  example_xref: Пример
@@ -56,6 +56,7 @@ table: 表
56
56
  requirement: 要求
57
57
  recommendation: 建议
58
58
  permission: 容許
59
+ box: 专栏
59
60
  key: 说明
60
61
  example: 示例
61
62
  example_xref: 示例
data/lib/isodoc.rb CHANGED
@@ -7,10 +7,10 @@ require "base64"
7
7
  require "mime/types"
8
8
  require "image_size"
9
9
  require "set"
10
- require "pp"
11
10
  require "html2doc"
12
11
  require "liquid"
13
12
  require "htmlentities"
13
+ require "relaton-render"
14
14
 
15
15
  require "isodoc/common"
16
16
  require "isodoc/convert"
@@ -24,6 +24,7 @@ require "isodoc/presentation_xml_convert"
24
24
  require "isodoc/xref"
25
25
  require "isodoc/i18n"
26
26
  require "metanorma/output"
27
+ require "relaton/render-isodoc/general"
27
28
 
28
29
  module IsoDoc
29
30
  end
File without changes
File without changes
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.4.3
4
+ version: 2.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-23 00:00:00.000000000 Z
11
+ date: 2023-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath
@@ -494,8 +494,8 @@ files:
494
494
  - lib/metanorma/output/base.rb
495
495
  - lib/metanorma/output/utils.rb
496
496
  - lib/metanorma/output/xslfo.rb
497
- - lib/relaton/render/config.yml
498
- - lib/relaton/render/general.rb
497
+ - lib/relaton/render-isodoc/config.yml
498
+ - lib/relaton/render-isodoc/general.rb
499
499
  homepage: https://github.com/metanorma/isodoc
500
500
  licenses:
501
501
  - BSD-2-Clause