isodoc 1.1.3.pre.alpha2 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/isodoc.gemspec +1 -1
  3. data/lib/isodoc-yaml/i18n-en.yaml +4 -1
  4. data/lib/isodoc-yaml/i18n-fr.yaml +4 -1
  5. data/lib/isodoc-yaml/i18n-zh-Hans.yaml +4 -1
  6. data/lib/isodoc.rb +1 -0
  7. data/lib/isodoc/common.rb +0 -2
  8. data/lib/isodoc/convert.rb +49 -44
  9. data/lib/isodoc/function/blocks.rb +10 -22
  10. data/lib/isodoc/function/blocks_example_note.rb +14 -15
  11. data/lib/isodoc/function/cleanup.rb +5 -4
  12. data/lib/isodoc/function/inline.rb +6 -76
  13. data/lib/isodoc/function/references.rb +10 -9
  14. data/lib/isodoc/function/reqt.rb +12 -11
  15. data/lib/isodoc/function/section.rb +39 -54
  16. data/lib/isodoc/function/table.rb +1 -6
  17. data/lib/isodoc/function/terms.rb +13 -6
  18. data/lib/isodoc/function/to_word_html.rb +1 -0
  19. data/lib/isodoc/function/utils.rb +5 -4
  20. data/lib/isodoc/gem_tasks.rb +18 -2
  21. data/lib/isodoc/html_function/html.rb +0 -1
  22. data/lib/isodoc/{function/i18n.rb → i18n.rb} +37 -36
  23. data/lib/isodoc/metadata.rb +4 -3
  24. data/lib/isodoc/metadata_date.rb +1 -1
  25. data/lib/isodoc/presentation_function/block.rb +138 -0
  26. data/lib/isodoc/presentation_function/inline.rb +131 -0
  27. data/lib/isodoc/presentation_function/section.rb +46 -0
  28. data/lib/isodoc/presentation_xml_convert.rb +38 -5
  29. data/lib/isodoc/version.rb +1 -1
  30. data/lib/isodoc/word_function/body.rb +12 -8
  31. data/lib/isodoc/word_function/inline.rb +3 -1
  32. data/lib/isodoc/xref.rb +5 -3
  33. data/lib/isodoc/xref/xref_sect_gen.rb +3 -3
  34. data/spec/assets/i18n.yaml +12 -1
  35. data/spec/isodoc/blocks_spec.rb +1101 -147
  36. data/spec/isodoc/cleanup_spec.rb +2 -2
  37. data/spec/isodoc/footnotes_spec.rb +2 -2
  38. data/spec/isodoc/i18n_spec.rb +679 -110
  39. data/spec/isodoc/inline_spec.rb +323 -142
  40. data/spec/isodoc/lists_spec.rb +2 -2
  41. data/spec/isodoc/postproc_spec.rb +1311 -1333
  42. data/spec/isodoc/ref_spec.rb +181 -3
  43. data/spec/isodoc/section_spec.rb +508 -680
  44. data/spec/isodoc/table_spec.rb +155 -4
  45. data/spec/isodoc/terms_spec.rb +111 -79
  46. data/spec/isodoc/xref_spec.rb +1569 -1186
  47. metadata +11 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 595f696067ee780226eb9e657df1786a99e805f58516f43c9c0fcfd0feed5579
4
- data.tar.gz: be599ec59b45ffabff696d03eb331613bd08e759ae645d9734af7bae7691095c
3
+ metadata.gz: 41a0527fbc7f1b53775ff475d0306709ad4ffb42d5aa17ab1907124684d6a891
4
+ data.tar.gz: ea38f9755d51aef103ca9d63f496a5a12d89211be9e3bd0c48bb5a21409318ca
5
5
  SHA512:
6
- metadata.gz: 319902ca73d2ad35626d5cad95dee5504e0cd4eeedd759fcf1c64e4739ab749597e7397712e868b262628c902a683d060454fe22e0944c46f9e36497643dbf15
7
- data.tar.gz: f14346e3eb2d380e4228ea1beed7e3e08767abf715e08e14165559c84254376446897c91e8d203bd3a1e7422a548575f2e5f16ed604617581b78fd493c9cf640
6
+ metadata.gz: c54dd45f7dac502a8cb36dcf5cd6c6ec19b7accf8a03d12b7e393d5d284cbc6ed055c4f024a8b643b56fc3fe9c0344b007a491de98dfdc93eb28cc74f7079f35
7
+ data.tar.gz: c626b8d0a3f08e48d62a082d0f0a33037b06918d3b1d767a8777ec2da04c507a9e16d1ee79827c9911eb8d4242c449fa46cbe1c4fc4ac387fefa1f5a363303fd
@@ -37,8 +37,8 @@ Gem::Specification.new do |spec|
37
37
  spec.add_dependency "liquid"
38
38
  spec.add_dependency "roman-numerals"
39
39
  spec.add_dependency "metanorma", "~> 1.1.0"
40
- spec.add_dependency "rake", "~> 12.0"
41
40
 
41
+ spec.add_development_dependency "rake", "~> 13.0"
42
42
  spec.add_development_dependency "byebug", "~> 9.1"
43
43
  spec.add_development_dependency "sassc", "~> 2.4.0"
44
44
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
@@ -1,10 +1,13 @@
1
1
  term_def_boilerplate:
2
2
  scope: Scope
3
- symbols: Symbols and abbreviated terms
3
+ symbolsabbrev: Symbols and abbreviated terms
4
+ abbrev: Abbreviated terms
5
+ symbols: Symbols
4
6
  table_of_contents: Table of contents
5
7
  introduction: Introduction
6
8
  foreword: Foreword
7
9
  abstract: Abstract
10
+ acknowledgements: Acknowledgements
8
11
  termsdef: Terms and definitions
9
12
  termsdefsymbolsabbrev: Terms, definitions, symbols and abbreviated terms
10
13
  termsdefsymbols: Terms, definitions and symbols
@@ -1,10 +1,13 @@
1
1
  term_def_boilerplate:
2
2
  scope: Domaine d'application
3
- symbols: Symboles et termes abrégés
3
+ symbolabbrev: Symboles et termes abrégés
4
+ abbrev: Termes abrégés
5
+ symbols: Symboles
4
6
  table_of_contents: Sommaire
5
7
  introduction: Introduction
6
8
  foreword: Avant-propos
7
9
  abstract: Résumé
10
+ acknowledgements: Remerciements
8
11
  termsdef: Terms et définitions
9
12
  termsdefsymbolsabbrev: Terms, définitions, symboles et termes abrégés
10
13
  termsdefsymbols: Terms, définitions et symboles
@@ -1,10 +1,13 @@
1
1
  term_def_boilerplate:
2
2
  scope: 范围
3
- symbols: 符号、代号和缩略语
3
+ symbolsabbrev: 符号、代号和缩略语
4
+ abbrev: 代号和缩略语
5
+ symbols: 符号
4
6
  table_of_contents: 目次
5
7
  introduction: 引言
6
8
  foreword: 前言
7
9
  abstract: 摘要
10
+ acknowledgements: 致謝
8
11
  termsdef: 术语和定义
9
12
  termsdefsymbolsabbrev: 术语、定义、符号、代号和缩略语
10
13
  termsdefsymbols: 术语、定义、符号和代号
@@ -23,6 +23,7 @@ require "isodoc/xslfo_convert"
23
23
  require "isodoc/headlesshtml_convert"
24
24
  require "isodoc/presentation_xml_convert"
25
25
  require "isodoc/xref"
26
+ require "isodoc/i18n"
26
27
 
27
28
  module IsoDoc
28
29
 
@@ -1,6 +1,5 @@
1
1
  require_relative "./function/blocks"
2
2
  require_relative "./function/cleanup"
3
- require_relative "./function/i18n"
4
3
  require_relative "./function/inline"
