isodoc 1.0.29 → 1.1.0

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: 56ed930565ee3a3bbb9649d61e3b552f6a13de3bb66cbf6f0e134d341c457386
4
- data.tar.gz: ee72443f7f96082b52b60bd525cb54d14088f0776c60bd88456bd5796de9d7a9
3
+ metadata.gz: 5b5e9597107793ecac111d5706640c399dcdec0411fdf49489c7058cf342bac2
4
+ data.tar.gz: 0b488bc57ff9c36a418f0012a49d68111a2e5f519a0a5d6191d201db99356526
5
5
  SHA512:
6
- metadata.gz: 8effb0abf7faf7a63a40a3cee55465290e5d156be8af54f16b36283e191f52ff3cba4443cce54f95c6b38a86c951656d78179cb02b4010c98a6bea8d80c97501
7
- data.tar.gz: 15c19b41ec493b97cc0ed06fbfe161f1d39f99e069f6d760a20858330f676c2bd35a60fe04f83b88569e6c61238090d0e2c336129f9665f6b695882fc75801d3
6
+ metadata.gz: 26660b7ac5d08b63f0846c5d8a3caea1f58eed0491c1fcfe83ee3d3b9b3d73da9eaf57636fc48ed84370f12a1dd25e6043b5372750b03d6fc20547be0c6f22f0
7
+ data.tar.gz: 99fe284cd22c1c19dc3f4528ae057857194b0354f55cf31414b1dbc1d54f9c564b1b45101faaad426c69fb2fb15dd3ae2186d0532a95a1675f5b92f7658d7546
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.add_dependency "liquid"
38
38
  spec.add_dependency "roman-numerals"
39
39
  spec.add_dependency "sassc", "~> 2.4.0"
40
- spec.add_dependency "metanorma", "~> 1.0.0"
40
+ spec.add_dependency "metanorma", "~> 1.1.0"
41
41
  spec.add_dependency "rake", "~> 12.0"
42
42
 
43
43
  spec.add_development_dependency "byebug", "~> 9.1"
@@ -21,6 +21,8 @@ require "isodoc/word_convert"
21
21
  require "isodoc/pdf_convert"
22
22
  require "isodoc/xslfo_convert"
23
23
  require "isodoc/headlesshtml_convert"
24
+ require "isodoc/presentation_xml_convert"
25
+ require "isodoc/xref"
24
26
 
25
27
  module IsoDoc
26
28
 
@@ -9,8 +9,6 @@ require_relative "./function/table"
9
9
  require_relative "./function/terms"
10
10
  require_relative "./function/to_word_html"
11
11
  require_relative "./function/utils"
12
- require_relative "./function/xref_gen"
13
- require_relative "./function/xref_sect_gen"
14
12
  require_relative "./function/reqt"
15
13
  require_relative "./class_utils"
16
14
 
@@ -27,8 +25,6 @@ module IsoDoc
27
25
  include Function::Terms
28
26
  include Function::ToWordHtml
29
27
  include Function::Utils
30
- include Function::XrefGen
31
- include Function::XrefSectGen
32
28
 
33
29
  extend ::IsoDoc::ClassUtils
34
30
  end
@@ -53,7 +53,6 @@ module IsoDoc
53
53
  @termexample = false
54
54
  @note = false
55
55
  @sourcecode = false
56
- @anchors = {}
57
56
  @footnotes = []
58
57
  @comments = []
59
58
  @in_footnote = false
@@ -142,7 +141,7 @@ module IsoDoc
142
141
  end
143
142
 
144
143
  def convert1(docxml, filename, dir)
145
- anchor_names docxml
144
+ @xrefs.parse docxml
146
145
  noko do |xml|
147
146
  xml.html **{ lang: "#{@lang}" } do |html|
148
147
  html.parent.add_namespace("epub", "http://www.idpf.org/2007/ops")
@@ -158,25 +157,36 @@ module IsoDoc
158
157
  @meta = Metadata.new(lang, script, labels)
159
158
  end
160
159
 
161
- def convert_init(file, filename, debug)
160
+ def xref_init(lang, script, klass, labels, options)
161
+ @xrefs = Xref.new(lang, script, klass, labels, options)
162
+ end
163
+
164
+ def convert_init(file, input_filename, debug)
162
165
  docxml = Nokogiri::XML(file)
163
- filename, dir = init_file(filename, debug)
166
+ filename, dir = init_file(input_filename, debug)
164
167
  docxml.root.default_namespace = ""
165
168
  lang = docxml&.at(ns("//bibdata/language"))&.text || @lang
166
169
  script = docxml&.at(ns("//bibdata/script"))&.text || @script
167
170
  i18n_init(lang, script)
168
171
  metadata_init(lang, script, @labels)
172
+ xref_init(lang, script, self, @labels, {})
169
173
  [docxml, filename, dir]
170
174
  end
171
175
 
172
- def convert(filename, file = nil, debug = false)
173
- file = File.read(filename, encoding: "utf-8") if file.nil?
176
+ def convert(input_filename, file = nil, debug = false, output_filename = nil)
177
+ file = File.read(input_filename, encoding: "utf-8") if file.nil?
174
178
  @openmathdelim, @closemathdelim = extract_delims(file)
175
- docxml, filename, dir = convert_init(file, filename, debug)
179
+ docxml, filename, dir = convert_init(file, input_filename, debug)
176
180
  result = convert1(docxml, filename, dir)
177
181
  return result if debug
178
- postprocess(result, filename, dir)
182
+ output_filename ||= "#{filename}.#{@suffix}"
183
+ postprocess(result, output_filename, dir)
179
184
  FileUtils.rm_rf dir
180
185
  end
186
+
187
+ def middle_clause
188
+ "//clause[parent::sections][not(xmlns:title = 'Scope')]"\
189
+ "[not(descendant::terms)]".freeze
190
+ end
181
191
  end
182
192
  end
@@ -6,7 +6,7 @@ module IsoDoc::Function
6
6
 
7
7
  def figure_name_parse(node, div, name)
8
8
  return if name.nil? && node.at(ns("./figure"))
9
- lbl = anchor(node['id'], :label, false)
9
+ lbl = @xrefs.anchor(node['id'], :label, false)
10
10
  lbl = nil if labelled_ancestor(node) && node.ancestors("figure").empty?
11
11
  return if lbl.nil? && name.nil?
12
12
  div.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
@@ -55,7 +55,7 @@ module IsoDoc::Function
55
55
  end
56
56
 
57
57
  def sourcecode_name_parse(node, div, name)
58
- lbl = anchor(node['id'], :label, false)
58
+ lbl = @xrefs.anchor(node['id'], :label, false)
59
59
  lbl = nil if labelled_ancestor(node)
