isodoc 1.6.3 → 1.6.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +2 -12
  3. data/.hound.yml +3 -1
  4. data/.rubocop.yml +4 -6
  5. data/isodoc.gemspec +3 -2
  6. data/lib/isodoc-yaml/i18n-en.yaml +1 -0
  7. data/lib/isodoc-yaml/i18n-fr.yaml +1 -0
  8. data/lib/isodoc-yaml/i18n-zh-Hans.yaml +1 -0
  9. data/lib/isodoc.rb +0 -2
  10. data/lib/isodoc/convert.rb +7 -1
  11. data/lib/isodoc/function/blocks.rb +5 -4
  12. data/lib/isodoc/function/cleanup.rb +52 -43
  13. data/lib/isodoc/function/inline.rb +7 -7
  14. data/lib/isodoc/function/references.rb +33 -52
  15. data/lib/isodoc/function/section.rb +28 -16
  16. data/lib/isodoc/function/table.rb +21 -22
  17. data/lib/isodoc/function/terms.rb +6 -7
  18. data/lib/isodoc/function/to_word_html.rb +6 -3
  19. data/lib/isodoc/function/utils.rb +181 -163
  20. data/lib/isodoc/gem_tasks.rb +8 -9
  21. data/lib/isodoc/headlesshtml_convert.rb +8 -7
  22. data/lib/isodoc/html_convert.rb +5 -1
  23. data/lib/isodoc/html_function/comments.rb +14 -12
  24. data/lib/isodoc/html_function/footnotes.rb +14 -7
  25. data/lib/isodoc/html_function/html.rb +30 -26
  26. data/lib/isodoc/html_function/postprocess.rb +191 -182
  27. data/lib/isodoc/html_function/sectionsplit.rb +230 -0
  28. data/lib/isodoc/metadata.rb +22 -20
  29. data/lib/isodoc/metadata_contributor.rb +31 -28
  30. data/lib/isodoc/pdf_convert.rb +11 -13
  31. data/lib/isodoc/presentation_function/bibdata.rb +50 -22
  32. data/lib/isodoc/presentation_function/inline.rb +20 -15
  33. data/lib/isodoc/presentation_function/section.rb +38 -1
  34. data/lib/isodoc/presentation_xml_convert.rb +2 -0
  35. data/lib/isodoc/version.rb +1 -1
  36. data/lib/isodoc/word_function/postprocess.rb +50 -36
  37. data/lib/isodoc/xref.rb +2 -0
  38. data/lib/isodoc/xref/xref_gen_seq.rb +60 -35
  39. data/lib/isodoc/xref/xref_sect_gen.rb +4 -4
  40. data/spec/assets/scripts_override.html +3 -0
  41. data/spec/isodoc/blocks_spec.rb +373 -685
  42. data/spec/isodoc/cleanup_spec.rb +40 -42
  43. data/spec/isodoc/i18n_spec.rb +694 -821
  44. data/spec/isodoc/inline_spec.rb +482 -328
  45. data/spec/isodoc/metadata_spec.rb +384 -379
  46. data/spec/isodoc/postproc_spec.rb +163 -55
  47. data/spec/isodoc/presentation_xml_spec.rb +355 -278
  48. data/spec/isodoc/ref_spec.rb +5 -5
  49. data/spec/isodoc/section_spec.rb +216 -199
  50. data/spec/isodoc/sectionsplit_spec.rb +190 -0
  51. data/spec/isodoc/table_spec.rb +41 -42
  52. data/spec/isodoc/terms_spec.rb +84 -84
  53. data/spec/isodoc/xref_spec.rb +974 -932
  54. metadata +22 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9d5c91b697c02cdac2a8221f2995d29f812804b48039967bd94c8aef7ce10c0
4
- data.tar.gz: cf66a1f8d4eb41297360341e0da8d16a9ddf0af2679f072d758a259186a291bd
3
+ metadata.gz: 17e14b978b65a7667074ab1dff17bd5dc76a58e6baf7ace593407dc921ddf558
4
+ data.tar.gz: 3622549bc44570ec6e8de62fb55a62af937e32306ccc444bfaf0a1063caae511
5
5
  SHA512:
6
- metadata.gz: 4cfa5637d6c22e73dd2a6c5bc32841183691a5db4121102787fad3caddd61815541e7128b624f03d20bf00d1e94fed81e43aaa19d1b84260e7bde5cfc69d924e
7
- data.tar.gz: 7015f57396172858edb4b8499e6c4706894ef540f6b96c95d5c9bf445580003a8e68d4930204e5731ec57dafa460c2cfbcf4da5572e82713070fd214bef5974e
6
+ metadata.gz: 2cffca2a878c9bc3e05d26b85edb21be9ff27a75b8fd6e9ab7b31cdb861915b41baeb9e4b4027fb5f8f5e751879143dd55ea7cc35d46d6feb507d2a83632ff2b
7
+ data.tar.gz: 5146c2a8457a5f41232b6176acb3bf5fd77bfb75941b9030f6c015463cfe7646e6a3df153423229a3c9a17e0aa6c02529062bffdd1e98ad116fb91f1d61f6306
@@ -16,19 +16,9 @@ jobs:
16
16
  strategy:
17
17
  fail-fast: false
18
18
  matrix:
19
- ruby: [ '2.7', '2.6', '2.5', '2.4' ]
19
+ ruby: [ '3.0', '2.7', '2.6', '2.5' ]
20
20
  os: [ ubuntu-latest, windows-latest, macos-latest ]
21
21
  experimental: [ false ]
22
- include:
23
- - ruby: '3.0'
24
- os: 'ubuntu-latest'
25
- experimental: true
26
- - ruby: '3.0'
27
- os: 'windows-latest'
28
- experimental: true
29
- - ruby: '3.0'
30
- os: 'macos-latest'
31
- experimental: true
32
22
  steps:
33
23
  - uses: actions/checkout@master
34
24
 
@@ -49,5 +39,5 @@ jobs:
49
39
  with:
50
40
  token: ${{ secrets.METANORMA_CI_PAT_TOKEN || secrets.GITHUB_TOKEN }}
51
41
  repository: ${{ github.repository }}
52
- event-type: notify
42
+ event-type: tests-passed
53
43
  client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
data/.hound.yml CHANGED
@@ -1,3 +1,5 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
1
3
  ruby:
2
- Enabled: true
4
+ enabled: true
3
5
  config_file: .rubocop.yml
data/.rubocop.yml CHANGED
@@ -1,12 +1,10 @@
1
- # This project follows the Ribose OSS style guide.
2
- # https://github.com/riboseinc/oss-guides
3
- # All project-specific additions and overrides should be specified in this file.
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
4
3
  inherit_from:
5
4
  - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
6
5
 
7
6
  # local repo-specific modifications
7
+ # ...
8
8
 
9
9
  AllCops:
10
- DisplayCopNames: false
11
- StyleGuideCopsOnly: false
12
- TargetRubyVersion: 2.4
10
+ TargetRubyVersion: 2.5
data/isodoc.gemspec CHANGED
@@ -26,14 +26,14 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ["lib"]
27
27
  spec.files = `git ls-files`.split("\n")
28
28
  spec.test_files = `git ls-files -- {spec}/*`.split("\n")
29
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
29
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
30
30
 
31
31
  spec.add_dependency "asciimath"
32
32
  spec.add_dependency "html2doc", "~> 1.1.1"
33
33
  spec.add_dependency "htmlentities", "~> 4.3.4"
34
34
  spec.add_dependency "liquid", "~> 4"
35
35
  spec.add_dependency "metanorma", ">= 1.2.0"
36
- spec.add_dependency "nokogiri", "~> 1.10.4"
36
+ spec.add_dependency "nokogiri", "~> 1.11.0"
37
37
  spec.add_dependency "relaton-cli"
38
38
  spec.add_dependency "roman-numerals"
39
39
  spec.add_dependency "thread_safe"
@@ -50,5 +50,6 @@ Gem::Specification.new do |spec|
50
50
  spec.add_development_dependency "rubocop", "~> 1.5.2"
