isodoc 2.9.4 → 2.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa1b06e38f973ba312a0f2d90d306c7ffb34e377f2fcc4a59c42775ba9f2a927
4
- data.tar.gz: b74dcbe6b71b90da2ec4f205754bb08028d5bd1d45f085f7e35d6c3c47dc55cc
3
+ metadata.gz: 9d98a917ee770ef1034262fa29628010e3254f3ddb5d8dfe63be54c57c3d58c0
4
+ data.tar.gz: 64b2107fddc44c0096653fc0319c7b0df81285327ab83600471b1b99971f3dbd
5
5
  SHA512:
6
- metadata.gz: 9cbe711521cc25e29f1879fa47ca42347a5ecfc0f94526166a4acb73f5787d5a5d577d68e3fe756cedce0c862b4aebfb54022fea51f296cbbeeff173e2ad5521
7
- data.tar.gz: a07f6c1bdd5457be3cad8fececa4974de6bc95a952c73e31b718e22606a6d4c6807293729a784d55655a4419e10486c7de171dd1630ceb2f275605b263955e5d
6
+ metadata.gz: 1b1ac5b466169fd9f2698b79617ef4d2c6dd9dbf35b0cca715102ddddfcb2a0013be3bd02153263da42a7f3cde0150ccffa4f3e16e7b750dd0f73be23420e4b1
7
+ data.tar.gz: 26338d106c6e1cb5133c305c97ec5a8bb1c75292120ce2928efb93572ea6ff79b203eef4a6d73419d097cad76d6a0e22e71beac64a0f483dc09919e8d7d25e86
@@ -10,7 +10,8 @@ require "mn-requirements"
10
10
  module IsoDoc
11
11
  class Convert < ::IsoDoc::Common
12
12
  attr_accessor :options, :i18n, :meta, :xrefs, :reqt_models,
13
- :requirements_processor, :doctype, :bibrender
13
+ :requirements_processor, :doctype, :bibrender,
14
+ :tempfile_cache, :wordcoverpage, :wordintropage
14
15
 
15
16
  # htmlstylesheet: Generic stylesheet for HTML
16
17
  # htmlstylesheet_override: Override stylesheet for HTML
@@ -89,11 +90,15 @@ module IsoDoc
89
90
  i18nhash: @i18n.get))
90
91
  end
91
92
 
93
+ def convert1_namespaces(html)
94
+ html.add_namespace("epub", "http://www.idpf.org/2007/ops")
95
+ end
96
+
92
97
  def convert1(docxml, filename, dir)
93
98
  @xrefs.parse docxml
94
99
  noko do |xml|
95
100
  xml.html lang: @lang.to_s do |html|
96
- html.parent.add_namespace("epub", "http://www.idpf.org/2007/ops")
101
+ convert1_namespaces(html.parent)
97
102
  info docxml, nil
98
103
  populate_css
99
104
  html.head { |head| define_head head, filename, dir }
@@ -177,5 +182,19 @@ module IsoDoc
177
182
  else "##{node['target']}"
178
183
  end
179
184
  end
185
+
186
+ # use a different class than self for rendering, as a result
187
+ # of document-specific criteria
188
+ # but pass on any singleton methods defined on top of the self instance
189
+ def swap_renderer(oldklass, newklass, file, input_filename, debug)
190
+ ref = oldklass # avoid oldklass == self for indirection of methods
191
+ oldklass.singleton_methods.each do |x|
192
+ newklass.define_singleton_method(x) do |*args|
193
+ ref.public_send(x, *args)
194
+ end
195
+ end
196
+ oldklass.singleton_methods.empty? or
197
+ newklass.convert_init(file, input_filename, debug)
198
+ end
180
199
  end
181
200
  end
@@ -8,7 +8,7 @@ module IsoDoc
8
8
  node["update-type"] == "true" and url = suffix_url(url)
9
9
  out.a **attr_code(href: url, title: node["alt"]) do |l|
10
10
  if node.elements.empty? && node.text.strip.empty?
11
- l << node["target"].sub(/^mailto:/, "")
11
+ l << @c.encode(node["target"].sub(/^mailto:/, ""), :basic, :hexadecimal)
12
12
  else node.children.each { |n| parse(n, l) }
13
13
  end
14
14
  end
@@ -100,7 +100,7 @@ module IsoDoc
100
100
  end
101
101
 
102
102
  def maths_just_numeral(node)
103
- mn = node.at("./m:mn", MATHML).children
103
+ mn = node.at(".//m:mn", MATHML).children
104
104
  if node.parent.name == "stem"
105
105
  node.parent.replace(mn)
106
106
  else