5
4
  require_relative "./function/lists"
6
5
  require_relative "./function/references"
@@ -16,7 +15,6 @@ module IsoDoc
16
15
  class Common
17
16
  include Function::Blocks
18
17
  include Function::Cleanup
19
- include Function::I18n
20
18
  include Function::Inline
21
19
  include Function::Lists
22
20
  include Function::References
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
-
3
- require 'isodoc/common'
4
- require 'fileutils'
5
- require 'tempfile'
2
+ require "isodoc/common"
3
+ require "fileutils"
4
+ require "tempfile"
5
+ require_relative "i18n"
6
6
 
7
7
  module IsoDoc
8
8
  class Convert < ::IsoDoc::Common
9
9
  attr_reader :options
10
- attr_accessor :labels
10
+ attr_accessor :i18n
11
11
 
12
12
  # htmlstylesheet: Generic stylesheet for HTML
13
13
  # wordstylesheet: Generic stylesheet for Word
@@ -38,15 +38,9 @@ module IsoDoc
38
38
  @options = options
39
39
  @files_to_delete = []
40
40
  @tempfile_cache = []
41
- @htmlstylesheet_name = precompiled_style_or_original(
42
- options[:htmlstylesheet]
43
- )
44
- @wordstylesheet_name = precompiled_style_or_original(
45
- options[:wordstylesheet]
46
- )
47
- @standardstylesheet_name = precompiled_style_or_original(
48
- options[:standardstylesheet]
49
- )
41
+ @htmlstylesheet_name = options[:htmlstylesheet]
42
+ @wordstylesheet_name = options[:wordstylesheet]
43
+ @standardstylesheet_name = options[:standardstylesheet]
50
44
  @header = options[:header]
51
45
  @htmlcoverpage = options[:htmlcoverpage]
52
46
  @wordcoverpage = options[:wordcoverpage]
@@ -72,10 +66,10 @@ module IsoDoc
72
66
  @in_figure = false
73
67
  @seen_footnote = Set.new
74
68
  @c = HTMLEntities.new
75
- @openmathdelim = '`'
76
- @closemathdelim = '`'
77
- @lang = 'en'
78
- @script = 'Latn'
69
+ @openmathdelim = "`"
70
+ @closemathdelim = "`"
71
+ @lang = options[:language] || "en"
72
+ @script = options[:script] || "Latn"
79
73
  @maxwidth = 1200
80
74
  @maxheight = 800
81
75
  @wordToClevels = options[:doctoclevels].to_i
@@ -121,8 +115,8 @@ module IsoDoc
121
115
  }
122
116
  end
123
117
 
124
- # none for this parent gem, but will be populated in child
125
- # gems which have access to stylesheets &c; e.g.
118
+ # none for this parent gem, but will be populated in child gems
119
+ # which have access to stylesheets &c; e.g.
126
120
  # {
127
121
  # htmlstylesheet: html_doc_path("htmlstyle.scss"),
128
122
  # htmlcoverpage: html_doc_path("html_rsd_titlepage.html"),
@@ -155,8 +149,12 @@ module IsoDoc
155
149
  "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
156
150
  end
157
151
 
158
- def html_doc_path(file)
159
- File.join(@libdir, File.join('html', file))
152
+ def html_doc_path(*file)
153
+ file.each do |f|
154
+ ret = File.join(@libdir, File.join('html', f))
155
+ File.exist?(ret) and return ret
156
+ end
157
+ nil
160
158
  end
161
159
 
162
160
  def convert_scss(filename, stylesheet)
@@ -165,17 +163,18 @@ module IsoDoc
165
163
 
