metanorma-standoc 1.11.0.1 → 1.11.4

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/lib/asciidoctor/standoc/base.rb +4 -100
  4. data/lib/asciidoctor/standoc/blocks.rb +1 -1
  5. data/lib/asciidoctor/standoc/cleanup.rb +2 -1
  6. data/lib/asciidoctor/standoc/cleanup_block.rb +1 -2
  7. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +28 -20
  8. data/lib/asciidoctor/standoc/cleanup_inline.rb +14 -4
  9. data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +25 -15
  10. data/lib/asciidoctor/standoc/cleanup_reqt.rb +3 -3
  11. data/lib/asciidoctor/standoc/cleanup_section_names.rb +2 -2
  12. data/lib/asciidoctor/standoc/cleanup_terms.rb +58 -21
  13. data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +58 -21
  14. data/lib/asciidoctor/standoc/cleanup_text.rb +23 -0
  15. data/lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb +6 -6
  16. data/lib/asciidoctor/standoc/front.rb +13 -9
  17. data/lib/asciidoctor/standoc/inline.rb +13 -11
  18. data/lib/asciidoctor/standoc/isodoc.rng +73 -19
  19. data/lib/asciidoctor/standoc/lists.rb +1 -3
  20. data/lib/asciidoctor/standoc/ref.rb +101 -75
  21. data/lib/asciidoctor/standoc/ref_date_id.rb +30 -1
  22. data/lib/asciidoctor/standoc/ref_sect.rb +16 -6
  23. data/lib/asciidoctor/standoc/render.rb +115 -0
  24. data/lib/asciidoctor/standoc/reqt.rb +1 -1
  25. data/lib/asciidoctor/standoc/section.rb +33 -15
  26. data/lib/asciidoctor/standoc/terms.rb +7 -1
  27. data/lib/asciidoctor/standoc/utils.rb +0 -16
  28. data/lib/asciidoctor/standoc/validate.rb +1 -1
  29. data/lib/isodoc/html/htmlstyle.css +20 -11
  30. data/lib/isodoc/html/htmlstyle.scss +11 -11
  31. data/lib/metanorma/standoc/version.rb +1 -1
  32. data/metanorma-standoc.gemspec +3 -3
  33. data/spec/asciidoctor/base_spec.rb +48 -0
  34. data/spec/asciidoctor/blocks_spec.rb +99 -17
  35. data/spec/asciidoctor/cleanup_blocks_spec.rb +24 -0
  36. data/spec/asciidoctor/cleanup_sections_spec.rb +1 -1
  37. data/spec/asciidoctor/cleanup_spec.rb +6 -6
  38. data/spec/asciidoctor/cleanup_terms_spec.rb +556 -89
  39. data/spec/asciidoctor/datamodel/attributes_table_preprocessor_spec.rb +21 -21
  40. data/spec/asciidoctor/datamodel/diagram_preprocessor_spec.rb +16 -16
  41. data/spec/asciidoctor/inline_spec.rb +174 -5
  42. data/spec/asciidoctor/isobib_cache_spec.rb +4 -8
  43. data/spec/asciidoctor/macros_spec.rb +2 -2
  44. data/spec/asciidoctor/refs_dl_spec.rb +4 -4
  45. data/spec/asciidoctor/refs_spec.rb +889 -495
  46. data/spec/asciidoctor/section_spec.rb +64 -2
  47. data/spec/spec_helper.rb +2 -2
  48. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +182 -182
  49. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
  50. data/spec/vcr_cassettes/isobib_get_123.yml +14 -14
  51. data/spec/vcr_cassettes/isobib_get_123_1.yml +99 -99
  52. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +107 -107
  53. data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -14
  54. data/spec/vcr_cassettes/isobib_get_124.yml +12 -12
  55. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
  56. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
  57. metadata +9 -8
@@ -22,37 +22,44 @@ module Asciidoctor
22
22
  { id: match[:anchor], type: "standard" }
23
23
  end
24
24
 
25
- def isorefrender1(bib, match, yr, allp = "")
25
+ def isorefrender1(bib, match, year, allp = "")
26
26
  bib.title(**plaintxt) { |i| i << ref_normalise(match[:text]) }
27
27
  docid(bib, match[:usrlbl]) if match[:usrlbl]
28
- docid(bib, id_and_year(match[:code], yr) + allp)
28
+ docid(bib, id_and_year(match[:code], year) + allp)
29
29
  docnumber(bib, match[:code])
