isodoc 1.0.27 → 1.0.28

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: 68d6f17f0d5291c6c067bfc6a3a476885b80f128bdc9c4e3e3d8356c6af30482
4
- data.tar.gz: 2710c48aa2fb9eeee44b586107b07884d52802a53fec81d69c0f3fb68fa988ed
3
+ metadata.gz: 6d2aca20ce5f2e96df3da6fbb1a8e675e3b2393f51720bac2bdc760e6e9c09a5
4
+ data.tar.gz: 6f83efeb115dbbb30f928d99e8f8c6da4172fc2a17d1792607d2cd38d6b5833c
5
5
  SHA512:
6
- metadata.gz: 1c38cb43027aa1a056d465660449a4a58e1a5b78474a5f0184fca4164f2af2480720329e5a7181fcc1731151ef15db71019aa9fc34175b779de517006bf85fa6
7
- data.tar.gz: '09503b88edfb1db0b3def003bca81c356b40790014953a9bc08de680af8db75222ded714f43a1f6820ec30dbaa2e3f83ac2a5e386f3c757f0d639f086e0b4b2c'
6
+ metadata.gz: f3e63f2f2f04dea86c5b716be19385eec4273bdd57870ee1215f441e2b6494ea25c8c52c3edf40b8b657ed8d081667356b003e68ded049605f2985450e903649
7
+ data.tar.gz: a1f408ba884174786963f38a5912ec128a94223b5f9f66fb28662398a6785bb2b54a42554fc3c2bb004230d443a6a38b8d771a1cdf64ec12447ea4e132b46a2c
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "html2doc", "~> 1.0.0"
37
37
  spec.add_dependency "liquid"
38
38
  spec.add_dependency "roman-numerals"
39
- spec.add_dependency "sassc", "~> 2.2.1"
39
+ spec.add_dependency "sassc", "~> 2.4.0"
40
40
  spec.add_dependency "metanorma", "~> 1.0.0"
41
41
  spec.add_dependency "rake", "~> 12.0"
42
42
 
@@ -141,7 +141,7 @@ module IsoDoc::Function
141
141
  def admonition_parse(node, out)
142
142
  type = node["type"]
143
143
  name = admonition_name(node, type)
144
- out.div **{ class: admonition_class(node) } do |t|
144
+ out.div **{ id: node["id"], class: admonition_class(node) } do |t|
145
145
  admonition_name_parse(node, t, name) if name
146
146
  node.children.each { |n| parse(n, t) unless n.name == "name" }
147
147
  end
@@ -1,16 +1,20 @@
1
1
  module IsoDoc::Function
2
2
  module Cleanup
3
3
  def textcleanup(docxml)
4
- docxml = passthrough_cleanup(docxml)
4
+ docxml = termref_cleanup(passthrough_cleanup(docxml))
5
+ end
6
+
7
+ def termref_cleanup(docxml)
5
8
  docxml.
9
+ gsub(%r{\s*\[/TERMREF\]\s*</p>\s*<p>\s*\[TERMREF\]}, "; ").
6
10
  gsub(/\[TERMREF\]\s*/, l10n("[#{@source_lbl}: ")).
7
11
  gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/, l10n(", #{@modified_lbl} [/TERMREF]")).
8
- gsub(/\s*\[\/TERMREF\]\s*/, l10n("]")).
12
+ gsub(%r{\s*\[\/TERMREF\]\s*}, l10n("]")).
9
13
  gsub(/\s*\[MODIFICATION\]/, l10n(", #{@modified_lbl} &mdash; "))
10
14
  end
11
15
 
12
16
  def passthrough_cleanup(docxml)
13
- docxml = docxml.split(%r{(<passthrough>|</passthrough>)}).each_slice(4).map do |a|
17
+ docxml.split(%r{(<passthrough>|</passthrough>)}).each_slice(4).map do |a|
14
18
  a.size > 2 and a[2] = HTMLEntities.new.decode(a[2])
15
19
  [a[0], a[2]]
16
20
  end.join
@@ -126,7 +130,7 @@ module IsoDoc::Function
126
130
  end
127
131
 
128
132
  def footnote_cleanup(docxml)
129
- docxml.xpath('//a[@epub:type = "footnote"]/sup').each_with_index do |x, i|
133
+ docxml.xpath('//a[@class = "FootnoteRef"]/sup').each_with_index do |x, i|
130
134
  x.content = (i + 1).to_s
131
135
  end
132
136
  docxml
@@ -1,28 +1,7 @@
1
+ require_relative "inline_simple"
2
+
1
3
  module IsoDoc::Function
2
4
  module Inline