60
60
  return if lbl.nil? && name.nil?
61
61
  div.p **{ class: "SourceTitle", style: "text-align:center;" } do |p|
@@ -141,7 +141,7 @@ module IsoDoc::Function
141
141
  out.div **attr_code(class: "formula") do |div|
142
142
  div.p do |p|
143
143
  parse(node.at(ns("./stem")), div)
144
- lbl = anchor(node['id'], :label, false)
144
+ lbl = @xrefs.anchor(node['id'], :label, false)
145
145
  unless lbl.nil?
146
146
  insert_tab(div, 1)
147
147
  div << "(#{lbl})"
@@ -1,7 +1,7 @@
1
1
  module IsoDoc::Function
2
2
  module Blocks
3
3
  def example_label(node, div, name)
4
- n = get_anchors[node["id"]]
4
+ n = @xrefs.get[node["id"]]
5
5
  div.p **{ class: "example-title" } do |p|
6
6
  lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @example_lbl :
7
7
  l10n("#{@example_lbl} #{n[:label]}")
@@ -56,7 +56,7 @@ module IsoDoc::Function
56
56
  end
57
57
 
58
58
  def note_label(node)
59
- n = get_anchors[node["id"]]
59
+ n = @xrefs.get[node["id"]]
60
60
  return @note_lbl if n.nil? || n[:label].nil? || n[:label].empty?
61
61
  l10n("#{@note_lbl} #{n[:label]}")
62
62
  end
@@ -17,17 +17,17 @@ module IsoDoc::Function
17
17
  end
18
18
 
19
19
  def prefix_container(container, linkend, _target)
20
- l10n(anchor(container, :xref) + ", " + linkend)
20
+ l10n(@xrefs.anchor(container, :xref) + ", " + linkend)
21
21
  end
22
22
 
23
23
  def anchor_linkend(node, linkend)
24
24
  if node["citeas"].nil? && node["bibitemid"]
25
- return anchor(node["bibitemid"] ,:xref) || "???"
25
+ return @xrefs.anchor(node["bibitemid"] ,:xref) || "???"
26
26
  elsif node["target"] && !/.#./.match(node["target"])
27
- linkend = anchor(node["target"], :xref)
28
- container = anchor(node["target"], :container, false)
27
+ linkend = @xrefs.anchor(node["target"], :xref)
28
+ container = @xrefs.anchor(node["target"], :container, false)
29
29
  (container && get_note_container_id(node) != container &&
30
- @anchors[node["target"]]) &&
30
+ @xrefs.get[node["target"]]) &&
31
31
  linkend = prefix_container(container, linkend, node["target"])
32
32
  linkend = capitalise_xref(node, linkend)
33
33
  end
@@ -129,12 +129,6 @@ module IsoDoc::Function
129
129
  end
130
130
  end
131
131
 
132
- ISO_PUBLISHER_XPATH =
133
- "./contributor[xmlns:role/@type = 'publisher']/"\
134
- "organization[abbreviation = 'ISO' or xmlns:abbreviation = 'IEC' or "\
135
- "xmlns:name = 'International Organization for Standardization' or "\
136
- "xmlns:name = 'International Electrotechnical Commission']".freeze
137
-
138
132
  def is_standard(b)
139
133
  ret = false
140
134
  b.xpath(ns("./docidentifier")).each do |id|
@@ -185,7 +179,7 @@ module IsoDoc::Function
185
179
  def bibliography_parse(node, out)
186
180
  title = node&.at(ns("./title"))&.text || ""
187
181
  out.div do |div|
188
- anchor(node['id'], :label, false) and
182
+ @xrefs.anchor(node['id'], :label, false) and
189
183
  clause_parse_title(node, div, node.at(ns("./title")), out) or
190
184
  div.h2 title, **{ class: "Section3" }
191
185
  biblio_list(node, div, true)
@@ -199,16 +193,6 @@ module IsoDoc::Function
199
193
  ref
200
194
  end
201
195
 
202
- def reference_names(ref)
203
- isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
204
- ids = bibitem_ref_code(ref)
205
- identifiers = render_identifier(ids)
206
- date = ref.at(ns("./date[@type = 'published']"))
207
- allparts = ref.at(ns("./extent[@type='part'][referenceFrom='all']"))
208
- reference = docid_l10n(identifiers[0] || identifiers[1])
209
- @anchors[ref["id"]] = { xref: reference }
210
- end
211
-
212
196
  # def ref_names(ref)
213
197
  # linkend = ref.text
214
198
  # linkend.gsub!(/[\[\]]/, "") unless /^\[\d+\]$/.match linkend
@@ -2,7 +2,7 @@ module IsoDoc::Function
2
2
  module Blocks
3
3
  def recommendation_labels(node)
4
4
  [node.at(ns("./label")), node.at(ns("./title")),
5
- anchor(node['id'], :label, false)]
5
+ @xrefs.anchor(node['id'], :label, false)]
6
6
  end
7
7
 
8
8
  def recommendation_name(node, out, type)
@@ -11,8 +11,8 @@ module IsoDoc::Function
11
11
  def inline_header_title(out, node, c1)
12
12
  out.span **{ class: "zzMoveToFollowing" } do |s|
13
13
  s.b do |b|
14
- if anchor(node['id'], :label, false) && !@suppressheadingnumbers
15
- b << "#{anchor(node['id'], :label)}#{clausedelim}"
14
+ if @xrefs.anchor(node['id'], :label, false) && !@suppressheadingnumbers
15
+ b << "#{@xrefs.anchor(node['id'], :label)}#{clausedelim}"
16
16
  clausedelimspace(out)
17
17
  end
18
18
  c1&.children&.each { |c2| parse(c2, b) }
@@ -26,8 +26,8 @@ module IsoDoc::Function
26
26
  if node["inline-header"] == "true"
27
27
  inline_header_title(out, node, c1)
28
28
  else
29
- div.send "h#{anchor(node['id'], :level, false) || '1'}" do |h|
30
- lbl = anchor(node['id'], :label, false)
29
+ div.send "h#{@xrefs.anchor(node['id'], :level, false) || '1'}" do |h|
30
+ lbl = @xrefs.anchor(node['id'], :label, false)
31
31
  h << "#{lbl}#{clausedelim}" if lbl && !@suppressheadingnumbers
32
32
  clausedelimspace(out) if lbl && !@suppressheadingnumbers
33
33
  c1&.children&.each { |c2| parse(c2, h) }
@@ -58,14 +58,10 @@ module IsoDoc::Function
58
58
  div.parent.at(".//h1")
59
59
  end