51
51
  spec.add_development_dependency "sassc", "~> 2.4.0"
52
52
  spec.add_development_dependency "simplecov", "~> 0.15"
53
+ spec.add_development_dependency "metanorma-iso"
53
54
  spec.add_development_dependency "timecop", "~> 0.9"
54
55
  end
@@ -14,6 +14,7 @@ termsdefsymbols: Terms, definitions and symbols
14
14
  termsdefabbrev: Terms, definitions and abbreviated terms
15
15
  normref: Normative references
16
16
  bibliography: Bibliography
17
+ preface: Preface
17
18
  clause: Clause
18
19
  annex: Annex
19
20
  appendix: Appendix
@@ -14,6 +14,7 @@ termsdefsymbols: Terms, définitions et symboles
14
14
  termsdefabbrev: Terms, définitions et termes abrégés
15
15
  normref: Références normatives
16
16
  bibliography: Bibliographie
17
+ preface: Préface
17
18
  clause: Article
18
19
  annex: Annexe
19
20
  appendix: Appendice
@@ -14,6 +14,7 @@ termsdefsymbols: 术语、定义、符号和代号
14
14
  termsdefabbrev: 术语、定义、符号和缩略语
15
15
  normref: 规范性引用文件
16
16
  bibliography: 参考文献
17
+ preface: 序言
17
18
  clause: 条
18
19
  annex: 附件
19
20
  appendix: 附录
data/lib/isodoc.rb CHANGED
@@ -8,7 +8,6 @@ require "mime/types"
8
8
  require "image_size"
9
9
  require "set"
10
10
  require "pp"
11
- require "uuidtools"
12
11
  require "html2doc"
13
12
  require "liquid"
14
13
  require "htmlentities"
@@ -26,5 +25,4 @@ require "isodoc/xref"
26
25
  require "isodoc/i18n"
27
26
 
28
27
  module IsoDoc
29
-
30
28
  end
@@ -32,10 +32,13 @@ module IsoDoc
32
32
  # monospace: font to use for monospace text
33
33
  # suppressheadingnumbers: suppress heading numbers for clauses
34
34
  # scripts: Scripts file for HTML
35
+ # scripts_override: Override scripts file for HTML
35
36
  # scripts_pdf: Scripts file for PDF (not used in XSLT PDF)
36
37
  # datauriimage: Encode images in HTML output as data URIs
37
38
  # break_up_urls_in_tables: whether to insert spaces in URLs in tables
38
39
  # every 40-odd chars
40
+ # sectionsplit: split up HTML output on sections
41
+ # bare: do not insert any prefatory material (coverpage, boilerplate)
39
42
  def initialize(options)
40
43
  @libdir ||= File.dirname(__FILE__) # rubocop:disable Lint/DisjunctiveAssignmentInConstructor
41
44
  options.merge!(default_fonts(options)) do |_, old, new|
@@ -64,12 +67,15 @@ module IsoDoc
64
67
  @scripts = options[:scripts] ||
65
68
  File.join(File.dirname(__FILE__), "base_style", "scripts.html")
66
69
  @scripts_pdf = options[:scripts_pdf]
70
+ @scripts_override = options[:scripts_override]
67
71
  @i18nyaml = options[:i18nyaml]
68
72
  @ulstyle = options[:ulstyle]
69
73
  @olstyle = options[:olstyle]
70
74
  @datauriimage = options[:datauriimage]
71
75
  @suppressheadingnumbers = options[:suppressheadingnumbers]
72
76
  @break_up_urls_in_tables = options[:break_up_urls_in_tables] == "true"
77
+ @sectionsplit = options[:sectionsplit] == "true"
78
+ @bare = options[:bare]
73
79
  @termdomain = ""
74
80
  @termexample = false
75
81
  @note = false
@@ -150,7 +156,7 @@ module IsoDoc
150
156
  [docxml, filename, dir]
151
157
  end
152
158
 