166
164
  [File.join(Gem.loaded_specs['isodoc'].full_gem_path,
167
165
  'lib', 'isodoc'),
168
- File.dirname(filename)].each do |name|
169
- SassC.load_paths << name
170
- end
171
- SassC::Engine.new(scss_fontheader + stylesheet, syntax: :scss,
172
- importer: SasscImporter)
166
+ File.dirname(filename)].each do |name|
167
+ SassC.load_paths << name
168
+ end
169
+ SassC::Engine.new(scss_fontheader + stylesheet, syntax: :scss,
170
+ importer: SasscImporter)
173
171
  .render
174
172
  end
175
173
 
176
174
  def generate_css(filename, stripwordcss)
177
175
  return nil if filename.nil?
178
176
 
177
+ filename = precompiled_style_or_original(filename)
179
178
  stylesheet = File.read(filename, encoding: 'UTF-8')
180
179
  stylesheet = populate_template(stylesheet, :word)
181
180
  stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m, '\\1') if stripwordcss
@@ -202,32 +201,38 @@ module IsoDoc
202
201
  end.join("\n")
203
202
  end
204
203
 
205
- def metadata_init(lang, script, labels)
206
- @meta = Metadata.new(lang, script, labels)
204
+ def metadata_init(lang, script, i18n)
205
+ @meta = Metadata.new(lang, script, i18n)
206
+ end
207
+
208
+ def xref_init(lang, script, _klass, i18n, options)
209
+ html = HtmlConvert.new(language: @lang, script: @script)
210
+ @xrefs = Xref.new(lang, script, html, i18n, options)
211
+ end
212
+
213
+ def i18n_init(lang, script, i18nyaml = nil)
214
+ @i18n = I18n.new(lang, script, i18nyaml || @i18nyaml)
207
215
  end
208
216
 
209
- def xref_init(lang, script, klass, labels, options)
210
- @xrefs = Xref.new(lang, script, klass, labels, options)
217
+ def l10n(x, lang = @lang, script = @script)
218
+ @i18n.l10n(x, lang, script)
211
219
  end
212
220
 
213
221
  def convert_init(file, input_filename, debug)
214
222
  docxml = Nokogiri::XML(file)
215
223
  filename, dir = init_file(input_filename, debug)
216
- docxml.root.default_namespace = ''
217
- lang = docxml&.at(ns('//bibdata/language'))&.text || @lang
218
- script = docxml&.at(ns('//bibdata/script'))&.text || @script
219
- i18n_init(lang, script)
220
- metadata_init(lang, script, @labels)
221
- @meta.fonts_options = fonts_options
222
- xref_init(lang, script, self, @labels, {})
224
+ docxml.root.default_namespace = ""
225
+ lang = docxml&.at(ns("//bibdata/language"))&.text and @lang = lang
226
+ script = docxml&.at(ns("//bibdata/script"))&.text and @script = script
227
+ i18n_init(@lang, @script)
228
+ metadata_init(@lang, @script, @i18n)
229
+ xref_init(@lang, @script, self, @i18n, {})
223
230
  [docxml, filename, dir]
224
231
  end
225
232
 