30
30
  end
31
31
 
32
- def isorefmatches(xml, match)
32
+ def isorefmatchescode(match)
33
33
  yr = norm_year(match[:year])
34
- ref = fetch_ref xml, match[:code], yr,
35
- title: match[:text], usrlbl: match[:usrlbl],
36
- lang: (@lang || :all)
37
- return use_my_anchor(ref, match[:anchor]) if ref
38
-
39
- xml.bibitem **attr_code(ref_attributes(match)) do |t|
40
- isorefrender1(t, match, yr)
41
- yr and t.date **{ type: "published" } do |d|
42
- set_date_range(d, yr)
34
+ { code: match[:code], year: yr, match: match,
35
+ title: match[:text], usrlbl: match[:usrlbl],
36
+ lang: (@lang || :all) }
37
+ end
38
+
39
+ def isorefmatchesout(item, xml)
40
+ if item[:doc] then use_retrieved_relaton(item, xml)
41
+ else
42
+ xml.bibitem **attr_code(ref_attributes(item[:ref][:match])) do |t|
43
+ isorefrender1(t, item[:ref][:match], item[:ref][:year])
44
+ item[:ref][:year] and t.date **{ type: "published" } do |d|
45
+ set_date_range(d, item[:ref][:year])
46
+ end
47
+ iso_publisher(t, item[:ref][:match][:code])
43
48
  end
44
- iso_publisher(t, match[:code])
45
49
  end
46
50
  end
47
51
 
48
- def isorefmatches2(xml, match)
49
- ref = fetch_ref xml, match[:code], nil,
50
- no_year: true, note: match[:fn],
51
- title: match[:text], usrlbl: match[:usrlbl],
52
- lang: (@lang || :all)
53
- return use_my_anchor(ref, match[:anchor]) if ref
52
+ def isorefmatches2code(match)
53
+ { code: match[:code], no_year: true,
54
+ note: match[:fn], year: nil, match: match,
55
+ title: match[:text], usrlbl: match[:usrlbl],
56
+ lang: (@lang || :all) }
57
+ end
54
58
 
55
- isorefmatches2_1(xml, match)
59
+ def isorefmatches2out(item, xml)
60
+ if item[:doc] then use_retrieved_relaton(item, xml)
61
+ else isorefmatches2_1(xml, item[:ref][:match])
62
+ end
56
63
  end
57
64
 
58
65
  def isorefmatches2_1(xml, match)
@@ -70,16 +77,22 @@ module Asciidoctor
70
77
  end
71
78
  end
72
79
 
73
- def isorefmatches3(xml, match)
80
+ def isorefmatches3code(match)
74
81
  yr = norm_year(match[:year])
75
82
  hasyr = !yr.nil? && yr != "--"
76
- ref = fetch_ref(xml, match[:code], hasyr ? yr : nil,
77
- all_parts: true, no_year: yr == "--",
78
- text: match[:text], usrlbl: match[:usrlbl],
79
- lang: (@lang || :all))
80
- return use_my_anchor(ref, match[:anchor]) if ref
81
-
82
- isorefmatches3_1(xml, match, yr, hasyr, ref)
83
+ { code: match[:code], match: match, yr: yr, hasyr: hasyr,
84
+ year: hasyr ? yr : nil,
85
+ all_parts: true, no_year: yr == "--",
86
+ text: match[:text], usrlbl: match[:usrlbl],
87
+ lang: (@lang || :all) }
88
+ end
89
+
90
+ def isorefmatches3out(item, xml)
91
+ if item[:doc] then use_retrieved_relaton(item, xml)
92
+ else
93
+ isorefmatches3_1(xml, item[:ref][:match], item[:ref][:yr],
94
+ item[:ref][:hasyr], item[:doc])
95
+ end
83
96
  end
84
97
 
85
98
  def isorefmatches3_1(xml, match, yr, _hasyr, _ref)
@@ -120,56 +133,34 @@ module Asciidoctor
120
133
  end
121
134
 
122
135
  MALFORMED_REF = "no anchor on reference, markup may be malformed: see "\