153
- def convert(input_filename, file = nil, debug = false,
159
+ def convert(input_filename, file = nil, debug = false,
154
160
  output_filename = nil)
155
161
  file = File.read(input_filename, encoding: "utf-8") if file.nil?
156
162
  @openmathdelim, @closemathdelim = extract_delims(file)
@@ -14,10 +14,11 @@ module IsoDoc::Function
14
14
  end
15
15
  end
16
16
 
17
- def figure_name_parse(node, div, name)
18
- return if name.nil?
17
+ def figure_name_parse(_node, div, name)
18
+ return if name.nil?
19
+
19
20
  div.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
20
- name.children.each { |n| parse(n, div) }
21
+ name.children.each { |n| parse(n, p) }
21
22
  end
22
23
  end
23
24
 
@@ -61,7 +62,7 @@ module IsoDoc::Function
61
62
  end
62
63
 
63
64
  def sourcecode_name_parse(node, div, name)
64
- return if name.nil?
65
+ return if name.nil?
65
66
 
66
67
  div.p **{ class: "SourceTitle", style: "text-align:center;" } do |p|
67
68
  name.children.each { |n| parse(n, p) }
@@ -1,16 +1,17 @@
1
1
  module IsoDoc::Function
2
2
  module Cleanup
3
3
  def textcleanup(docxml)
4
- docxml = termref_cleanup(passthrough_cleanup(docxml))
4
+ termref_cleanup(passthrough_cleanup(docxml))
5
5
  end
6
6
 
7
7
  def termref_cleanup(docxml)
8
- docxml.
9
- gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/, l10n(", #{@i18n.modified} [/TERMREF]")).
10
- gsub(%r{\s*\[/TERMREF\]\s*</p>\s*<p>\s*\[TERMREF\]}, "; ").
11
- gsub(/\[TERMREF\]\s*/, l10n("[#{@i18n.source}: ")).
12
- gsub(%r{\s*\[\/TERMREF\]\s*}, l10n("]")).
13
- gsub(/\s*\[MODIFICATION\]/, l10n(", #{@i18n.modified} &mdash; "))
8
+ docxml
9
+ .gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/,
10
+ l10n(", #{@i18n.modified} [/TERMREF]"))
11
+ .gsub(%r{\s*\[/TERMREF\]\s*</p>\s*<p>\s*\[TERMREF\]}, "; ")
12
+ .gsub(/\[TERMREF\]\s*/, l10n("[#{@i18n.source}: "))
13
+ .gsub(%r{\s*\[/TERMREF\]\s*}, l10n("]"))
14
+ .gsub(/\s*\[MODIFICATION\]/, l10n(", #{@i18n.modified} &mdash; "))
14
15
  end
15
16
 
16
17
  def passthrough_cleanup(docxml)
@@ -21,7 +22,7 @@ module IsoDoc::Function
21
22
  end
22
23
 
23
24
  def cleanup(docxml)
24
- @i18n ||= i18n_init(@lang, @script)
25
+ @i18n ||= i18n_init(@lang, @script)
25
26
  comment_cleanup(docxml)
26
27
  footnote_cleanup(docxml)
27
28
  inline_header_cleanup(docxml)
@@ -34,30 +35,36 @@ module IsoDoc::Function
34
35
 
35
36
  def table_long_strings_cleanup(docxml)
36
37
  return unless @break_up_urls_in_tables == true
38
+
37
39
  docxml.xpath("//td | //th").each do |d|
38
40
  d.traverse do |n|
39
41
  next unless n.text?
42
+
40
43
  n.replace(HTMLEntities.new.encode(
41
- break_up_long_strings(n.text)))
44
+ break_up_long_strings(n.text),
45
+ ))
42
46
  end
43
47
  end
44
48
  end
45
49
 
46
- def break_up_long_strings(t)
47
- return t if t.match(/^\s*$/)
48
- t.split(/(?=\s)/).map do |w|
49
- (/^\s*$/.match(t) or w.size < 30) ? w :
50
+ def break_up_long_strings(text)
51
+ return text if /^\s*$/.match?(text)
52
+
53
+ text.split(/(?=\s)/).map do |w|
54
+ if /^\s*$/.match(text) || (w.size < 30) then w
55
+ else
50
56
  w.scan(/.{,30}/).map do |w1|