226
- def convert(input_filename,
227
- file = nil,
228
- debug = false,
233
+ def convert(input_filename, file = nil, debug = false,
229
234
  output_filename = nil)
230
- file = File.read(input_filename, encoding: 'utf-8') if file.nil?
235
+ file = File.read(input_filename, encoding: "utf-8") if file.nil?
231
236
  @openmathdelim, @closemathdelim = extract_delims(file)
232
237
  docxml, filename, dir = convert_init(file, input_filename, debug)
233
238
  result = convert1(docxml, filename, dir)
@@ -238,8 +243,8 @@ module IsoDoc
238
243
  end
239
244
 
240
245
  def middle_clause
241
- "//clause[parent::sections][not(xmlns:title = 'Scope')]"\
242
- '[not(descendant::terms)]'
246
+ "//clause[parent::sections][not(@type = 'scope')]"\
247
+ '[not(descendant::terms)]'
243
248
  end
244
249
  end
245
250
  end
@@ -5,20 +5,15 @@ module IsoDoc::Function
5
5
  @annotation = false
6
6
 
7
7
  def figure_name_parse(node, div, name)
8
- return if name.nil? && node.at(ns("./figure"))
9
- lbl = @xrefs.anchor(node['id'], :label, false)
10
- lbl = nil if labelled_ancestor(node) && node.ancestors("figure").empty?
11
- return if lbl.nil? && name.nil?
8
+ return if name.nil?
12
9
  div.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
13
- lbl.nil? or p << l10n("#{@figure_lbl} #{lbl}")
14
- name and !lbl.nil? and p << "&nbsp;&mdash; "
15
- name and name.children.each { |n| parse(n, div) }
10
+ name.children.each { |n| parse(n, div) }
16
11
  end
17
12
  end
18
13
 
19
14
  def figure_key(out)
20
15
  out.p **{ style: "page-break-after:avoid;"} do |p|
21
- p.b { |b| b << @key_lbl }
16
+ p.b { |b| b << @i18n.key }
22
17
  end
23
18
  end
24
19
 
@@ -55,15 +50,9 @@ module IsoDoc::Function
55
50
  end
56
51
 
57
52
  def sourcecode_name_parse(node, div, name)
58
- lbl = @xrefs.anchor(node['id'], :label, false)
59
- lbl = nil if labelled_ancestor(node)
60
- return if lbl.nil? && name.nil?
53
+ return if name.nil?
61
54
  div.p **{ class: "SourceTitle", style: "text-align:center;" } do |p|
62
- if node.ancestors("example").empty?
63
- lbl.nil? or p << l10n("#{@figure_lbl} #{lbl}")
64
- name and !lbl.nil? and p << "&nbsp;&mdash; "
65
- end
66
- name&.children&.each { |n| parse(n, p) }
55
+ name.children.each { |n| parse(n, p) }
67
56
  end
68
57
  end
69
58
 
@@ -109,8 +98,8 @@ module IsoDoc::Function
109
98
  def admonition_name(node, type)
110
99
  name = node&.at(ns("./name")) and return name
111
100
  name = Nokogiri::XML::Node.new('name', node.document)
112
- return unless type && @admonition[type]
113
- name << @admonition[type]&.upcase
101
+ return unless type && @i18n.admonition[type]
102
+ name << @i18n.admonition[type]&.upcase
114
103
  name
115
104
  end
116
105
 
@@ -131,7 +120,7 @@ module IsoDoc::Function
131
120
  def formula_where(dl, out)
132
121
  return unless dl
133
122
  out.p **{ style: "page-break-after:avoid;"} do |p|
134
- p << @where_lbl
123
+ p << @i18n.where
135
124
  end
136
125
  parse(dl, out)
137
126
  out.parent.at("./dl")["class"] = "formula_dl"
@@ -141,8 +130,7 @@ module IsoDoc::Function
141
130
  out.div **attr_code(class: "formula") do |div|
142
131
  div.p do |p|
143
132
  parse(node.at(ns("./stem")), div)
144
- lbl = @xrefs.anchor(node['id'], :label, false)
145
- unless lbl.nil?
133
+ if lbl = node&.at(ns("./name"))&.text
146
134
  insert_tab(div, 1)
147
135
  div << "(#{lbl})"
148
136
  end
@@ -159,7 +147,7 @@ module IsoDoc::Function
159
147
  formula_parse1(node, div)
160
148
  formula_where(node.at(ns("./dl")), div)
161
149
  node.children.each do |n|
162
- next if %w(stem dl).include? n.name
150
+ next if %w(stem dl name).include? n.name
163
151
  parse(n, div)
164
152
  end
165
153
  end
@@ -1,13 +1,9 @@
1
1
  module IsoDoc::Function
2
2
  module Blocks
3
3
  def example_label(node, div, name)
4
- n = @xrefs.get[node["id"]]
4
+ return if name.nil?
5
5
  div.p **{ class: "example-title" } do |p|
6
- lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @example_lbl :
7
- l10n("#{@example_lbl} #{n[:label]}")
8
- p << lbl
9
- name and !lbl.nil? and p << "&nbsp;&mdash; "
10
- name and name.children.each { |n| parse(n, div) }
6
+ name.children.each { |n| parse(n, div) }
11
7
  end
12
8
  end
13
9
 
@@ -55,16 +51,16 @@ module IsoDoc::Function
55
51
  example_div_parse(node, out)
56
52
  end
57
53
 
58
- def note_label(node)
59
- n = @xrefs.get[node["id"]]
60
- return @note_lbl if n.nil? || n[:label].nil? || n[:label].empty?
61
- l10n("#{@note_lbl} #{n[:label]}")
54
+ def note_delim
55
+ ""
62
56
  end
63
57
 
64
58
  def note_p_parse(node, div)
59
+ name = node&.at(ns("./name"))&.remove
65
60
  div.p do |p|
66
- p.span **{ class: "note_label" } do |s|
67
- s << note_label(node)
61
+ name and p.span **{ class: "note_label" } do |s|
62
+ name and name.children.each { |n| parse(n, s) }
63
+ s << note_delim
68
64
  end
69
65
  insert_tab(p, 1)
70
66
  node.first_element_child.children.each { |n| parse(n, p) }
@@ -73,9 +69,11 @@ module IsoDoc::Function
73
69
  end
74
70
 
75
71
  def note_parse1(node, div)
76
- div.p do |p|
72
+ name = node&.at(ns("./name"))&.remove
73
+ name and div.p do |p|
77
74
  p.span **{ class: "note_label" } do |s|
78
- s << note_label(node)
75
+ name.children.each { |n| parse(n, s) }
76
+ s << note_delim
79
77
  end
80
78
  insert_tab(p, 1)
81
79
  end
@@ -99,7 +97,8 @@ module IsoDoc::Function
99
97
  def note_parse(node, out)
100
98
  @note = true
101
99
  out.div **note_attrs(node) do |div|
102
- node.first_element_child.name == "p" ?
100
+ node&.at(ns("./*[local-name() != 'name'][1]"))&.name == "p" ?
101
+ #node.first_element_child.name == "p" ?
103
102
  note_p_parse(node, div) : note_parse1(node, div)
104
103
  end
105
104
  @note = false
@@ -7,10 +7,10 @@ module IsoDoc::Function
7
7
  def termref_cleanup(docxml)
8
8
  docxml.
9
9
  gsub(%r{\s*\[/TERMREF\]\s*</p>\s*<p>\s*\[TERMREF\]}, "; ").
10
- gsub(/\[TERMREF\]\s*/, l10n("[#{@source_lbl}: ")).
11
- gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/, l10n(", #{@modified_lbl} [/TERMREF]")).
10
+ gsub(/\[TERMREF\]\s*/, l10n("[#{@i18n.source}: ")).
11
+ gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/, l10n(", #{@i18n.modified} [/TERMREF]")).
12
12
  gsub(%r{\s*\[\/TERMREF\]\s*}, l10n("]")).