60
60
 
61
- MIDDLE_CLAUSE =
62
- "//clause[parent::sections][not(xmlns:title = 'Scope')]"\
63
- "[not(descendant::terms)]".freeze
64
-
65
61
  def clause(isoxml, out)
66
- isoxml.xpath(ns(self.class::MIDDLE_CLAUSE)).each do |c|
62
+ isoxml.xpath(ns(middle_clause)).each do |c|
67
63
  out.div **attr_code(id: c["id"]) do |s|
68
- clause_name(anchor(c['id'], :label),
64
+ clause_name(@xrefs.anchor(c['id'], :label),
69
65
  c&.at(ns("./title")), s, nil)
70
66
  c.elements.reject { |c1| c1.name == "title" }.each do |c1|
71
67
  parse(c1, s)
@@ -76,7 +72,7 @@ module IsoDoc::Function
76
72
 
77
73
  def annex_name(annex, name, div)
78
74
  div.h1 **{ class: "Annex" } do |t|
79
- t << "#{anchor(annex['id'], :label)}<br/><br/>"
75
+ t << "#{@xrefs.anchor(annex['id'], :label)}<br/><br/>"
80
76
  t.b do |b|
81
77
  name&.children&.each { |c2| parse(c2, b) }
82
78
  end
@@ -3,7 +3,7 @@ module IsoDoc::Function
3
3
 
4
4
  def table_title_parse(node, out)
5
5
  name = node.at(ns("./name"))
6
- lbl = anchor(node['id'], :label, false)
6
+ lbl = @xrefs.anchor(node['id'], :label, false)
7
7
  lbl = nil if labelled_ancestor(node)
8
8
  return if name.nil? && lbl.nil?
9
9
  out.p **{ class: "TableTitle", style: "text-align:center;" } do |p|
@@ -43,7 +43,7 @@ module IsoDoc::Function
43
43
  out.div **note_attrs(node) do |div|
44
44
  first = node.first_element_child
45
45
  div.p do |p|
46
- p << "#{anchor(node['id'], :label) || '???'}: "
46
+ p << "#{@xrefs.anchor(node['id'], :label) || '???'}: "
47
47
  para_then_remainder(first, node, p, div)
48
48
  end
49
49
  end
@@ -59,7 +59,7 @@ module IsoDoc::Function
59
59
 
60
60
  def termdef_parse(node, out)
61
61
  out.p **{ class: "TermNum", id: node["id"] } do |p|
62
- p << "#{get_anchors[node["id"]][:label]}#{clausedelim}"
62
+ p << "#{@xrefs.get[node["id"]][:label]}#{clausedelim}"
63
63
  end
64
64
  set_termdomain("")
65
65
  node.children.each { |n| parse(n, out) }
@@ -16,18 +16,19 @@ module IsoDoc
16
16
 
17
17
  def initialize(options)
18
18
  @format = :html
19
+ @suffix = "headless.html"
19
20
  super
20
21
  end
21
22
 
22
- def convert(filename, file = nil, debug = false)
23
- file = File.read(filename, encoding: "utf-8") if file.nil?
23
+ def convert(input_filename, file = nil, debug = false, output_filename = nil)
24
+ file = File.read(input_filename, encoding: "utf-8") if file.nil?
24
25
  @openmathdelim, @closemathdelim = extract_delims(file)
25
- docxml, outname_html, dir = convert_init(file, filename, debug)
26
- result = convert1(docxml, outname_html, dir)
26
+ docxml, filename, dir = convert_init(file, input_filename, debug)
27
+ result = convert1(docxml, filename, dir)
27
28
  return result if debug
28
- postprocess(result, filename + ".tmp", dir)
29
+ postprocess(result, filename + ".tmp.html", dir)
29
30
  FileUtils.rm_rf dir
30
- strip_head(filename + ".tmp.html", outname_html + ".headless.html")
31
+ strip_head(filename + ".tmp.html", output_filename || "#{filename}.#{@suffix}")
31
32
  FileUtils.rm_rf ["#{filename}.tmp.html", tmpimagedir]
32
33
  end
33
34
 
@@ -16,10 +16,11 @@ module IsoDoc
16
16
 
17
17
  def initialize(options)
18
18
  @format = :html
19
+ @suffix = "html"
19
20
  super
20
21
  end
21
22
 
22
- def convert(filename, file = nil, debug = false)
23
+ def convert(filename, file = nil, debug = false, output_filename = nil)
23
24
  ret = super
24
25
  Dir.exists?(tmpimagedir) and Dir["#{tmpimagedir}/*"].empty? and
25
26
  FileUtils.rm_r tmpimagedir
@@ -4,7 +4,7 @@ require "base64"
4
4
  module IsoDoc::HtmlFunction
5
5
  module Html
6
6
  def convert1(docxml, filename, dir)
7
- anchor_names docxml
7
+ @xrefs.parse docxml
8
8
  noko do |xml|
9
9
  xml.html **{ lang: "#{@lang}" } do |html|
10
10
  info docxml, nil
@@ -18,7 +18,7 @@ module IsoDoc::HtmlFunction
18
18
  #result = populate_template(result, :html)
19
19
  result = from_xhtml(move_images(to_xhtml(result)))
20
20
  result = html5(script_cdata(inject_script(result)))
21
- File.open("#{filename}.html", "w:UTF-8") { |f| f.write(result) }
21
+ File.open(filename, "w:UTF-8") { |f| f.write(result) }
22
22
  end
23
23
 
24
24
  def html5(doc)
@@ -24,19 +24,21 @@ module IsoDoc
24
24
 
25
25
  def initialize(options)
26
26
  @format = :pdf
27
+ @suffix = "pdf"
27
28
  super
28
29
  end
29
30
 
30
- def convert(filename, file = nil, debug = false)
31
- file = File.read(filename, encoding: "utf-8") if file.nil?
31
+ def convert(input_filename, file = nil, debug = false, output_filename = nil)
32
+ file = File.read(input_filename, encoding: "utf-8") if file.nil?
32
33
  @openmathdelim, @closemathdelim = extract_delims(file)
33
- docxml, outname_html, dir = convert_init(file, filename, debug)
34
+ docxml, filename, dir = convert_init(file, input_filename, debug)
34
35
  result = convert1(docxml, filename, dir)
35
36
  return result if debug
36
- postprocess(result, filename, dir)
37
+ postprocess(result, filename + ".tmp.html", dir)
37
38
  FileUtils.rm_rf dir
38
- ::Metanorma::Output::Pdf.new.convert("#{filename}.html", outname_html + ".pdf")
39
- FileUtils.rm_rf ["#{filename}.html", tmpimagedir]
39
+ ::Metanorma::Output::Pdf.new.convert("#{filename}.tmp.html",
40
+ output_filename || "#{filename}.#{@suffix}")
41
+ FileUtils.rm_rf ["#{filename}.tmp.html", tmpimagedir]
40
42
  end
41
43
 
42
44
  def xref_parse(node, out)
@@ -0,0 +1,29 @@
1
+ module IsoDoc
2
+ class PresentationXMLConvert < ::IsoDoc::Convert
3
+ def initialize(options)
4
+ @format = :presentation
5
+ @suffix = "presentation.xml"
6
+ super
7
+ end
8
+
9
+ def convert1(docxml, filename, dir)
10
+ @xrefs.parse docxml
11
+ info docxml, nil
12
+ docxml.to_xml
13
+ end
14
+
15
+ def postprocess(result, filename, dir)
16
+ #result = from_xhtml(cleanup(to_xhtml(textcleanup(result))))
17
+ toXML(result, filename)
18
+ @files_to_delete.each { |f| FileUtils.rm_rf f }
19
+ end
20
+
21
+ def toXML(result, filename)
22
+ #result = (from_xhtml(html_cleanup(to_xhtml(result))))
23
+ #result = from_xhtml(move_images(to_xhtml(result)))
24
+ #result = html5(script_cdata(inject_script(result)))
25
+ File.open(filename, "w:UTF-8") { |f| f.write(result) }
26
+ end
27
+ end
28
+ end
29
+
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "1.0.29".freeze
2
+ VERSION = "1.1.0".freeze
3
3
  end
@@ -32,10 +32,11 @@ module IsoDoc
32
32
 
33
33
  def initialize(options)
34
34
  @format = :doc
35
+ @suffix = "doc"
35
36
  super
36
37
  end
37
38
 
38
- def convert(filename, file = nil, debug = false)
39
+ def convert(filename, file = nil, debug = false, output_filename = nil)
39
40
  ret = super
40
41
  FileUtils.rm_rf tmpimagedir
41
42
  ret
@@ -156,7 +156,7 @@ module IsoDoc::WordFunction
156
156
  out.div **note_attrs(node) do |div|
157
157
  first = node.first_element_child
158
158
  div.p **{ class: "Note" } do |p|
159
- anchor = get_anchors[node['id']]
159
+ anchor = @xrefs.get[node['id']]
160
160
  p << "#{anchor&.dig(:label) || '???'}: "
161
161
  para_then_remainder(first, node, p, div)
162
162
  end
@@ -32,6 +32,7 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
32
32
  end
33
33
 
34
34
  def postprocess(result, filename, dir)
35
+ filename = filename.sub(/\.doc$/, "")
35
36
  header = generate_header(filename, dir)
36
37
  result = from_xhtml(cleanup(to_xhtml(textcleanup(result))))
37
38
  toWord(result, filename, dir, header)
@@ -0,0 +1,59 @@
1
+ require_relative "xref/xref_anchor"
2
+ require_relative "xref/xref_counter"
3
+ require_relative "xref/xref_gen_seq"
4
+ require_relative "xref/xref_gen"
5
+ require_relative "xref/xref_sect_gen"
6
+ require_relative "class_utils"
7
+
8
+ module IsoDoc
9
+ class Xref
10
+ include XrefGen::Anchor
11
+ include XrefGen::Blocks
12
+ include XrefGen::Sections
13
+
14
+ def initialize(lang, script, klass, labels, options = {})
15
+ @anchors = {}
16
+ @lang = lang
17
+ @script = script
18
+ @klass = klass
19
+ @labels = labels
20
+ @options = options
21
+ end
22
+
23
+ def get
24
+ @anchors
25
+ end
26
+
27
+ def anchor(id, lbl, warning = true)
28
+ return nil if id.nil? || id.empty?
29
+ unless @anchors[id]
30
+ if warning
31
+ @seen ||= Seen_Anchor.instance
32
+ @seen.seen(id) or warn "No label has been processed for ID #{id}"
33
+ @seen.add(id)
34
+ return "[#{id}]"
35
+ end
36
+ end
37
+ @anchors.dig(id, lbl)
38
+ end
39
+
40
+ # extract names for all anchors, xref and label
41
+ def parse(docxml)
42
+ initial_anchor_names(docxml)
43
+ back_anchor_names(docxml)
44
+ # preempt clause notes with all other types of note (ISO default)
45
+ note_anchor_names(docxml.xpath(ns("//table | //figure")))
46
+ note_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
47
+ example_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
48
+ list_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
49
+ end
50
+
51
+ def ns(xpath)
52
+ Common::ns(xpath)
53
+ end
54
+
55
+ def l10n(a, lang = @lang, script = @script)
56
+ IsoDoc::Function::I18n::l10n(a, lang, script)
57
+ end
58
+ end
59
+ end
@@ -1,7 +1,7 @@
1
1
  require "singleton"
2
2
 
3
- module IsoDoc::Function
4
- module XrefGen
3
+ module IsoDoc::XrefGen
4
+ module Anchor
5
5
  class Seen_Anchor
6
6
  include Singleton
7
7
 
@@ -12,34 +12,23 @@ module IsoDoc::Function
12
12
  def seen(x)
13
13
  @seen.has_key?(x)
14
14
  end
15
-
15
+
16
16
  def add(x)
17
17
  @seen[x] = true
18
18
  end
19
19
  end
20
20
 
21
- @anchors = {}
21
+ def initialize()
22
+ @anchors = {}
23
+ end
22
24
 
23
25
  def get_anchors
24
26
  @anchors
25
27
  end
26
28
 
27
- def anchor(id, lbl, warning = true)
28
- return nil if id.nil? || id.empty?
29
- unless @anchors[id]
30
- if warning
31
- @seen ||= Seen_Anchor.instance
32
- @seen.seen(id) or warn "No label has been processed for ID #{id}"
33
- @seen.add(id)
34
- return "[#{id}]"
35
- end
36
- end
37
- @anchors.dig(id, lbl)
38
- end
39
-
40
29
  def anchor_struct_label(lbl, elem)
41
30
  case elem
42
- when @appendix_lbl then l10n("#{elem} #{lbl}")
31
+ when @labels["appendix"] then l10n("#{elem} #{lbl}")
43
32
  else
44
33
  lbl.to_s
45
34
  end
@@ -47,8 +36,8 @@ module IsoDoc::Function
47
36
 
48
37
  def anchor_struct_xref(lbl, elem)
49
38
  case elem
50
- when @formula_lbl then l10n("#{elem} (#{lbl})")
51
- when @inequality_lbl then l10n("#{elem} (#{lbl})")
39
+ when @labels["formula"] then l10n("#{elem} (#{lbl})")
40
+ when @labels["inequality"] then l10n("#{elem} (#{lbl})")
52
41
  else
53
42
  l10n("#{elem} #{lbl}")
54
43
  end
@@ -59,7 +48,7 @@ module IsoDoc::Function
59
48
  ret[:label] = unnumbered == "true" ? nil : anchor_struct_label(lbl, elem)
60
49
  ret[:xref] = anchor_struct_xref(unnumbered == "true" ? "(??)" : lbl, elem)
61
50
  ret[:xref].gsub!(/ $/, "")
62
- ret[:container] = get_clause_id(container) unless container.nil?
51
+ ret[:container] = @klass.get_clause_id(container) unless container.nil?
63
52
  ret[:type] = type
64
53
  ret
65
54
  end
@@ -0,0 +1,74 @@
1
+ require "roman-numerals"
2
+
3
+ module IsoDoc::XrefGen
4
+ class Counter
5
+ def initialize
6
+ @num = 0
7
+ @letter = ""
8
+ @subseq = ""
9
+ @letter_override = nil
10
+ @number_override = nil
11
+ end
12
+
13
+ def new_subseq_increment(node)
14
+ @subseq = node["subsequence"]
15
+ @num += 1
16
+ @letter = node["subsequence"] ? "a" : ""
17
+ if node["number"]
18
+ /^(?<n>\d*)(?<a>[a-z]*)$/ =~ node["number"]
19
+ if n || a
20
+ @letter_override = @letter = a if a
21
+ @number_override = @num = n.to_i if n
22
+ else
23
+ @letter_override = node["number"]
24
+ @letter = @letter_override if /^[a-z]$/.match(@letter_override)
25
+ end
26
+ end
27
+ end
28
+
29
+ def sequence_increment(node)
30
+ if node["number"]
31
+ @number_override = node["number"]
32
+ @num = @number_override.to_i if /^\d+$/.match(@number_override)
33
+ else
34
+ @num += 1
35
+ end
36
+ end
37
+
38
+ def subsequence_increment(node)
39
+ if node["number"]
40
+ @letter_override = node["number"]
41
+ @letter = @letter_override if /^[a-z]$/.match(@letter_override)
42
+ else
43
+ @letter = (@letter.ord + 1).chr.to_s
44
+ end
45
+ end
46
+
47
+ def increment(node)
48
+ return self if node["unnumbered"]
49
+ @letter_override = nil
50
+ @number_override = nil
51
+ if node["subsequence"] != @subseq
52
+ new_subseq_increment(node)
53
+ elsif @letter.empty?
54
+ sequence_increment(node)
55
+ else
56
+ subsequence_increment(node)
57
+ end
58
+ self
59
+ end
60
+
61
+ def print
62
+ "#{@number_override || @num}#{@letter_override || @letter}"
63
+ end
64
+
65
+ def listlabel(depth)
66
+ return @num.to_s if [2, 7].include? depth
67
+ return (96 + @num).chr.to_s if [1, 6].include? depth
68
+ return (64 + @num).chr.to_s if [4, 9].include? depth
69
+ return RomanNumerals.to_roman(@num).downcase if [3, 8].include? depth
70
+ return RomanNumerals.to_roman(@num).upcase if [5, 10].include? depth
71
+ return @num.to_s
72
+ end
73
+ end
74
+ end
@@ -1,11 +1,9 @@
1
- require_relative "xref_counter"
2
- require_relative "xref_anchor"
3
- require_relative "xref_gen_seq"
1
+ require_relative "xref_gen_seq.rb"
4
2
 
5
- module IsoDoc::Function
6
- module XrefGen
3
+ module IsoDoc::XrefGen
4
+ module Blocks
7
5
  def termnote_label(n)
8
- @termnote_lbl.gsub(/%/, n.to_s)
6
+ @labels["termnote"].gsub(/%/, n.to_s)
9
7
  end
10
8
 
11
9
  def termnote_anchor_names(docxml)
@@ -17,7 +15,7 @@ module IsoDoc::Function
17
15
  @anchors[n["id"]] =
18
16
  { label: termnote_label(c.print), type: "termnote",
19
17
  xref: l10n("#{anchor(t['id'], :xref)}, "\
20
- "#{@note_xref_lbl} #{c.print}") }
18
+ "#{@labels["note_xref"]} #{c.print}") }
21
19
  end