51
- (w1.size < 30) ? w1 : break_up_long_strings1(w1)
52
- end.join
57
+ w1.size < 30 ? w1 : break_up_long_strings1(w1)
58
+ end.join
59
+ end
53
60
  end.join
54
61
  end
55
62
 
56
- def break_up_long_strings1(w1)
57
- s = w1.split(%r{(?<=[,.?+;/=])})
58
- if s.size == 1 then w1 + " "
63
+ def break_up_long_strings1(text)
64
+ s = text.split(%r{(?<=[,.?+;/=])})
65
+ if s.size == 1 then "#{text} "
59
66
  else
60
- s[-1] = " " + s[-1]
67
+ s[-1] = " #{s[-1]}"
61
68
  s.join
62
69
  end
63
70
  end
@@ -78,11 +85,11 @@ module IsoDoc::Function
78
85
  docxml
79
86
  end
80
87
 
81
- def figure_get_or_make_dl(t)
82
- dl = t.at(".//dl")
88
+ def figure_get_or_make_dl(elem)
89
+ dl = elem.at(".//dl")
83
90
  if dl.nil?
84
- t.add_child("<p><b>#{@i18n.key}</b></p><dl></dl>")
85
- dl = t.at(".//dl")
91
+ elem.add_child("<p><b>#{@i18n.key}</b></p><dl></dl>")
92
+ dl = elem.at(".//dl")
86
93
  end
87
94
  dl
88
95
  end
@@ -91,10 +98,10 @@ module IsoDoc::Function
91
98
  "//div[@class = 'figure'][descendant::aside]"\
92
99
  "[not(descendant::div[@class = 'figure'])]".freeze
93
100
 
94
- def figure_aside_process(f, aside, key)
101
+ def figure_aside_process(elem, aside, key)
95
102
  # get rid of footnote link, it is in diagram
96
- f&.at("./a[@class='TableFootnoteRef']")&.remove
97
- fnref = f.at(".//span[@class='TableFootnoteRef']/..")
103
+ elem&.at("./a[@class='TableFootnoteRef']")&.remove
104
+ fnref = elem.at(".//span[@class='TableFootnoteRef']/..")
98
105
  dt = key.add_child("<dt></dt>").first
99
106
  dd = key.add_child("<dd></dd>").first
100
107
  fnref.parent = dt
@@ -109,6 +116,7 @@ module IsoDoc::Function
109
116
  def figure_cleanup(docxml)
110
117
  docxml.xpath(FIGURE_WITH_FOOTNOTES).each do |f|
111
118
  next unless f.at(".//aside[not(ancestor::p[@class = 'FigureTitle'])]")
119
+
112
120
  key = figure_get_or_make_dl(f)
113
121
  f.xpath(".//aside").each do |aside|
114
122
  figure_aside_process(f, aside, key)
@@ -137,12 +145,13 @@ module IsoDoc::Function
137
145
  docxml
138
146
  end
139
147
 
140
- def merge_fnref_into_fn_text(a)
141
- fn = a.at('.//span[@class="TableFootnoteRef"]/..')
148
+ def merge_fnref_into_fn_text(elem)
149
+ fn = elem.at('.//span[@class="TableFootnoteRef"]/..')
142
150
  n = fn.next_element
143
151
  n&.children&.first&.add_previous_sibling(fn.remove)
144
152
  end
145
153
 
154
+ # preempt html2doc putting MsoNormal under TableFootnote class
146
155
  def table_footnote_cleanup(docxml)
147
156
  docxml.xpath("//table[descendant::aside]").each do |t|
148
157
  t.xpath(".//aside").each do |a|
@@ -152,36 +161,36 @@ module IsoDoc::Function
152
161
  t << a.remove
153
162
  end
154
163
  end
155
- # preempt html2doc putting MsoNormal there
156
164
  docxml.xpath("//p[not(self::*[@class])]"\
157
165
  "[ancestor::*[@class = 'TableFootnote']]").each do |p|
158
166
  p["class"] = "TableFootnote"
159
167
  end
160
168
  end
161
169
 