13
- gsub(/\s*\[MODIFICATION\]/, l10n(", #{@modified_lbl} &mdash; "))
13
+ gsub(/\s*\[MODIFICATION\]/, l10n(", #{@i18n.modified} &mdash; "))
14
14
  end
15
15
 
16
16
  def passthrough_cleanup(docxml)
@@ -21,6 +21,7 @@ module IsoDoc::Function
21
21
  end
22
22
 
23
23
  def cleanup(docxml)
24
+ @i18n ||= i18n_init(@lang, @script)
24
25
  comment_cleanup(docxml)
25
26
  footnote_cleanup(docxml)
26
27
  inline_header_cleanup(docxml)
@@ -80,7 +81,7 @@ module IsoDoc::Function
80
81
  def figure_get_or_make_dl(t)
81
82
  dl = t.at(".//dl")
82
83
  if dl.nil?
83
- t.add_child("<p><b>#{@key_lbl}</b></p><dl></dl>")
84
+ t.add_child("<p><b>#{@i18n.key}</b></p><dl></dl>")
84
85
  dl = t.at(".//dl")
85
86
  end
86
87
  dl
@@ -16,85 +16,16 @@ module IsoDoc::Function
16
16
  out << " &lt;#{node.text}&gt;"
17
17
  end
18
18
 