22
20
  end
23
21
  end
@@ -33,7 +31,7 @@ module IsoDoc::Function
33
31
  @anchors[n["id"]] = {
34
32
  type: "termexample", label: idx,
35
33
  xref: l10n("#{anchor(t['id'], :xref)}, "\
36
- "#{@example_xref_lbl} #{c.print}") }
34
+ "#{@labels["example_xref"]} #{c.print}") }
37
35
  end
38
36
  end
39
37
  end
@@ -57,7 +55,7 @@ module IsoDoc::Function
57
55
  notes.each do |n|
58
56
  next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty?
59
57
  idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
60
- @anchors[n["id"]] = anchor_struct(idx, n, @note_xref_lbl,
58
+ @anchors[n["id"]] = anchor_struct(idx, n, @labels["note_xref"],
61
59
  "note", false)
62
60
  end
63
61
  note_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
@@ -79,7 +77,7 @@ module IsoDoc::Function
79
77
  next if @anchors[n["id"]]
80
78
  next if n["id"].nil? || n["id"].empty?
81
79
  idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
82
- @anchors[n["id"]] = anchor_struct(idx, n, @example_xref_lbl,
80
+ @anchors[n["id"]] = anchor_struct(idx, n, @labels["example_xref"],
83
81
  "example", n["unnumbered"])
84
82
  end
85
83
  example_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
@@ -94,7 +92,7 @@ module IsoDoc::Function
94
92
  notes.each do |n|
95
93
  next if n["id"].nil? || n["id"].empty?
96
94
  idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
97
- @anchors[n["id"]] = anchor_struct(idx, n, @list_lbl, "list", false)
95
+ @anchors[n["id"]] = anchor_struct(idx, n, @labels["list"], "list", false)
98
96
  list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size != 1)
99
97
  end
100
98
  list_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
@@ -115,16 +113,5 @@ module IsoDoc::Function
115
113
  end
116
114
  end
117
115
  end
118
-
119
- # extract names for all anchors, xref and label
120
- def anchor_names(docxml)
121
- initial_anchor_names(docxml)
122
- back_anchor_names(docxml)
123
- # preempt clause notes with all other types of note (ISO default)
124
- note_anchor_names(docxml.xpath(ns("//table | //figure")))
125
- note_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
126
- example_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
127
- list_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
128
- end
129
116
  end
130
117
  end
@@ -1,11 +1,19 @@
1
- module IsoDoc::Function
2
- module XrefGen
1
+ module IsoDoc::XrefGen
2
+ module Blocks
3
+ def hiersep
4
+ "."
5
+ end
6
+
7
+ def hierfigsep
8
+ "-"
9
+ end
10
+
3
11
  def subfigure_increment(j, c, t)
4
12
  if t.parent.name == "figure" then j += 1
5
- else
6
- j = 0
7
- c.increment(t)
8
- end
13
+ else
14
+ j = 0
15
+ c.increment(t)
16
+ end
9
17
  j
10
18
  end
11
19
 
@@ -18,7 +26,7 @@ module IsoDoc::Function
18
26
  label = c.print + (j.zero? ? "" : "-#{j}")
19
27
  next if t["id"].nil? || t["id"].empty?
20
28
  @anchors[t["id"]] =
21
- anchor_struct(label, nil, @figure_lbl, "figure", t["unnumbered"])
29
+ anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
22
30
  end
23
31
  end
24
32
 
@@ -27,7 +35,7 @@ module IsoDoc::Function
27
35
  clause.xpath(ns(".//table")).each do |t|
28
36
  next if t["id"].nil? || t["id"].empty?
29
37
  @anchors[t["id"]] = anchor_struct(c.increment(t).print, nil,
30
- @table_lbl, "table", t["unnumbered"])
38
+ @labels["table"], "table", t["unnumbered"])
31
39
  end