@@ -127,12 +127,22 @@ module IsoDoc
127
127
  end
128
128
 
129
129
  def mathml_number(node, locale)
130
- justnumeral = node.elements.size == 1 && node.elements.first.name == "mn"
130
+ justnumeral = numeric_mathml?(node)
131
131
  justnumeral or asciimath_dup(node)
132
132
  localize_maths(node, locale)
133
133
  justnumeral and maths_just_numeral(node)
134
134
  end
135
135
 
136
+ def numeric_mathml?(node)
137
+ m = {}
138
+ node.traverse do |x|
139
+ %w(mstyle mrow math text).include?(x.name) and next
140
+ m[x.name] ||= 0
141
+ m[x.name] += 1
142
+ end
143
+ m.keys.size == 1 && m["mn"] == 1
144
+ end
145
+
136
146
  def mathml_style_inherit(node)
137
147
  node.at("./ancestor::xmlns:strong") or return
138
148
  node.children =
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.9.4".freeze
2
+ VERSION = "2.10.0".freeze
3
3
  end
@@ -5,6 +5,14 @@ require_relative "lists"
5
5
  module IsoDoc
6
6
  module WordFunction
7
7
  module Body
8
+ def convert1_namespaces(html)
9
+ super
10
+ html.add_namespace("v", "urn:schemas-microsoft-com:vml")
11
+ html.add_namespace("o", "urn:schemas-microsoft-com:office:office")
12
+ html.add_namespace("w", "urn:schemas-microsoft-com:office:word")
13
+ html.add_namespace("m", "http://schemas.microsoft.com/office/2004/12/omml")
14
+ end
15
+
8
16
  def define_head(head, filename, _dir)
9
17
  head.style do |style|