3
- def section_break(body)
4
- body.br
5
- end
6
-
7
- def page_break(out)
8
- out.br
9
- end
10
-
11
- def pagebreak_parse(_node, out)
12
- out.br
13
- end
14
-
15
- def hr_parse(node, out)
16
- out.hr
17
- end
18
-
19
- def br_parse(node, out)
20
- out.br
21
- end
22
-
23
- def index_parse(node, out)
24
- end
25
-
26
5
  def link_parse(node, out)
27
6
  out.a **attr_code(href: node["target"], title: node["alt"]) do |l|
28
7
  if node.text.empty?
@@ -50,17 +29,39 @@ module IsoDoc::Function
50
29
  (container && get_note_container_id(node) != container &&
51
30
  @anchors[node["target"]]) &&
52
31
  linkend = prefix_container(container, linkend, node["target"])
32
+ linkend = capitalise_xref(node, linkend)
53
33
  end
54
34
  linkend || "???"
55
35
  end
56
36
 
37
+ def capitalise_xref(node, linkend)
38
+ return linkend unless %w(Latn Cyrl Grek).include? @script
39
+ return linkend&.capitalize if node["case"] == "capital"
40
+ return linkend&.downcase if node["case"] == "lowercase"
41
+ return linkend if linkend[0,1].match(/\p{Upper}/)
42
+ prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
43
+ node.xpath("./preceding::text()")
44
+ (prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map { |p| p.text }.join)) ?
45
+ linkend&.capitalize : linkend
46
+ end
47
+
48
+ def nearest_block_parent(node)
49
+ until %w(p title td th name formula
50
+ li dt dd sourcecode pre).include?(node.name)
51
+ node = node.parent
52
+ end
53
+ node
54
+ end
55
+
57
56
  def get_linkend(node)
58
- contents = node.children.select { |c| !%w{locality localityStack}.include? c.name }.
59
- select { |c| !c.text? || /\S/.match(c) }
57
+ contents = node.children.select do |c|
58
+ !%w{locality localityStack}.include? c.name
59
+ end.select { |c| !c.text? || /\S/.match(c) }
60
60
  !contents.empty? and
61
61
  return Nokogiri::XML::NodeSet.new(node.document, contents).to_xml
62
62
  link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))
63
- link + eref_localities(node.xpath(ns("./locality | ./localityStack")), link)
63
+ link + eref_localities(node.xpath(ns("./locality | ./localityStack")),
64
+ link)
64
65
  # so not <origin bibitemid="ISO7301" citeas="ISO 7301">
65
66
  # <locality type="section"><reference>3.1</reference></locality></origin>
66
67
  end
@@ -83,7 +84,7 @@ module IsoDoc::Function
83
84
  end
84
85
  else
85
86
  ret += eref_localities0(r, i, target, delim)
86
- end
87
+ end
87
88
  end
88
89
  ret
89
90
  end
@@ -120,8 +121,9 @@ module IsoDoc::Function
120
121
  end
121
122
 
122
123
  def concept_parse(node, out)
123
- content = node.first_element_child.children.select { |c| !%w{locality localityStack}.include? c.name }.
124
- select { |c| !c.text? || /\S/.match(c) }
124
+ content = node.first_element_child.children.select do |c|
125
+ !%w{locality localityStack}.include? c.name
126
+ end.select { |c| !c.text? || /\S/.match(c) }
125
127
  if content.empty?
126
128
  out << "[Term defined in "
127
129
  parse(node.first_element_child, out)
@@ -133,7 +135,8 @@ module IsoDoc::Function
133
135
 
134
136
  def stem_parse(node, out)
135
137
  ooml = if node["type"] == "AsciiMath"
136
- "#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}#{@closemathdelim}"
138
+ "#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}"\
139
+ "#{@closemathdelim}"
137
140
  elsif node["type"] == "MathML" then node.first_element_child.to_s
138
141
  else
139
142
  HTMLEntities.new.encode(node.text)
@@ -175,52 +178,6 @@ module IsoDoc::Function
175
178
  out << text
176
179
  end
177
180
 
178
- def bookmark_parse(node, out)
179
- out.a **attr_code(id: node["id"])
180
- end
181
-
182
- def keyword_parse(node, out)
183
- out.span **{ class: "keyword" } do |s|
184
- node.children.each { |n| parse(n, s) }
185
- end
186
- end
187
-
188
- def em_parse(node, out)
189
- out.i do |e|
190
- node.children.each { |n| parse(n, e) }
191
- end
192
- end
193
-
194
- def strong_parse(node, out)
195
- out.b do |e|
196
- node.children.each { |n| parse(n, e) }
197
- end
198
- end
199
-
200
- def sup_parse(node, out)
201
- out.sup do |e|
202
- node.children.each { |n| parse(n, e) }
203
- end
204
- end
205
-
206
- def sub_parse(node, out)
207
- out.sub do |e|
208
- node.children.each { |n| parse(n, e) }
209
- end
210
- end
211
-
212
- def tt_parse(node, out)
213
- out.tt do |e|
214
- node.children.each { |n| parse(n, e) }
215
- end
216
- end
217
-
218
- def strike_parse(node, out)
219
- out.s do |e|
220
- node.children.each { |n| parse(n, e) }
221
- end
222
- end
223
-
224
181
  def error_parse(node, out)