32
40
  end
33
41
 
@@ -37,7 +45,7 @@ module IsoDoc::Function
37
45
  next if t["id"].nil? || t["id"].empty?
38
46
  @anchors[t["id"]] =
39
47
  anchor_struct(c.increment(t).print, t,
40
- t["inequality"] ? @inequality_lbl : @formula_lbl,
48
+ t["inequality"] ? @labels["inequality"] : @labels["formula"],
41
49
  "formula", t["unnumbered"])
42
50
  end
43
51
  end
@@ -56,9 +64,9 @@ module IsoDoc::Function
56
64
  end
57
65
 
58
66
  def sequential_permission_names2(t, id)
59
- sequential_permission_names1(t, id, "permission", @permission_lbl)
60
- sequential_permission_names1(t, id, "requirement", @requirement_lbl)
61
- sequential_permission_names1(t, id, "recommendation", @recommendation_lbl)
67
+ sequential_permission_names1(t, id, "permission", @labels["permission"])
68
+ sequential_permission_names1(t, id, "requirement", @labels["requirement"])
69
+ sequential_permission_names1(t, id, "recommendation", @labels["recommendation"])
62
70
  end
63
71
 
64
72
  def sequential_permission_names1(block, lbl, klass, label)
@@ -75,9 +83,9 @@ module IsoDoc::Function
75
83
  sequential_table_names(clause)