162
- def remove_bottom_border(td)
163
- td["style"] =
164
- td["style"].gsub(/border-bottom:[^;]+;/, "border-bottom:0pt;")
170
+ def remove_bottom_border(cell)
171
+ cell["style"] =
172
+ cell["style"].gsub(/border-bottom:[^;]+;/, "border-bottom:0pt;")
165
173
  end
166
174
 
167
- def table_get_or_make_tfoot(t)
168
- tfoot = t.at(".//tfoot")
175
+ def table_get_or_make_tfoot(table)
176
+ tfoot = table.at(".//tfoot")
169
177
  if tfoot.nil?
170
- t.add_child("<tfoot></tfoot>")
171
- tfoot = t.at(".//tfoot")
178
+ table.add_child("<tfoot></tfoot>")
179
+ tfoot = table.at(".//tfoot")
172
180
  else
173
181
  tfoot.xpath(".//td | .//th").each { |td| remove_bottom_border(td) }
174
182
  end
175
183
  tfoot
176
184
  end
177
185
 
178
- def new_fullcolspan_row(t, tfoot)
186
+ def new_fullcolspan_row(table, tfoot)
179
187
  # how many columns in the table?
180
188
  cols = 0
181
- t.at(".//tr").xpath("./td | ./th").each do |td|
189
+ table.at(".//tr").xpath("./td | ./th").each do |td|
182
190
  cols += (td["colspan"] ? td["colspan"].to_i : 1)
183
191
  end