123
- "https://www.metanorma.com/author/topics/document-format/bibliography/ , "\
124
- "https://www.metanorma.com/author/iso/topics/markup/#bibliographies".freeze
125
-
126
- def analyse_ref_nofetch(ret)
127
- return ret unless m = /^nofetch\((?<id>.+)\)$/.match(ret[:id])
128
-
129
- ret.merge(id: m[:id], nofetch: true)
130
- end
131
-
132
- def analyse_ref_repo_path(ret)
133
- return ret unless m =
134
- /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
135
-
136
- id = m[:id].empty? ? m[:key].sub(%r{^[^/]+/}, "") : m[:id]
137
- ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true)
138
- end
139
-
140
- def analyse_ref_numeric(ret)
141
- return ret unless /^\d+$/.match?(ret[:id])
142
-
143
- ret.merge(numeric: true)
144
- end
145
-
146
- # ref id = (usrlbl)code[:-]year
147
- # code = nofetch(code) | (repo|path):(key,code) | \[? number \]? | ident
148
- def analyse_ref_code(code)
149
- ret = { id: code }
150
- return ret if code.blank?
151
-
152
- analyse_ref_nofetch(analyse_ref_repo_path(analyse_ref_numeric(ret)))
153
- end
136
+ "https://www.metanorma.com/author/topics/document-format/bibliography/ , "\
137
+ "https://www.metanorma.com/author/iso/topics/markup/#bibliographies".freeze
154
138
 
155
139
  # TODO: alternative where only title is available
156
- def refitem(xml, item, node)
157
- m = NON_ISO_REF.match(item) and return refitem1(xml, item, m)
140
+ def refitemcode(item, node)
141
+ m = NON_ISO_REF.match(item) and return refitem1code(item, m)
158
142
  @log.add("AsciiDoc Input", node, "#{MALFORMED_REF}: #{item}")
159
- nil
143
+ {}
160
144
  end
161
145
 
162
- def refitem1(xml, _item, match)
146
+ def refitem1code(_item, match)
163
147
  code = analyse_ref_code(match[:code])
164
- unless code[:id] && code[:numeric] || code[:nofetch]
165
- ref = fetch_ref(xml, code[:id],
166
- match.names.include?("year") ? match[:year] : nil,
167
- title: match[:text],
168
- usrlbl: match[:usrlbl], lang: (@lang || :all)) and
169
- return use_my_anchor(ref, match[:anchor])
148
+ if (code[:id] && code[:numeric]) || code[:nofetch]
149
+ { code: nil, match: match, analyse_code: code }
150
+ else
151
+ { code: code[:id], analyse_code: code,
152
+ year: match.names.include?("year") ? match[:year] : nil,
153
+ title: match[:text], match: match,
154
+ usrlbl: match[:usrlbl], lang: (@lang || :all) }
170
155
  end
156
+ end
157
+
158
+ def refitemout(item, xml)
159
+ return nil if item[:ref][:match].nil?
171
160
 
172
- refitem_render(xml, match, code)
161
+ item[:doc] or return refitem_render(xml, item[:ref][:match],
162
+ item[:ref][:analyse_code])
163
+ use_retrieved_relaton(item, xml)
173
164
  end
174
165
 
175
166
  def ref_normalise(ref)
@@ -211,15 +202,50 @@ module Asciidoctor
211
202
  [matched, matched2, matched3]
212
203
  end
213
204
 
214
- def reference1(node, item, xml)
205
+ def reference1code(item, node)
215
206
  matched, matched2, matched3 = reference1_matches(item)
216
207
  if matched3.nil? && matched2.nil? && matched.nil?
217
- refitem(xml, item, node)
218
- elsif !matched.nil? then isorefmatches(xml, matched)
219
- elsif !matched2.nil? then isorefmatches2(xml, matched2)
220
- elsif !matched3.nil? then isorefmatches3(xml, matched3)
208
+ refitemcode(item, node).merge(process: 0)
209
+ elsif !matched.nil? then isorefmatchescode(matched).merge(process: 1)
210
+ elsif !matched2.nil? then isorefmatches2code(matched2).merge(process: 2)
211
+ elsif !matched3.nil? then isorefmatches3code(matched3).merge(process: 3)
221
212
  end
222
213
  end