19
- def prefix_container(container, linkend, _target)
20
- l10n(@xrefs.anchor(container, :xref) + ", " + linkend)
21
- end
22
-
23
- def anchor_linkend(node, linkend)
24
- if node["citeas"].nil? && node["bibitemid"]
25
- return @xrefs.anchor(node["bibitemid"] ,:xref) || "???"
26
- elsif node["target"] && !/.#./.match(node["target"])
27
- linkend = @xrefs.anchor(node["target"], :xref)
28
- container = @xrefs.anchor(node["target"], :container, false)
29
- (container && get_note_container_id(node) != container &&
30
- @xrefs.get[node["target"]]) &&
31
- linkend = prefix_container(container, linkend, node["target"])
32
- linkend = capitalise_xref(node, linkend)
19
+ def no_locality_parse(node, out)
20
+ node.children.each do |n|
21
+ parse(n, out) unless %w{locality localityStack}.include? n.name
33
22
  end
34
- linkend || "???"
35
- end
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
-
56
- def get_linkend(node)
57
- contents = node.children.select do |c|
58
- !%w{locality localityStack}.include? c.name
59
- end.select { |c| !c.text? || /\S/.match(c) }
60
- !contents.empty? and
61
- return Nokogiri::XML::NodeSet.new(node.document, contents).to_xml
62
- link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))
63
- link + eref_localities(node.xpath(ns("./locality | ./localityStack")),
64
- link)
65
- # so not <origin bibitemid="ISO7301" citeas="ISO 7301">
66
- # <locality type="section"><reference>3.1</reference></locality></origin>
67
23
  end
68
24
 
69
25
  def xref_parse(node, out)
70
26
  target = /#/.match(node["target"]) ? node["target"].sub(/#/, ".html#") :
71
27
  "##{node["target"]}"
72
- out.a(**{ "href": target }) { |l| l << get_linkend(node) }
73
- end
74
-
75
- def eref_localities(refs, target)
76
- ret = ""
77
- refs.each_with_index do |r, i|
78
- delim = ","
79
- delim = ";" if r.name == "localityStack" && i>0
80
- if r.name == "localityStack"
81
- r.elements.each_with_index do |rr, j|
82
- ret += eref_localities0(rr, j, target, delim)
83
- delim = ","
84
- end
85
- else
86
- ret += eref_localities0(r, i, target, delim)
87
- end
88
- end
89
- ret
90
- end
91
-
92
- def eref_localities0(r, i, target, delim)
93
- if r["type"] == "whole" then l10n("#{delim} #{@wholeoftext_lbl}")
94
- else
95
- eref_localities1(target, r["type"], r.at(ns("./referenceFrom")),
96
- r.at(ns("./referenceTo")), delim, @lang)
97
- end
28
+ out.a(**{ "href": target }) { |l| no_locality_parse(node, l) }
98
29
  end
99
30
 
100
31
  def suffix_url(url)
@@ -114,14 +45,13 @@ module IsoDoc::Function
114
45
  end
115
46
 
116
47
  def eref_parse(node, out)
117
- linkend = get_linkend(node)
118
48
  href = eref_target(node)
119
49
  if node["type"] == "footnote"
120
50
  out.sup do |s|
121
- s.a(**{ "href": href }) { |l| l << linkend }
51
+ s.a(**{ "href": href }) { |l| no_locality_parse(node, l) }
122
52
  end
123
53
  else
124
- out.a(**{ "href": href }) { |l| l << linkend }
54
+ out.a(**{ "href": href }) { |l| no_locality_parse(node, l) }
125
55
  end
126
56
  end
127
57