184
- style = %{border-top:0pt;border-bottom:#{IsoDoc::Function::Table::SW} 1.5pt;}
192
+ style =
193
+ %{border-top:0pt;border-bottom:#{IsoDoc::Function::Table::SW} 1.5pt;}
185
194
  tfoot.add_child("<tr><td colspan='#{cols}' style='#{style}'/></tr>")
186
195
  tfoot.xpath(".//td").last
187
196
  end
@@ -206,12 +215,12 @@ module IsoDoc::Function
206
215
 
207
216
  def symbols_cleanup(docxml); end
208
217
 
209
- def table_footnote_reference_format(a)
210
- a
218
+ def table_footnote_reference_format(link)
219
+ link
211
220
  end
212
221
 
213
- def footnote_reference_format(a)
214
- a
222
+ def footnote_reference_format(link)
223
+ link
215
224
  end
216
225
  end
217
226
  end
@@ -3,11 +3,12 @@ require_relative "inline_simple"
3
3
  module IsoDoc::Function
4
4
  module Inline
5
5
  def link_parse(node, out)
6
- out.a **attr_code(href: node["target"], title: node["alt"]) do |l|
6
+ url = node["target"]
7
+ node["updatetype"] == "true" and url = suffix_url(url)
8
+ out.a **attr_code(href: url, title: node["alt"]) do |l|
7
9
  if node.text.empty?
8
10
  l << node["target"].sub(/^mailto:/, "")
9
- else
10
- node.children.each { |n| parse(n, l) }
11
+ else node.children.each { |n| parse(n, l) }
11
12
  end
12
13
  end
13
14
  end
@@ -79,8 +80,7 @@ module IsoDoc::Function
79
80
  "#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}"\
80
81
  "#{@closemathdelim}"
81
82
  when "MathML" then node.first_element_child.to_s
82
- else
83
- HTMLEntities.new.encode(node.text)
83
+ else HTMLEntities.new.encode(node.text)
84
84
  end
85
85
  out.span **{ class: "stem" } do |span|
86
86
  span.parent.add_child ooml
@@ -123,13 +123,13 @@ module IsoDoc::Function
123
123
  end
124
124
 
125
125
  def add_parse(node, out)
126
- out.span **{class: "addition"} do |e|
126
+ out.span **{ class: "addition" } do |e|
127
127
  node.children.each { |n| parse(n, e) }
128
128
  end
129
129
  end
130
130
 
131
131
  def del_parse(node, out)
132
- out.span **{class: "deletion"} do |e|
132
+ out.span **{ class: "deletion" } do |e|
133
133
  node.children.each { |n| parse(n, e) }
134
134
  end
135
135
  end
@@ -10,9 +10,9 @@ module IsoDoc::Function
10
10
  end
11
11
 
12
12
  # TODO generate formatted ref if not present
13
- def nonstd_bibitem(list, b, ordinal, biblio)
14
- list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref|
15
- ids = bibitem_ref_code(b)
13
+ def nonstd_bibitem(list, bib, ordinal, biblio)
14
+ list.p **attr_code(iso_bibitem_entry_attrs(bib, biblio)) do |ref|
15
+ ids = bibitem_ref_code(bib)
16
16
  identifiers = render_identifier(ids)
17
17
  if biblio then ref_entry_code(ref, ordinal, identifiers, ids)
18
18
  else
@@ -20,21 +20,21 @@ module IsoDoc::Function
20
20
  ref << ", #{identifiers[1]}" if identifiers[0] && identifiers[1]
21
21
  end
22
22
  ref << ", " unless biblio && !identifiers[1]
23
- reference_format(b, ref)
23
+ reference_format(bib, ref)
24
24
  end
25
25
  end
26
26
 
27
- def std_bibitem_entry(list, b, ordinal, biblio)
28
- list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref|
29
- identifiers = render_identifier(bibitem_ref_code(b))
27
+ def std_bibitem_entry(list, bib, ordinal, biblio)
28
+ list.p **attr_code(iso_bibitem_entry_attrs(bib, biblio)) do |ref|
29
+ identifiers = render_identifier(bibitem_ref_code(bib))
30
30
  if biblio then ref_entry_code(ref, ordinal, identifiers, nil)
31
31
  else
32
32
  ref << (identifiers[0] || identifiers[1]).to_s
33
33
  ref << ", #{identifiers[1]}" if identifiers[0] && identifiers[1]
34
34
  end
35
- date_note_process(b, ref)
35
+ date_note_process(bib, ref)
36
36
  ref << ", " unless biblio && !identifiers[1]
37
- reference_format(b, ref)
37
+ reference_format(bib, ref)
38
38
  end
39
39
  end
40
40
 
@@ -45,20 +45,20 @@ module IsoDoc::Function
45
45
  t[1] and r << (t[1]).to_s
46
46
  end
47
47
 
48
- def pref_ref_code(b)
49
- b.at(ns("./docidentifier[not(@type = 'DOI' or @type = 'metanorma' "\
48
+ def pref_ref_code(bib)
49
+ bib.at(ns("./docidentifier[not(@type = 'DOI' or @type = 'metanorma' "\
50
50
  "or @type = 'ISSN' or @type = 'ISBN' or @type = 'rfc-anchor')]"))
51
51
  end
52
52
 
53
53
  # returns [metanorma, non-metanorma, DOI/ISSN/ISBN] identifiers
54
- def bibitem_ref_code(b)
55
- id = b.at(ns("./docidentifier[@type = 'metanorma']"))
56
- id1 = pref_ref_code(b)
57
- id2 = b.at(ns("./docidentifier[@type = 'DOI' or @type = 'ISSN' or "\
54
+ def bibitem_ref_code(bib)
55
+ id = bib.at(ns("./docidentifier[@type = 'metanorma']"))
56
+ id1 = pref_ref_code(bib)
57
+ id2 = bib.at(ns("./docidentifier[@type = 'DOI' or @type = 'ISSN' or "\
58
58
  "@type = 'ISBN']"))
59
59
  return [id, id1, id2] if id || id1 || id2
60
60
 
61
- id = Nokogiri::XML::Node.new("docidentifier", b.document)
61
+ id = Nokogiri::XML::Node.new("docidentifier", bib.document)
62
62
  id << "(NO ID)"
63
63
  [nil, id, nil]
64
64
  end
@@ -72,20 +72,10 @@ module IsoDoc::Function
72
72
  num
73
73
  end
74
74
 
75
- def render_identifier(id)
76
- [
77
- bracket_if_num(id[0]),
78
- if id[1].nil?
79
- nil
80
- else
81
- docid_prefix(id[1]["type"], id[1].text.sub(/^\[/, "").sub(/\]$/, ""))
82
- end,
83
- if id[2].nil?
84
- nil
85
- else
86
- docid_prefix(id[2]["type"], id[2].text.sub(/^\[/, "").sub(/\]$/, ""))
87
- end,
88
- ]
75
+ def render_identifier(ident)
76
+ [bracket_if_num(ident[0]),
77
+ ident[1].nil? ? nil : ident[1].text.sub(/^\[/, "").sub(/\]$/, ""),
78
+ ident[2].nil? ? nil : ident[2].text.sub(/^\[/, "").sub(/\]$/, "")]
89
79
  end
90
80
 
91
81
  def docid_prefix(prefix, docid)
@@ -97,19 +87,20 @@ module IsoDoc::Function
97
87
  def omit_docid_prefix(prefix)
98
88
  return true if prefix.nil? || prefix.empty?
99
89
 
100
- %w(ISO IEC IEV ITU W3C csd metanorma rfc-anchor).include? prefix
90
+ %w(ISO IEC IEV ITU W3C csd metanorma repository rfc-anchor)
91
+ .include? prefix
101
92
  end
102
93
 
103
- def date_note_process(b, ref)
104
- date_note = b.at(ns("./note[@type = 'Unpublished-Status']"))
94
+ def date_note_process(bib, ref)
95
+ date_note = bib.at(ns("./note[@type = 'Unpublished-Status']"))
105
96
  return if date_note.nil?
106
97
 
107
98
  date_note.children.first.replace("<p>#{date_note.content}</p>")
108
99
  footnote_parse(date_note, ref)
109
100
  end
110
101
 
111
- def iso_bibitem_entry_attrs(b, biblio)
112
- { id: b["id"], class: biblio ? "Biblio" : "NormRef" }
102
+ def iso_bibitem_entry_attrs(bib, biblio)
103
+ { id: bib["id"], class: biblio ? "Biblio" : "NormRef" }
113
104
  end
114
105
 
115
106
  def iso_title(bib)
@@ -130,22 +121,21 @@ module IsoDoc::Function
130
121
  insert_tab(ref, 1)
131
122
  end
132
123
 
133
- def reference_format(bib, r)
124
+ def reference_format(bib, out)
134
125
  if ftitle = bib.at(ns("./formattedref"))
135
- ftitle&.children&.each { |n| parse(n, r) }
126
+ ftitle&.children&.each { |n| parse(n, out) }
136
127
  else
137
- title = iso_title(bib)
138
- r.i do |i|
139
- title&.children&.each { |n| parse(n, i) }
128
+ out.i do |i|
129
+ iso_title(bib)&.children&.each { |n| parse(n, i) }
140
130
  end
141
131
  end
142
132
  end
143
133
 
144
134
  def is_standard(bib)
145
135
  ret = false
136
+ drop = %w(metanorma DOI ISSN ISBN)
146
137
  bib.xpath(ns("./docidentifier")).each do |id|
147
- next if id["type"].nil? ||
148
- %w(metanorma DOI ISSN ISBN).include?(id["type"])
138
+ next if id["type"].nil? || drop.include?(id["type"])
149
139
 
150
140
  ret = true
151
141
  end
@@ -180,8 +170,7 @@ module IsoDoc::Function
180
170
  clause_name(num, f.at(ns("./title")), div, nil)
181
171
  if f.name == "clause"
182
172
  f.elements.each { |e| parse(e, div) unless e.name == "title" }
183
- else
184
- biblio_list(f, div, false)
173
+ else biblio_list(f, div, false)
185
174
  end
186
175
  end
187
176
  num
@@ -212,13 +201,5 @@ module IsoDoc::Function
212
201
  biblio_list(node, div, true)
213
202
  end
214
203
  end
215
-
216
- def format_ref(ref, prefix, _isopub, _date, _allparts)
217
- ref = docid_prefix(prefix, ref)
218
- return "[#{ref}]" if ref && /^\d+$/.match(ref) && !prefix &&
219
- !/^\[.*\]$/.match(ref)
220
-
221
- ref
222
- end
223
204
  end
224
205
  end