214
+
215
+ def reference1out(item, xml)
216
+ case item[:ref][:process]
217
+ when 0 then refitemout(item, xml)
218
+ when 1 then isorefmatchesout(item, xml)
219
+ when 2 then isorefmatches2out(item, xml)
220
+ when 3 then isorefmatches3out(item, xml)
221
+ end
222
+ end
223
+
224
+ def reference_preproc(node)
225
+ refs = node.items.each_with_object([]) do |b, m|
226
+ m << reference1code(b.text, node)
227
+ end
228
+ results = refs.each_with_index.with_object(Queue.new) do |(ref, i), res|
229
+ fetch_ref_async(ref.merge(ord: i), i, res)
230
+ end
231
+ [refs, results]
232
+ end
233
+
234
+ def reference(node)
235
+ refs, results = reference_preproc(node)
236
+ noko do |xml|
237
+ ret = refs.each.with_object([]) do |_, m|
238
+ ref, i, doc = results.pop
239
+ m[i.to_i] = { ref: ref }
240
+ if doc.is_a?(RelatonBib::RequestError)
241
+ @log.add("Bibliography", nil, "Could not retrieve #{ref[:code]}: "\
242
+ "no access to online site")
243
+ else m[i.to_i][:doc] = doc
244
+ end
245
+ end
246
+ ret.each { |b| reference1out(b, xml) }
247
+ end.join
248
+ end
223
249
  end
224
250
  end
225
251
  end
@@ -26,7 +26,7 @@ module Asciidoctor
26
26
  def conditional_date(bib, match, noyr)
27
27
  if match.names.include?("year") && !match[:year].nil?
28
28
  bib.date(**{ type: "published" }) do |d|
29
- noyr and d.on "--" or set_date_range(d, norm_year(match[:year]))
29
+ (noyr and d.on "--") or set_date_range(d, norm_year(match[:year]))
30
30
  end
31
31
  end
32
32
  end
@@ -57,6 +57,35 @@ module Asciidoctor
57
57
  def mn_code(code)
58
58
  code.sub(/^\(/, "[").sub(/\).*$/, "]").sub(/^nofetch\((.+)\)$/, "\\1")
59
59
  end
60
+
61
+ def analyse_ref_nofetch(ret)
62
+ return ret unless m = /^nofetch\((?<id>.+)\)$/.match(ret[:id])
63
+
64
+ ret.merge(id: m[:id], nofetch: true)
65
+ end
66
+
67
+ def analyse_ref_repo_path(ret)
68
+ return ret unless m =
69
+ /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
70
+
71
+ id = m[:id].empty? ? m[:key].sub(%r{^[^/]+/}, "") : m[:id]
72
+ ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true)
73
+ end
74
+
75
+ def analyse_ref_numeric(ret)
76
+ return ret unless /^\d+$/.match?(ret[:id])
77
+
78
+ ret.merge(numeric: true)
79
+ end
80
+
81
+ # ref id = (usrlbl)code[:-]year
82
+ # code = nofetch(code) | (repo|path):(key,code) | \[? number \]? | ident
83
+ def analyse_ref_code(code)
84
+ ret = { id: code }
85
+ return ret if code.blank?
86
+
87
+ analyse_ref_nofetch(analyse_ref_repo_path(analyse_ref_numeric(ret)))
88
+ end
60
89
  end
61
90
  end
62
91
  end
@@ -9,12 +9,6 @@ module Asciidoctor
9
9
  @norm_ref
10
10
  end
11
11
 
12
- def reference(node)
13
- noko do |xml|
14
- node.items.each { |item| reference1(node, item.text, xml) }
15
- end.join
16
- end
17
-
18
12
  def bibliography_parse(attrs, xml, node)
19
13
  x = biblio_prep(attrs, xml, node) and return x
20
14
  @biblio = true
@@ -86,6 +80,16 @@ module Asciidoctor
86
80
  nil
87
81
  end
88
82
 
83
+ def fetch_ref_async(ref, idx, res)
84
+ if ref[:code].nil? || ref[:no_year] || @bibdb.nil?
85
+ res << [ref, idx, nil]
86
+ else
87
+ @bibdb.fetch_async(ref[:code], ref[:year], ref) do |doc|
88
+ res << [ref, idx, doc]
89
+ end
90
+ end
91
+ end
92
+
89
93
  def emend_biblio(xml, code, title, usrlbl)
90
94
  unless xml.at("/bibitem/docidentifier[not(@type = 'DOI')][text()]")