76
84
  sequential_figure_names(clause)
77
85
  sequential_formula_names(clause)
78
- sequential_permission_names(clause, "permission", @permission_lbl)
79
- sequential_permission_names(clause, "requirement", @requirement_lbl)
80
- sequential_permission_names(clause, "recommendation", @recommendation_lbl)
86
+ sequential_permission_names(clause, "permission", @labels["permission"])
87
+ sequential_permission_names(clause, "requirement", @labels["requirement"])
88
+ sequential_permission_names(clause, "recommendation", @labels["recommendation"])
81
89
  end
82
90
 
83
91
  def hierarchical_figure_names(clause, num)
@@ -89,7 +97,7 @@ module IsoDoc::Function
89
97
  label = "#{num}#{hiersep}#{c.print}" +
90
98
  (j.zero? ? "" : "#{hierfigsep}#{j}")
91
99
  next if t["id"].nil? || t["id"].empty?
92
- @anchors[t["id"]] = anchor_struct(label, nil, @figure_lbl, "figure",
100
+ @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"], "figure",
93
101
  t["unnumbered"])
94
102
  end
95
103
  end
@@ -100,7 +108,7 @@ module IsoDoc::Function
100
108
  next if t["id"].nil? || t["id"].empty?
101
109
  @anchors[t["id"]] =
102
110
  anchor_struct("#{num}#{hiersep}#{c.increment(t).print}",
103
- nil, @table_lbl, "table", t["unnumbered"])
111
+ nil, @labels["table"], "table", t["unnumbered"])
104
112
  end
105
113
  end
106
114
 
@@ -108,11 +116,11 @@ module IsoDoc::Function
108
116
  hierarchical_table_names(clause, num)
109
117
  hierarchical_figure_names(clause, num)
110
118
  hierarchical_formula_names(clause, num)
111
- hierarchical_permission_names(clause, num, "permission", @permission_lbl)
119
+ hierarchical_permission_names(clause, num, "permission", @labels["permission"])
112
120
  hierarchical_permission_names(clause, num, "requirement",
113
- @requirement_lbl)
121
+ @labels["requirement"])
114
122
  hierarchical_permission_names(clause, num, "recommendation",
115
- @recommendation_lbl)
123
+ @labels["recommendation"])
116
124
  end
117
125
 
118
126
  def hierarchical_formula_names(clause, num)
@@ -121,7 +129,7 @@ module IsoDoc::Function
121
129
  next if t["id"].nil? || t["id"].empty?
122
130
  @anchors[t["id"]] =
123
131
  anchor_struct("#{num}#{hiersep}#{c.increment(t).print}", nil,
124
- t["inequality"] ? @inequality_lbl : @formula_lbl,
132
+ t["inequality"] ? @labels["inequality"] : @labels["formula"],
125
133
  "formula", t["unnumbered"])
126
134
  end
127
135
  end
@@ -136,13 +144,13 @@ module IsoDoc::Function
136
144
  end
137
145
  end
138
146
 
139
- def hierarchical_permission_names2(t, id)
140
- hierarchical_permission_names1(t, id, "permission", @permission_lbl)
141
- hierarchical_permission_names1(t, id, "requirement", @requirement_lbl)
142
- hierarchical_permission_names1(t, id, "recommendation", @recommendation_lbl)
147
+ def hierarchical_permission_names2(t, id)
148
+ hierarchical_permission_names1(t, id, "permission", @labels["permission"])
149
+ hierarchical_permission_names1(t, id, "requirement", @labels["requirement"])
150
+ hierarchical_permission_names1(t, id, "recommendation", @labels["recommendation"])
143
151
  end
144
152
 
145
- def hierarchical_permission_names1(block, lbl, klass, label)
153
+ def hierarchical_permission_names1(block, lbl, klass, label)
146
154
  c = Counter.new