225
182
  text = node.to_xml.gsub(/</, "&lt;").gsub(/>/, "&gt;")
226
183
  out.para do |p|
@@ -232,14 +189,20 @@ module IsoDoc::Function
232
189
  if node["lang"] == @lang && node["script"] == @script
233
190
  node.children.each { |n| parse(n, out) }
234
191
  else
235
- prev = node.xpath("./preceding-sibling::xmlns:variant")
236
- foll = node.xpath("./following-sibling::xmlns:variant")
237
- found = false
238
- (prev + foll).each { |n| found = true if n["lang"] == @lang && n["script"] == @script }
239
- return if found
240
- return unless prev.empty?
192
+ return if found_matching_variant_sibling(node)
193
+ return unless !node.at("./preceding-sibling::xmlns:variant")
241
194
  node.children.each { |n| parse(n, out) }
242
195
  end
243
196
  end
197
+
198
+ def found_matching_variant_sibling(node)
199
+ prev = node.xpath("./preceding-sibling::xmlns:variant")
200
+ foll = node.xpath("./following-sibling::xmlns:variant")
201
+ found = false
202
+ (prev + foll).each do |n|
203
+ found = true if n["lang"] == @lang && n["script"] == @script
204
+ end
205
+ found
206
+ end
244
207
  end
245
208
  end
@@ -0,0 +1,72 @@
1
+ module IsoDoc::Function
2
+ module Inline
3
+ def section_break(body)
4
+ body.br
5
+ end
6
+
7
+ def page_break(out)
8
+ out.br
9
+ end
10
+
11
+ def pagebreak_parse(_node, out)
12
+ out.br
13
+ end
14
+
15
+ def hr_parse(node, out)
16
+ out.hr
17
+ end
18
+
19
+ def br_parse(node, out)
20
+ out.br
21
+ end
22
+
23
+ def index_parse(node, out)
24
+ end
25
+
26
+ def bookmark_parse(node, out)
27
+ out.a **attr_code(id: node["id"])
28
+ end
29
+
30
+ def keyword_parse(node, out)
31
+ out.span **{ class: "keyword" } do |s|
32
+ node.children.each { |n| parse(n, s) }
33
+ end
34
+ end
35
+
36
+ def em_parse(node, out)
37
+ out.i do |e|
38
+ node.children.each { |n| parse(n, e) }
39
+ end
40
+ end
41
+
42
+ def strong_parse(node, out)
43
+ out.b do |e|
44
+ node.children.each { |n| parse(n, e) }
45
+ end
46
+ end
47
+
48
+ def sup_parse(node, out)
49
+ out.sup do |e|
50
+ node.children.each { |n| parse(n, e) }
51
+ end
52
+ end
53
+
54
+ def sub_parse(node, out)
55
+ out.sub do |e|
56
+ node.children.each { |n| parse(n, e) }
57
+ end
58
+ end
59
+
60
+ def tt_parse(node, out)
61
+ out.tt do |e|
62
+ node.children.each { |n| parse(n, e) }
63
+ end
64
+ end
65
+
66
+ def strike_parse(node, out)
67
+ out.s do |e|
68
+ node.children.each { |n| parse(n, e) }
69
+ end
70
+ end
71
+ end
72
+ end
@@ -5,7 +5,7 @@ module IsoDoc::Function
5
5
  # references anyway; keeping here instead of in IsoDoc::Iso for now
6
6
  def docid_l10n(x)
7
7
  return x if x.nil?
8
- x.gsub(/All Parts/i, @all_parts_lbl.downcase)
8
+ x.gsub(/All Parts/i, @all_parts_lbl.downcase) if @all_parts_lbl
9
9
  end
10
10
 
11
11
  # TODO generate formatted ref if not present
@@ -84,7 +84,7 @@ module IsoDoc::Function
84
84
 
85
85
  def omit_docid_prefix(prefix)
86
86
  return true if prefix.nil? || prefix.empty?
87
- return %w(ISO IEC ITU metanorma).include? prefix
87
+ return %w(ISO IEC ITU W3C metanorma).include? prefix
88
88
  end
89
89
 
90
90
  def date_note_process(b, ref)
@@ -16,6 +16,7 @@ module IsoDoc::Function
16
16
  clausedelimspace(out)