91
95
  @log.add("Bibliography", nil,
@@ -112,6 +116,12 @@ module Asciidoctor
112
116
  xml.to_xml.sub(/<\?[^>]+>/, "")
113
117
  end
114
118
 
119
+ def use_retrieved_relaton(item, xml)
120
+ xml.parent.add_child(smart_render_xml(item[:doc], item[:ref][:code],
121
+ item[:ref]))
122
+ use_my_anchor(xml, item[:ref][:match][:anchor])
123
+ end
124
+
115
125
  def init_bib_caches(node)
116
126
  return if @no_isobib
117
127
 
@@ -0,0 +1,115 @@
1
+ module Asciidoctor
2
+ module Standoc
3
+ module Base
4
+ def html_extract_attributes(node)
5
+ {
6
+ script: node.attr("script"),
7
+ bodyfont: node.attr("body-font"),
8
+ headerfont: node.attr("header-font"),
9
+ monospacefont: node.attr("monospace-font"),
10
+ i18nyaml: node.attr("i18nyaml"),
11
+ scope: node.attr("scope"),
12
+ htmlstylesheet: node.attr("htmlstylesheet"),
13
+ htmlstylesheet_override: node.attr("htmlstylesheet-override"),
14
+ htmlcoverpage: node.attr("htmlcoverpage"),
15
+ htmlintropage: node.attr("htmlintropage"),
16
+ scripts: node.attr("scripts"),
17
+ scripts_override: node.attr("scripts-override"),
18
+ scripts_pdf: node.attr("scripts-pdf"),
19
+ datauriimage: node.attr("data-uri-image") != "false",
20
+ htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
21
+ doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
22
+ break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
23
+ suppressasciimathdup: node.attr("suppress-asciimath-dup"),
24
+ bare: node.attr("bare"),
25
+ sectionsplit: node.attr("sectionsplit"),
26
+ baseassetpath: node.attr("base-asset-path"),
27
+ aligncrosselements: node.attr("align-cross-elements"),
28
+ }
29
+ end
30
+
31
+ def html_converter(node)
32
+ IsoDoc::HtmlConvert.new(html_extract_attributes(node))
33
+ end
34
+
35
+ def pdf_converter(node)
36
+ return nil if node.attr("no-pdf")
37
+
38
+ IsoDoc::Standoc::PdfConvert.new(pdf_extract_attributes(node))
39
+ end
40
+
41
+ def doc_extract_attributes(node)
42
+ attrs = {
43
+ script: node.attr("script"),
44
+ bodyfont: node.attr("body-font"),
45
+ headerfont: node.attr("header-font"),
46
+ monospacefont: node.attr("monospace-font"),
47
+ i18nyaml: node.attr("i18nyaml"),
48
+ scope: node.attr("scope"),
49
+ wordstylesheet: node.attr("wordstylesheet"),
50
+ wordstylesheet_override: node.attr("wordstylesheet-override"),
51
+ standardstylesheet: node.attr("standardstylesheet"),
52
+ header: node.attr("header"),
53
+ wordcoverpage: node.attr("wordcoverpage"),
54
+ wordintropage: node.attr("wordintropage"),
55
+ ulstyle: node.attr("ulstyle"),
56
+ olstyle: node.attr("olstyle"),
57
+ htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
58
+ doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
59
+ break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
60
+ suppressasciimathdup: node.attr("suppress-asciimath-dup"),
61
+ bare: node.attr("bare"),
62
+ baseassetpath: node.attr("base-asset-path"),
63
+ aligncrosselements: node.attr("align-cross-elements"),
64
+ }
65
+
66
+ if fonts_manifest = node.attr(FONTS_MANIFEST)
67
+ attrs[IsoDoc::XslfoPdfConvert::MN2PDF_OPTIONS] = {
68
+ IsoDoc::XslfoPdfConvert::MN2PDF_FONT_MANIFEST => fonts_manifest,
69
+ }
70
+ end
71
+
72
+ attrs
73
+ end
74
+
75
+ def pdf_extract_attributes(node)
76
+ %w(pdf-encrypt pdf-encryption-length pdf-user-password
77
+ pdf-owner-password pdf-allow-copy-content pdf-allow-edit-content
78
+ pdf-allow-assemble-document pdf-allow-edit-annotations
79
+ pdf-allow-print pdf-allow-print-hq pdf-allow-fill-in-forms
80
+ pdf-allow-access-content pdf-encrypt-metadata)
81
+ .each_with_object({}) do |x, m|
82
+ m[x.gsub(/-/, "").to_i] = node.attr(x)
83
+ end
84
+ end
85
+
86
+ def doc_converter(node)
87
+ IsoDoc::WordConvert.new(doc_extract_attributes(node))
88
+ end
89
+
90
+ def presentation_xml_converter(node)
91
+ IsoDoc::PresentationXMLConvert.new(html_extract_attributes(node))
92
+ end
93
+
94
+ def default_fonts(node)
95
+ b = node.attr("body-font") ||
96
+ (node.attr("script") == "Hans" ? '"Source Han Sans",serif' : '"Cambria",serif')
97
+ h = node.attr("header-font") ||
98
+ (node.attr("script") == "Hans" ? '"Source Han Sans",sans-serif' : '"Cambria",serif')
99
+ m = node.attr("monospace-font") || '"Courier New",monospace'
100
+ "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
101
+ end
102
+
103
+ def outputs(node, ret)
104
+ File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) }
105
+ presentation_xml_converter(node).convert("#{@filename}.xml")
106
+ html_converter(node).convert("#{@filename}.presentation.xml",
107
+ nil, false, "#{@filename}.html")
108
+ doc_converter(node).convert("#{@filename}.presentation.xml",
109
+ nil, false, "#{@filename}.doc")
110
+ pdf_converter(node)&.convert("#{@filename}.presentation.xml",
111
+ nil, false, "#{@filename}.pdf")
112
+ end
113
+ end
114
+ end
115
+ end
@@ -1,5 +1,5 @@
1
1
  require "htmlentities"