10
18
  loc = File.join(File.dirname(__FILE__), "..", "base_style",
@@ -7,17 +7,21 @@ module IsoDoc
7
7
  module WordFunction
8
8
  module Postprocess
9
9
  def postprocess(result, filename, dir)
10
+ result = postprocess_cleanup(result)
10
11
  filename = filename.sub(/\.doc$/, "")
11
12
  header = generate_header(filename, dir)
12
- result = from_xhtml(cleanup(to_xhtml(textcleanup(result))))
13
+ @wordstylesheet = wordstylesheet_update
13
14
  toWord(result, filename, dir, header)
14
15
  @files_to_delete.each { |f| FileUtils.rm_f f }
15
16
  end
16
17
 
17
- def toWord(result, filename, dir, header)
18
- result = from_xhtml(word_cleanup(to_xhtml(result)))
18
+ def postprocess_cleanup(result)
19
+ result = cleanup(to_xhtml(textcleanup(result)))
20
+ from_xhtml(word_cleanup(result))
19
21
  .gsub("-DOUBLE_HYPHEN_ESCAPE-", "--")
20
- @wordstylesheet = wordstylesheet_update
22
+ end
23
+
24
+ def toWord(result, filename, dir, header)
21
25
  Html2Doc.new(
22
26
  filename: filename, imagedir: @localdir,
23
27
  stylesheet: @wordstylesheet&.path,
@@ -60,6 +64,7 @@ module IsoDoc
60
64
  word_tab_clean(docxml)
61
65
  authority_cleanup(docxml)
62
66
  word_footnote_format(docxml)
67
+ word_remove_empty_sections(docxml)
63
68
  docxml
64
69
  end
65
70
 
@@ -6,21 +6,30 @@ module IsoDoc
6
6
  word_intro(docxml, @wordToClevels) if @wordintropage
7
7
  end
8
8
 
9
+ def word_remove_empty_sections(docxml)
10
+ %w(WordSection1 WordSection2).each do |x|
11
+ ins = docxml.at("//div[@class='#{x}']") or next
12
+ @c.decode(ins.text).gsub(/\p{Z}|\p{C}/, "").strip.empty? or next
13
+ ins.next_element.remove
14
+ ins.remove
15
+ end
16
+ end
17
+
9
18
  def word_cover(docxml)
19
+ ins = docxml.at('//div[@class="WordSection1"]') or return
10
20
  cover = File.read(@wordcoverpage, encoding: "UTF-8")
11
21
  cover = populate_template(cover, :word)
12
22
  coverxml = to_word_xhtml_fragment(cover)
13
- docxml.at('//div[@class="WordSection1"]').children.first.previous =
14
- coverxml.to_xml(encoding: "US-ASCII")
23
+ ins.children.first.previous = coverxml.to_xml(encoding: "US-ASCII")
15
24
  end
16
25
 
17
26
  def word_intro(docxml, level)
27
+ ins = docxml.at('//div[@class="WordSection2"]') or return
18
28
  intro = insert_toc(File.read(@wordintropage, encoding: "UTF-8"),
19
29
  docxml, level)
20
30
  intro = populate_template(intro, :word)
21
31
  introxml = to_word_xhtml_fragment(intro)
22
- docxml.at('//div[@class="WordSection2"]').children.first.previous =
23
- introxml.to_xml(encoding: "US-ASCII")
32
+ ins.children.first.previous = introxml.to_xml(encoding: "US-ASCII")
24
33
  end
25
34
 
26
35
  # add namespaces for Word fragments
@@ -90,10 +99,7 @@ module IsoDoc
90
99
  def generate_header(filename, _dir)
91
100
  @header or return nil
92
101
  template = IsoDoc::Common.liquid(File.read(@header, encoding: "UTF-8"))
93
- meta = @meta.get.merge(@labels ? { labels: @labels } : {})
94
- .merge(@meta.labels ? { labels: @meta.labels } : {})
95
- meta[:filename] = filename
96
- params = meta.transform_keys(&:to_s)
102
+ params = header_params(filename)
97
103
  Tempfile.open(%w(header html),
98
104
  mode: File::BINARY | File::SHARE_DELETE,
99
105
  encoding: "utf-8") do |f|
@@ -102,6 +108,13 @@ module IsoDoc
102
108
  end
103
109
  end
104
110
 
111
+ def header_params(filename)
112
+ meta = @meta.get.merge(@labels ? { labels: @labels } : {})
113
+ .merge(@meta.labels ? { labels: @meta.labels } : {})
114
+ meta[:filename] = filename
115
+ meta.transform_keys(&:to_s)
116
+ end
117
+
105
118
  def word_section_breaks(docxml)
106
119
  @landscapestyle = ""
107
120
  word_section_breaks1(docxml, "WordSection2")
@@ -88,6 +88,7 @@ module IsoDoc
88
88
 
89
89
  def admonition_anchor_names(sections)
90
90
  sections.each do |s|
91
+ s.at(ns(".//admonition[@type = 'box']")) or next
91
92
  notes = s.xpath(child_asset_path("admonition[@type = 'box']"))
92
93
  admonition_anchor_names1(notes, Counter.new)
93
94
  admonition_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
@@ -132,20 +133,19 @@ module IsoDoc
132
133
  end
133
134
  end
134
135
 
135
- def list_item_anchor_names(list, list_anchor, depth, prev_label,
136
- refer_list)
136
+ def list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list)
137
137
  c = Counter.new(list["start"] ? list["start"].to_i - 1 : 0)
138
138
  list.xpath(ns("./li")).each do |li|
139
139
  bare_label, label =
140
140
  list_item_value(li, c, depth, { list_anchor: list_anchor, prev_label: prev_label,
141
- refer_list: refer_list })
141
+ refer_list: depth == 1 ? refer_list : nil })
142
142
  li["id"] and @anchors[li["id"]] =
143
143
  { label: bare_label, bare_xref: "#{label})",
144
144
  xref: "#{label})",
145
145
  type: "listitem", refer_list: refer_list,
146
146
  container: list_anchor[:container] }
147
147
  (li.xpath(ns(".//ol")) - li.xpath(ns(".//ol//ol"))).each do |ol|
148
- list_item_anchor_names(ol, list_anchor, depth + 1, label, false)
148
+ list_item_anchor_names(ol, list_anchor, depth + 1, label, refer_list)
149
149
  end
150
150
  end
151
151
  end
@@ -105,11 +105,12 @@ module IsoDoc
105
105
  termnote_anchor_names(doc)
106
106
  termexample_anchor_names(doc)
107
107
  note_anchor_names(doc.xpath(ns("//table | //figure")))
108
- note_anchor_names(doc.xpath(ns(sections_xpath)))
109
- admonition_anchor_names(doc.xpath(ns(sections_xpath)))
110
- example_anchor_names(doc.xpath(ns(sections_xpath)))
111
- list_anchor_names(doc.xpath(ns(sections_xpath)))
112
- deflist_anchor_names(doc.xpath(ns(sections_xpath)))
108
+ sections = doc.xpath(ns(sections_xpath))
109
+ note_anchor_names(sections)
110
+ admonition_anchor_names(sections)
111
+ example_anchor_names(sections)
112
+ list_anchor_names(sections)
113
+ deflist_anchor_names(sections)
113
114
  bookmark_anchor_names(doc)
114
115
  end
115
116
 
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.9.4
4
+ version: 2.10.0
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-03-25 00:00:00.000000000 Z
11
+ date: 2024-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html2doc