17
17
  end
18
18
  c1&.children&.each { |c2| parse(c2, b) }
19
+ clausedelimspace(out) if /\S/.match(c1&.text)
19
20
  end
20
21
  end
21
22
  end
@@ -79,7 +79,7 @@ module IsoDoc::Function
79
79
 
80
80
  def make_body3(body, docxml)
81
81
  body.div **{ class: "main-section" } do |div3|
82
- boilerplate docxml, div3
82
+ boilerplate docxml, div3
83
83
  abstract docxml, div3
84
84
  foreword docxml, div3
85
85
  introduction docxml, div3
@@ -102,6 +102,7 @@ module IsoDoc::Function
102
102
  @meta.relations isoxml, out
103
103
  @meta.version isoxml, out
104
104
  @meta.url isoxml, out
105
+ @meta.keywords isoxml, out
105
106
  @meta.get
106
107
  end
107
108
 
@@ -109,8 +110,15 @@ module IsoDoc::Function
109
110
  out.p(**{ class: "zzSTDTitle1" }) { |p| p << @meta.get[:doctitle] }
110
111
  end
111
112
 
113
+ def middle_admonitions(isoxml, out)
114
+ isoxml.xpath(ns("//sections/note | //sections/admonition")).each do |x|
115
+ parse(x, out)
116
+ end
117
+ end
118
+
112
119
  def middle(isoxml, out)
113
120
  middle_title(out)
121
+ middle_admonitions(isoxml, out)
114
122
  i = scope isoxml, out, 0
115
123
  i = norm_ref isoxml, out, i
116
124
  i = terms_defs isoxml, out, i
@@ -120,20 +128,20 @@ module IsoDoc::Function
120
128
  bibliography isoxml, out
121
129
  end
122
130
 
123
- def boilerplate(node, out)
124
- boilerplate = node.at(ns("//boilerplate")) or return
125
- out.div **{class: "authority"} do |s|
126
- boilerplate.children.each do |n|
127
- if n.name == "title"
128
- s.h1 do |h|
129
- n.children.each { |nn| parse(nn, h) }
130
- end
131
- else
132
- parse(n, s)
131
+ def boilerplate(node, out)
132
+ boilerplate = node.at(ns("//boilerplate")) or return
133
+ out.div **{class: "authority"} do |s|
134
+ boilerplate.children.each do |n|
135
+ if n.name == "title"
136
+ s.h1 do |h|
137
+ n.children.each { |nn| parse(nn, h) }
133
138
  end
139
+ else
140
+ parse(n, s)
134
141
  end
135
142
  end
136
143
  end
144
+ end
137
145
 
138
146
  def parse(node, out)
139
147
  if node.text?
@@ -121,7 +121,7 @@ module IsoDoc::Function
121
121
  h1.traverse do |x|
122
122
  x.replace(" ") if x.name == "span" && /mso-tab-count/.match(x["style"])
123
123
  x.remove if x.name == "span" && x["class"] == "MsoCommentReference"
124
- x.remove if x.name == "a" && x["epub:type"] == "footnote"
124
+ x.remove if x.name == "a" && x["class"] == "FootnoteRef"
125
125
  x.remove if x.name == "span" && /mso-bookmark/.match(x["style"])
126
126
  x.replace(x.children) if x.name == "a"
127
127
  end
@@ -65,7 +65,7 @@ module IsoDoc::HtmlFunction
65
65
  return table_footnote_parse(node, out) if (@in_table || @in_figure) &&
66
66
  !node.ancestors.map {|m| m.name }.include?("name")
67
67
  fn = node["reference"] || UUIDTools::UUID.random_create.to_s
68
- attrs = { "epub:type": "footnote", rel: "footnote", href: "#fn:#{fn}" }
68
+ attrs = { class: "FootnoteRef", href: "#fn:#{fn}" }
69
69
  out.a **attrs do |a|
70
70
  a.sup { |sup| sup << fn }
71
71
  end
@@ -3,6 +3,18 @@ require "base64"
3
3
 
4
4
  module IsoDoc::HtmlFunction
5
5
  module Html
6
+ def convert1(docxml, filename, dir)
7
+ anchor_names docxml
8
+ noko do |xml|
9
+ xml.html **{ lang: "#{@lang}" } do |html|
10
+ info docxml, nil
11
+ populate_css()
12
+ html.head { |head| define_head head, filename, dir }
13
+ make_body(html, docxml)
14
+ end
15
+ end.join("\n")
16
+ end
17
+
6
18
  def make_body1(body, _docxml)
7
19
  body.div **{ class: "title-section" } do |div1|
8
20
  div1.p { |p| p << "&nbsp;" } # placeholder