147
155
  block.xpath(ns("./#{klass}")).each do |t|
148
156
  next if t["id"].nil? || t["id"].empty?
@@ -1,18 +1,18 @@
1
- module IsoDoc::Function
2
- module XrefSectGen
1
+ module IsoDoc::XrefGen
2
+ module Sections
3
3
  def back_anchor_names(docxml)
4
4
  docxml.xpath(ns("//annex")).each_with_index do |c, i|
5
5
  annex_names(c, (65 + i).chr.to_s)
6
6
  end
7
7
  docxml.xpath(
8
- ns("//bibliography/clause[.//references[@normative = 'false']] | "\
8
+ ns("//bibliography/clause[.//references[@normative = 'false']] | "\
9
9
  "//bibliography/references[@normative = 'false']"
10
- )).each do |b|
11
- preface_names(b)
12
- end
13
- docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
14
- reference_names(ref)
15
- end
10
+ )).each do |b|
11
+ preface_names(b)
12
+ end
13
+ docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
14
+ reference_names(ref)
15
+ end
16
16
  end
17
17
 
18
18
  def initial_anchor_names(d)
@@ -72,8 +72,7 @@ module IsoDoc::Function
72
72
  end
73
73
 
74
74
  def clause_names(docxml, sect_num)
75
- q = self.class::MIDDLE_CLAUSE
76
- docxml.xpath(ns(q)).each_with_index do |c, i|
75
+ docxml.xpath(ns(@klass.middle_clause)).each_with_index do |c, i|
77
76
  section_names(c, (i + sect_num), 1)
78
77
  end
79
78
  end
@@ -82,7 +81,7 @@ module IsoDoc::Function
82
81
  return num if clause.nil?
83
82
  num = num + 1
84
83
  @anchors[clause["id"]] =