2
- require "uri"
2
+ require "uri" if /^2\./.match?(RUBY_VERSION)
3
3
  require "mime/types"
4
4
  require "base64"
5
5
 
@@ -1,4 +1,4 @@
1
- require "uri"
1
+ require "uri" if /^2\./.match?(RUBY_VERSION)
2
2
  require_relative "ref_sect"
3
3
  require_relative "terms"
4
4
 
@@ -18,7 +18,7 @@ module Asciidoctor
18
18
  def sectiontype(node, level = true)
19
19
  ret = sectiontype1(node)
20
20
  ret1 = sectiontype_streamline(ret)
21
- return ret1 if "symbols and abbreviated terms" == ret1
21
+ return ret1 if ret1 == "symbols and abbreviated terms"
22
22
  return nil unless !level || node.level == 1
23
23
  return nil if @seen_headers.include? ret
24
24
 
@@ -49,12 +49,17 @@ module Asciidoctor
49
49
  script: node.attributes["script"],
50
50
  number: node.attributes["number"],
51
51
  type: node.attributes["type"],
52
- annex: (if (node.attr("style") == "appendix" || node.role == "appendix") &&
52
+ annex: (if (node.attr("style") == "appendix" ||
53
+ node.role == "appendix") &&
53
54
  node.level == 1
54
55
  true
55
56
  end),
56
- preface: (
57
- node.role == "preface" || node.attr("style") == "preface" ? true : nil) }
57
+ tag: node&.attr("tag"),
58
+ "multilingual-rendering": node&.attr("multilingual-rendering"),
59
+ preface: (if node.role == "preface" ||
60
+ node.attr("style") == "preface"
61
+ true
62
+ end) }
58
63
  return ret unless node.attributes["change"]
59
64
 