85
- { label: num.to_s, xref: l10n("#{@clause_lbl} #{num}"), level: lvl,
84
+ { label: num.to_s, xref: l10n("#{@labels["clause"]} #{num}"), level: lvl,
86
85
  type: "clause" }
87
86
  clause.xpath(ns(SUBCLAUSES)).
88
87
  each_with_index do |c, i|
@@ -93,7 +92,7 @@ module IsoDoc::Function
93
92
 
94
93
  def section_names1(clause, num, level)
95
94
  @anchors[clause["id"]] =
96
- { label: num, level: level, xref: l10n("#{@clause_lbl} #{num}"),
95
+ { label: num, level: level, xref: l10n("#{@labels["clause"]} #{num}"),
97
96
  type: "clause" }
98
97
  clause.xpath(ns(SUBCLAUSES)).
99
98
  each_with_index do |c, i|
@@ -102,9 +101,9 @@ module IsoDoc::Function
102
101
  end
103
102
 
104
103
  def annex_name_lbl(clause, num)
105
- obl = l10n("(#{@inform_annex_lbl})")
106
- obl = l10n("(#{@norm_annex_lbl})") if clause["obligation"] == "normative"
107
- l10n("<b>#{@annex_lbl} #{num}</b><br/>#{obl}")
104
+ obl = l10n("(#{@labels["inform_annex"]})")
105
+ obl = l10n("(#{@labels["norm_annex"]})") if clause["obligation"] == "normative"
106
+ l10n("<b>#{@labels["annex"]} #{num}</b><br/>#{obl}")
108
107
  end
109
108
 
110
109
  def single_annex_special_section(clause)
@@ -119,7 +118,7 @@ module IsoDoc::Function
119
118
  def annex_names(clause, num)
120
119
  @anchors[clause["id"]] = { label: annex_name_lbl(clause, num),
121
120
  type: "clause",
122
- xref: "#{@annex_lbl} #{num}", level: 1 }
121
+ xref: "#{@labels["annex"]} #{num}", level: 1 }
123
122
  if a = single_annex_special_section(clause)
124
123
  annex_names1(a, "#{num}", 1)
125
124
  else
@@ -131,11 +130,26 @@ module IsoDoc::Function
131
130
  end
132
131
 
133
132
  def annex_names1(clause, num, level)
134
- @anchors[clause["id"]] = { label: num, xref: "#{@annex_lbl} #{num}",
133
+ @anchors[clause["id"]] = { label: num, xref: "#{@labels["annex"]} #{num}",
135
134
  level: level, type: "clause" }
136
135
  clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
137
136
  annex_names1(c, "#{num}.#{i + 1}", level + 1)
138
137
  end
139
138
  end
139
+
140
+ ISO_PUBLISHER_XPATH =
141
+ "./contributor[xmlns:role/@type = 'publisher']/"\
142
+ "organization[abbreviation = 'ISO' or xmlns:abbreviation = 'IEC' or "\
143
+ "xmlns:name = 'International Organization for Standardization' or "\
144
+ "xmlns:name = 'International Electrotechnical Commission']".freeze
145
+
146
+ def reference_names(ref)
147
+ isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
148
+ ids = @klass.bibitem_ref_code(ref)
149
+ identifiers = @klass.render_identifier(ids)
150
+ date = ref.at(ns("./date[@type = 'published']"))
151
+ reference = @klass.docid_l10n(identifiers[0] || identifiers[1])
152
+ @anchors[ref["id"]] = { xref: reference }
153
+ end
140
154
  end
141
155
  end
@@ -15,14 +15,26 @@ module IsoDoc
15
15
 
16
16
  def initialize(options)
17
17
  @format = :pdf
18
+ @suffix = "pdf"
18
19
  super
19
20
  end
20
21
 
21
- def convert(filename, file = nil, debug = false)
22
- file = File.read(filename, encoding: "utf-8") if file.nil?
23
- docxml, outname_html, dir = convert_init(file, filename, debug)
22
+ def pdf_stylesheet(docxml)
23
+ nil
24
+ end
25
+
26
+ def convert(input_filename, file = nil, debug = false, output_filename = nil)
27
+ file = File.read(input_filename, encoding: "utf-8") if file.nil?
28
+ docxml, filename, dir = convert_init(file, input_filename, debug)
29
+ /\.xml$/.match(input_filename) or
30
+ input_filename = Tempfile.open([filename, ".xml"], encoding: "utf-8") do |f|
31
+ f.write file
32
+ f.path
33
+ end
24
34
  FileUtils.rm_rf dir
25
- ::Metanorma::Output::XslfoPdf.new.convert(filename, outname_html + ".pdf", nil)
35
+ ::Metanorma::Output::XslfoPdf.new.convert(input_filename,
36
+ output_filename || "#{filename}.#{@suffix}",
37
+ File.join(@libdir, pdf_stylesheet(docxml)))
26
38
  end
27
39
 
28
40
  def xref_parse(node, out)
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe IsoDoc do
4
+ it "generates file based on string input" do
5
+ FileUtils.rm_f "test.presentation.xml"
6
+ IsoDoc::PresentationXMLConvert.new({filename: "test"}).convert("test", <<~"INPUT", false)
7
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
8
+ <bibdata>
9
+ <title language="en">test</title>
10
+ </bibdata>
11
+ <preface><foreword>
12
+ <note>
13
+ <p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">These results are based on a study carried out on three different types of kernel.</p>
14
+ </note>
15
+ </foreword></preface>
16
+ </iso-standard>
17
+ INPUT
18
+ expect(File.exist?("test.presentation.xml")).to be true
19
+ end
20
+ end
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: 1.0.29
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-19 00:00:00.000000000 Z
11
+ date: 2020-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 1.0.0
145
+ version: 1.1.0
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 1.0.0
152
+ version: 1.1.0
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rake
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -333,11 +333,6 @@ files:
333
333
  - lib/isodoc/function/terms.rb
334
334
  - lib/isodoc/function/to_word_html.rb
335
335
  - lib/isodoc/function/utils.rb
336
- - lib/isodoc/function/xref_anchor.rb
337
- - lib/isodoc/function/xref_counter.rb
338
- - lib/isodoc/function/xref_gen.rb
339
- - lib/isodoc/function/xref_gen_seq.rb
340
- - lib/isodoc/function/xref_sect_gen.rb
341
336
  - lib/isodoc/headlesshtml_convert.rb
342
337
  - lib/isodoc/html_convert.rb
343
338
  - lib/isodoc/html_function.rb
@@ -348,6 +343,7 @@ files:
348
343
  - lib/isodoc/metadata.rb
349
344
  - lib/isodoc/metadata_date.rb
350
345
  - lib/isodoc/pdf_convert.rb
346
+ - lib/isodoc/presentation_xml_convert.rb
351
347
  - lib/isodoc/version.rb
352
348
  - lib/isodoc/word_convert.rb
353
349
  - lib/isodoc/word_function.rb
@@ -358,6 +354,12 @@ files:
358
354
  - lib/isodoc/word_function/postprocess.rb
359
355
  - lib/isodoc/word_function/postprocess_cover.rb
360
356
  - lib/isodoc/word_function/table.rb
357
+ - lib/isodoc/xref.rb
358
+ - lib/isodoc/xref/xref_anchor.rb
359
+ - lib/isodoc/xref/xref_counter.rb
360
+ - lib/isodoc/xref/xref_gen.rb
361
+ - lib/isodoc/xref/xref_gen_seq.rb
362
+ - lib/isodoc/xref/xref_sect_gen.rb
361
363
  - lib/isodoc/xslfo_convert.rb
362
364
  - spec/assets/header.html
363
365
  - spec/assets/html.css
@@ -383,6 +385,7 @@ files:
383
385
  - spec/isodoc/lists_spec.rb
384
386
  - spec/isodoc/metadata_spec.rb
385
387
  - spec/isodoc/postproc_spec.rb
388
+ - spec/isodoc/presentation_xml_spec.rb
386
389
  - spec/isodoc/ref_spec.rb
387
390
  - spec/isodoc/section_spec.rb
388
391
  - spec/isodoc/table_spec.rb
@@ -393,7 +396,7 @@ homepage: https://github.com/metanorma/isodoc
393
396
  licenses:
394
397
  - BSD-2-Clause
395
398
  metadata: {}
396
- post_install_message:
399
+ post_install_message:
397
400
  rdoc_options: []
398
401
  require_paths:
399
402
  - lib
@@ -408,9 +411,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
408
411
  - !ruby/object:Gem::Version
409
412
  version: '0'
410
413
  requirements: []
411
- rubyforge_project:
412
- rubygems_version: 2.7.6
413
- signing_key:
414
+ rubygems_version: 3.0.3
415
+ signing_key:
414
416
  specification_version: 4
415
417
  summary: Convert documents in IsoDoc into Word and HTML in AsciiDoc.
416
418
  test_files: []
@@ -1,84 +0,0 @@
1
- require "roman-numerals"
2
-
3
- module IsoDoc::Function
4
- module XrefGen
5
- def hiersep
6
- "."
7
- end
8
-
9
- def hierfigsep
10
- "-"
11
- end
12
-
13
- class Counter
14
- def initialize
15
- @num = 0
16
- @letter = ""
17
- @subseq = ""
18
- @letter_override = nil
19
- @number_override = nil
20
- end
21
-
22
- def new_subseq_increment(node)
23
- @subseq = node["subsequence"]
24
- @num += 1
25
- @letter = node["subsequence"] ? "a" : ""
26
- if node["number"]
27
- /^(?<n>\d*)(?<a>[a-z]*)$/ =~ node["number"]
28
- if n || a
29
- @letter_override = @letter = a if a
30
- @number_override = @num = n.to_i if n
31
- else
32
- @letter_override = node["number"]
33
- @letter = @letter_override if /^[a-z]$/.match(@letter_override)
34
- end
35
- end
36
- end
37
-
38
- def sequence_increment(node)
39
- if node["number"]
40
- @number_override = node["number"]
41
- @num = @number_override.to_i if /^\d+$/.match(@number_override)
42
- else
43
- @num += 1
44
- end
45
- end
46
-
47
- def subsequence_increment(node)
48
- if node["number"]
49
- @letter_override = node["number"]
50
- @letter = @letter_override if /^[a-z]$/.match(@letter_override)
51
- else
52
- @letter = (@letter.ord + 1).chr.to_s
53
- end
54
- end
55
-
56
- def increment(node)
57
- return self if node["unnumbered"]
58
- @letter_override = nil
59
- @number_override = nil
60
- if node["subsequence"] != @subseq
61
- new_subseq_increment(node)
62
- elsif @letter.empty?
63
- sequence_increment(node)
64
- else
65
- subsequence_increment(node)
66
- end
67
- self
68
- end
69
-
70
- def print
71
- "#{@number_override || @num}#{@letter_override || @letter}"
72
- end
73
-
74
- def listlabel(depth)
75
- return @num.to_s if [2, 7].include? depth
76
- return (96 + @num).chr.to_s if [1, 6].include? depth
77
- return (64 + @num).chr.to_s if [4, 9].include? depth
78
- return RomanNumerals.to_roman(@num).downcase if [3, 8].include? depth
79
- return RomanNumerals.to_roman(@num).upcase if [5, 10].include? depth
80
- return @num.to_s
81
- end
82
- end
83
- end
84
- end