60
65
  ret.merge(change: node.attributes["change"],
@@ -84,13 +89,11 @@ module Asciidoctor
84
89
  else
85
90
  if @term_def then term_def_subclause_parse(a, xml, node)
86
91
  elsif @definitions then symbols_parse(a, xml, node)
87
- elsif @norm_ref then norm_ref_parse(a, xml, node)
88
- elsif @biblio then bibliography_parse(a, xml, node)
89
- elsif node.attr("style") == "bibliography" && sectiontype(node, false) == "normative references"
92
+ elsif @norm_ref ||
93
+ (node.attr("style") == "bibliography" &&
94
+ sectiontype(node, false) == "normative references")
90
95
  norm_ref_parse(a, xml, node)
91
- elsif node.attr("style") == "bibliography" && sectiontype(node, false) == "bibliography"
92
- bibliography_parse(a, xml, node)
93
- elsif node.attr("style") == "bibliography"
96
+ elsif @biblio || node.attr("style") == "bibliography"
94
97
  bibliography_parse(a, xml, node)
95
98
  elsif node.attr("style") == "abstract"
96
99
  abstract_parse(a, xml, node)
@@ -118,7 +121,9 @@ module Asciidoctor
118
121
  def preamble(node)
119
122
  noko do |xml|
120
123
  xml.foreword **attr_code(section_attributes(node)) do |xml_abstract|
121
- xml_abstract.title { |t| t << (node.blocks[0].title || @i18n.foreword) }
124
+ xml_abstract.title do |t|
125
+ t << (node.blocks[0].title || @i18n.foreword)
126
+ end
122
127
  content = node.content
123
128
  xml_abstract << content
124
129
  end
@@ -143,7 +148,7 @@ module Asciidoctor
143
148
  end
144
149
 
145
150
  def clause_parse(attrs, xml, node)
146
- attrs["inline-header".to_sym] = node.option? "inline-header"
151
+ attrs[:"inline-header"] = node.option? "inline-header"
147
152
  attrs[:bibitem] = true if node.option? "bibitem"
148
153
  attrs[:level] = node.attr("level")
149
154
  set_obligation(attrs, node)
@@ -154,7 +159,7 @@ module Asciidoctor
154
159
  end
155
160
 
156
161
  def annex_parse(attrs, xml, node)
157
- attrs["inline-header".to_sym] = node.option? "inline-header"
162
+ attrs[:"inline-header"] = node.option? "inline-header"
158
163
  set_obligation(attrs, node)
159
164
  xml.annex **attr_code(attrs) do |xml_section|
160
165
  xml_section.title { |name| name << node.title }
@@ -180,11 +185,24 @@ module Asciidoctor
180
185
 
181
186
  def acknowledgements_parse(attrs, xml, node)
182
187
  xml.acknowledgements **attr_code(attrs) do |xml_section|
183
- xml_section.title { |t| t << node.title || @i18n.acknowledgements }
188
+ xml_section.title { |t| (t << node.title) || @i18n.acknowledgements }
184
189
  content = node.content
185
190
  xml_section << content
186
191
  end
187
192
  end
193
+
194
+ def floating_title_attrs(node)
195
+ attr_code(id_attr(node).merge(align: node.attr("align"),
196
+ type: "floating-title"))
197
+ end
198
+
199
+ def floating_title(node)
200
+ noko do |xml|
201
+ xml.p **floating_title_attrs(node) do |xml_t|
202
+ xml_t << node.title
203
+ end
204
+ end.join("\n")
205
+ end
188
206
  end
189
207
  end
190
208
  end
@@ -105,8 +105,14 @@ module Asciidoctor
105
105
  else
106
106
  attrs = term_source_attrs(node, seen_xref)
107
107
  attrs.delete(:text)
108
- xml_t.origin seen_xref.children[0].content, **attr_code(attrs)
108
+ xml_t.origin **attr_code(attrs) do |o|
109
+ o << seen_xref.children[0].children.to_xml
110
+ end
109
111
  end
112
+ add_term_source_mod(xml_t, match)
113
+ end
114
+
115
+ def add_term_source_mod(xml_t, match)
110
116
  match[:text] && xml_t.modification do |mod|
111
117
  mod.p { |p| p << match[:text].sub(/^\s+/, "") }
112
118
  end
@@ -64,22 +64,6 @@ module Asciidoctor
64
64
  conv
65
65
  end
66
66
 
67
- def default_script(lang)
68
- case lang
69
- when "ar", "fa" then "Arab"
70
- when "ur" then "Aran"
71
- when "ru", "bg" then "Cyrl"
72
- when "hi" then "Deva"
73
- when "el" then "Grek"
74
- when "zh" then "Hans"
75
- when "ko" then "Kore"
76
- when "he" then "Hebr"
77
- when "ja" then "Jpan"
78
- else
79
- "Latn"
80
- end
81
- end
82
-
83
67
  def dl_to_attrs(elem, dlist, name)
84
68
  e = dlist.at("./dt[text()='#{name}']") or return
85
69
  val = e.at("./following::dd/p") || e.at("./following::dd") or return
@@ -112,7 +112,7 @@ module Asciidoctor
112
112
  def schema_validate1(file, doc, schema)
113
113
  file.write(doc.to_xml)
114
114
  file.close
115
- errors = Jing.new(schema).validate(file.path)
115
+ errors = Jing.new(schema, encoding: "UTF-8").validate(file.path)
116
116
  warn "Syntax Valid!" if errors.none?
117
117
  errors.each do |e|
118
118
  @log.add("Metanorma XML Syntax",