metanorma-standoc 1.6.3 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +1 -1
  3. data/lib/asciidoctor/standoc/base.rb +8 -16
  4. data/lib/asciidoctor/standoc/basicdoc.rng +50 -3
  5. data/lib/asciidoctor/standoc/cleanup.rb +1 -1
  6. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +33 -20
  7. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +14 -0
  8. data/lib/asciidoctor/standoc/cleanup_inline.rb +3 -1
  9. data/lib/asciidoctor/standoc/cleanup_ref.rb +17 -24
  10. data/lib/asciidoctor/standoc/cleanup_terms.rb +4 -6
  11. data/lib/asciidoctor/standoc/converter.rb +85 -1
  12. data/lib/asciidoctor/standoc/front_contributor.rb +8 -4
  13. data/lib/asciidoctor/standoc/inline.rb +7 -5
  14. data/lib/asciidoctor/standoc/isodoc.rng +36 -3
  15. data/lib/asciidoctor/standoc/macros.rb +42 -61
  16. data/lib/asciidoctor/standoc/macros_terms.rb +82 -0
  17. data/lib/asciidoctor/standoc/ref.rb +17 -23
  18. data/lib/asciidoctor/standoc/ref_sect.rb +4 -3
  19. data/lib/asciidoctor/standoc/section.rb +21 -20
  20. data/lib/asciidoctor/standoc/table.rb +12 -0
  21. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +86 -0
  22. data/lib/asciidoctor/standoc/utils.rb +2 -0
  23. data/lib/metanorma/standoc/version.rb +1 -1
  24. data/metanorma-standoc.gemspec +5 -4
  25. data/spec/asciidoctor-standoc/base_spec.rb +10 -4
  26. data/spec/asciidoctor-standoc/blocks_spec.rb +14 -9
  27. data/spec/asciidoctor-standoc/cleanup_sections_spec.rb +37 -16
  28. data/spec/asciidoctor-standoc/cleanup_spec.rb +75 -11
  29. data/spec/asciidoctor-standoc/converter_spec.rb +21 -0
  30. data/spec/asciidoctor-standoc/inline_spec.rb +4 -5
  31. data/spec/asciidoctor-standoc/isobib_cache_spec.rb +9 -2
  32. data/spec/asciidoctor-standoc/macros_lutaml_spec.rb +5 -5
  33. data/spec/asciidoctor-standoc/macros_plantuml_spec.rb +307 -0
  34. data/spec/asciidoctor-standoc/macros_spec.rb +374 -169
  35. data/spec/asciidoctor-standoc/refs_dl_spec.rb +6 -6
  36. data/spec/asciidoctor-standoc/refs_spec.rb +100 -53
  37. data/spec/asciidoctor-standoc/section_spec.rb +17 -12
  38. data/spec/asciidoctor-standoc/table_spec.rb +146 -0
  39. data/spec/asciidoctor-standoc/validate_spec.rb +26 -0
  40. data/spec/fixtures/diagram_definitions.lutaml +22 -0
  41. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +49 -49
  42. data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
  43. data/spec/vcr_cassettes/isobib_get_123_1.yml +26 -26
  44. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +33 -33
  45. data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -14
  46. data/spec/vcr_cassettes/isobib_get_124.yml +12 -12
  47. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
  48. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +286 -174
  49. metadata +31 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ca3aedd38f18114d3fb4c86c797294a3f1fb4fced3dbe22141980ad899df051
4
- data.tar.gz: b885be1a706d741781853f85df50fe988b9ed93d31f15f6458c3f8debe8ab704
3
+ metadata.gz: b74869d08fd6dece972c8a91e6d3bee248f3cd1f8f6dbf5ce1280358be4a6e27
4
+ data.tar.gz: d3d41f3fc77fead3848808777fcfaf09c20baa24a3aebdde2ace278fcbb44cfd
5
5
  SHA512:
6
- metadata.gz: b679c9834b6a85dcbbb743a50f4fe4cae499cf6bc8f6bebe2c58545bc09b282fe2c529068fa8db2a3027023f983f6b589a1b1883b356f18710d34cbdf8e13ce4
7
- data.tar.gz: 583bc49e6a03656378f097a2acfa91578699d04be365bd92e3515b0252a940104efddf778ef79784fa27e06997345505a8527c530a86cdeaf3d13c78cc644e1f
6
+ metadata.gz: da9c7ea38fa9545e6657d178296a7c022a4ab460ba8ea31a9e34b188e7be5451c2ff6e4e202767f4ca57a1548803744f7bdec6bac1b1a1684429fe2b66be1118
7
+ data.tar.gz: 2e67fb7b6f31ca587c37855d65ede4ef7ea3c9153eedce5a00f7003312b20cb87821060ecf4abdc3637a6aaa5899847659c153491e18a1e2fce81d7dd320bd8b
@@ -36,7 +36,7 @@ jobs:
36
36
  with:
37
37
  ruby-version: ${{ matrix.ruby }}
38
38
 
39
- - uses: actions/cache@v1
39
+ - uses: actions/cache@v2
40
40
  with:
41
41
  path: vendor/bundle
42
42
  key: bundle-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}
@@ -94,12 +94,10 @@ module Asciidoctor
94
94
  @draft = node.attributes.has_key?("draft")
95
95
  @novalid = node.attr("novalid")
96
96
  @smartquotes = node.attr("smartquotes") != "false"
97
- @keepasciimath = node.attr("mn-keep-asciimath") &&
98
- node.attr("mn-keep-asciimath") != "false"
97
+ @keepasciimath = node.attr("mn-keep-asciimath") && node.attr("mn-keep-asciimath") != "false"
99
98
  @fontheader = default_fonts(node)
100
99
  @files_to_delete = []
101
- @filename = node.attr("docfile") ?
102
- File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : ""
100
+ @filename = node.attr("docfile") ? File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : ""
103
101
  @localdir = Utils::localdir(node)
104
102
  @output_dir = outputdir node
105
103
  @no_isobib_cache = node.attr("no-isobib-cache")
@@ -119,11 +117,9 @@ module Asciidoctor
119
117
 
120
118
  def default_fonts(node)
121
119
  b = node.attr("body-font") ||
122
- (node.attr("script") == "Hans" ? '"SimSun",serif' :
123
- '"Cambria",serif')
120
+ (node.attr("script") == "Hans" ? '"SimSun",serif' : '"Cambria",serif')
124
121
  h = node.attr("header-font") ||
125
- (node.attr("script") == "Hans" ? '"SimHei",sans-serif' :
126
- '"Cambria",serif')
122
+ (node.attr("script") == "Hans" ? '"SimHei",sans-serif' : '"Cambria",serif')
127
123
  m = node.attr("monospace-font") || '"Courier New",monospace'
128
124
  "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
129
125
  end
@@ -154,8 +150,7 @@ module Asciidoctor
154
150
  end
155
151
 
156
152
  def makexml1(node)
157
- result = ["<?xml version='1.0' encoding='UTF-8'?>",
158
- "<#{xml_root_tag} type='semantic' version='#{version}'>"]
153
+ result = ["<?xml version='1.0' encoding='UTF-8'?>", "<#{xml_root_tag} type='semantic' version='#{version}'>"]
159
154
  result << noko { |ixml| front node, ixml }
160
155
  result << noko { |ixml| middle node, ixml }
161
156
  result << "</#{xml_root_tag}>"
@@ -192,16 +187,14 @@ module Asciidoctor
192
187
 
193
188
  def term_source_attrs(seen_xref)
194
189
  { bibitemid: seen_xref.children[0]["target"],
195
- format: seen_xref.children[0]["format"],
196
- type: "inline" }
190
+ format: seen_xref.children[0]["format"], type: "inline" }
197
191
  end
198
192
 
199
193
  def add_term_source(xml_t, seen_xref, m)
200
194
  if seen_xref.children[0].name == "concept"
201
195
  xml_t.origin { |o| o << seen_xref.children[0].to_xml }
202
196
  else
203
- xml_t.origin seen_xref.children[0].content,
204
- **attr_code(term_source_attrs(seen_xref))
197
+ xml_t.origin seen_xref.children[0].content, **attr_code(term_source_attrs(seen_xref))
205
198
  end
206
199
  m[:text] && xml_t.modification do |mod|
207
200
  mod.p { |p| p << m[:text].sub(/^\s+/, "") }
@@ -219,8 +212,7 @@ module Asciidoctor
219
212
 
220
213
  def extract_termsource_refs(text, node)
221
214
  matched = TERM_REFERENCE_RE.match text
222
- matched.nil? and
223
- @log.add("AsciiDoc Input", node, "term reference not in expected format: #{text}")
215
+ matched.nil? and @log.add("AsciiDoc Input", node, "term reference not in expected format: #{text}")
224
216
  matched
225
217
  end
226
218
 
@@ -596,6 +596,7 @@
596
596
  <ref name="bookmark"/>
597
597
  <ref name="image"/>
598
598
  <ref name="index"/>
599
+ <ref name="index-xref"/>
599
600
  </choice>
600
601
  </define>
601
602
  <define name="PureTextElement">
@@ -728,15 +729,61 @@
728
729
  </define>
729
730
  <define name="index">
730
731
  <element name="index">
731
- <attribute name="primary"/>
732
+ <attribute name="to">
733
+ <data type="IDREF"/>
734
+ </attribute>
735
+ <element name="primary">
736
+ <oneOrMore>
737
+ <ref name="PureTextElement"/>
738
+ </oneOrMore>
739
+ </element>
732
740
  <optional>
733
- <attribute name="secondary"/>
741
+ <element name="secondary">
742
+ <oneOrMore>
743
+ <ref name="PureTextElement"/>
744
+ </oneOrMore>
745
+ </element>
734
746
  </optional>
735
747
  <optional>
736
- <attribute name="tertiary"/>
748
+ <element name="tertiary">
749
+ <oneOrMore>
750
+ <ref name="PureTextElement"/>
751
+ </oneOrMore>
752
+ </element>
737
753
  </optional>
738
754
  </element>
739
755
  </define>
756
+ <define name="index-xref">
757
+ <element name="index-xref">
758
+ <attribute name="also">
759
+ <data type="boolean"/>
760
+ </attribute>
761
+ <element name="primary">
762
+ <oneOrMore>
763
+ <ref name="PureTextElement"/>
764
+ </oneOrMore>
765
+ </element>
766
+ <optional>
767
+ <element name="secondary">
768
+ <oneOrMore>
769
+ <ref name="PureTextElement"/>
770
+ </oneOrMore>
771
+ </element>
772
+ </optional>
773
+ <optional>
774
+ <element name="tertiary">
775
+ <oneOrMore>
776
+ <ref name="PureTextElement"/>
777
+ </oneOrMore>
778
+ </element>
779
+ </optional>
780
+ <element name="target">
781
+ <oneOrMore>
782
+ <ref name="PureTextElement"/>
783
+ </oneOrMore>
784
+ </element>
785
+ </element>
786
+ </define>
740
787
  <!-- bare ID element, used for referencing arbitrary spans of text -->
741
788
  <define name="bookmark">
742
789
  <element name="bookmark">
@@ -176,7 +176,7 @@ module Asciidoctor
176
176
 
177
177
  # presuppose multichar mi upright, singlechar mi MathML default italic
178
178
  def mathml_italicise(x)
179
- x.xpath(".//m:mi", "m" => MATHML_NS).each do |i|
179
+ x.xpath(".//m:mi[not(ancestor::*[@mathvariant])]", "m" => MATHML_NS).each do |i|
180
180
  char = HTMLEntities.new.decode(i.text)
181
181
  i["mathvariant"] = "normal" if mi_italicise?(char)
182
182
  end
@@ -3,14 +3,12 @@ module Asciidoctor
3
3
  module Cleanup
4
4
  def external_terms_boilerplate(sources)
5
5
  @i18n.l10n(
6
- @i18n.external_terms_boilerplate.gsub(/%/, sources || "???"),
7
- @lang, @script)
6
+ @i18n.external_terms_boilerplate.gsub(/%/, sources || "???"), @lang, @script)
8
7
  end
9
8
 
10
9
  def internal_external_terms_boilerplate(sources)
11
10
  @i18n.l10n(
12
- @i18n.internal_external_terms_boilerplate.gsub(/%/, sources || "??"),
13
- @lang, @script)
11
+ @i18n.internal_external_terms_boilerplate.gsub(/%/, sources || "??"), @lang, @script)
14
12
  end
15
13
 
16
14
  def term_defs_boilerplate(div, source, term, preface, isodoc)
@@ -19,11 +17,9 @@ module Asciidoctor
19
17
  @anchors[s["bibitemid"]] or
20
18
  @log.add("Crossreferences", nil, "term source #{s['bibitemid']} not referenced")
21
19
  end
22
- if source.empty? && term.nil?
23
- div.next = @i18n.no_terms_boilerplate
24
- else
25
- div.next = term_defs_boilerplate_cont(source, term, isodoc)
26
- end
20
+ a = (source.empty? && term.nil?) ? @i18n.no_terms_boilerplate :
21
+ term_defs_boilerplate_cont(source, term, isodoc)
22
+ a and div.next = a
27
23
  end
28
24
 
29
25
  def term_defs_boilerplate_cont(src, term, isodoc)
@@ -38,15 +34,14 @@ module Asciidoctor
38
34
  end
39
35
 
40
36
  def norm_ref_preface(f)
41
- refs = f.elements.select do |e|
42
- ["reference", "bibitem"].include? e.name
37
+ refs = f.elements.select do |e|
38
+ ["reference", "bibitem"].include? e.name
39
+ end
40
+ f.at("./title").next =
41
+ "<p>#{(refs.empty? ? @i18n.norm_empty_pref : @i18n.norm_with_refs_pref)}</p>"
43
42
  end
44
- f.at("./title").next =
45
- "<p>#{(refs.empty? ? @i18n.norm_empty_pref : @i18n.norm_with_refs_pref)}</p>"
46
- end
47
43
 
48
- TERM_CLAUSE = "//sections/terms | "\
49
- "//sections/clause[descendant::terms]".freeze
44
+ TERM_CLAUSE = "//sections/terms | //sections/clause[descendant::terms]".freeze
50
45
 
51
46
  NORM_REF = "//bibliography/references[@normative = 'true']".freeze
52
47
 
@@ -59,15 +54,33 @@ module Asciidoctor
59
54
  @isodoc
60
55
  end
61
56
 
57
+ def termdef_boilerplate_cleanup(xmldoc)
58
+ #termdef_remove_initial_paras(xmldoc)
59
+ end
60
+
61
+ def termdef_remove_initial_paras(xmldoc)
62
+ xmldoc.xpath("//terms/p | //terms/ul").each(&:remove)
63
+ end
64
+
65
+ def termdef_unwrap_boilerplate_clauses(xmldoc)
66
+ xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
67
+ f.xpath(".//clause[@type = 'boilerplate']").each do |c|
68
+ c&.at("./title")&.remove
69
+ c.replace(c.children)
70
+ end
71
+ end
72
+ end
73
+
62
74
  def boilerplate_cleanup(xmldoc)
63
75
  isodoc = boilerplate_isodoc(xmldoc)
76
+ termdef_boilerplate_cleanup(xmldoc)
64
77
  xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
65
- term_defs_boilerplate(f.at("./title"),
66
- xmldoc.xpath(".//termdocsource"),
78
+ next if f.at("./clause[@type = 'boilerplate']")
79
+ term_defs_boilerplate(f.at("./title"), xmldoc.xpath(".//termdocsource"),
67
80
  f.at(".//term"), f.at(".//p"), isodoc)
68
81
  end
69
- f = xmldoc.at(self.class::NORM_REF) and
70
- norm_ref_preface(f)
82
+ termdef_unwrap_boilerplate_clauses(xmldoc)
83
+ f = xmldoc.at(self.class::NORM_REF) and norm_ref_preface(f)
71
84
  initial_boilerplate(xmldoc, isodoc)
72
85
  end
73
86
 
@@ -82,7 +82,21 @@ module Asciidoctor
82
82
  end
83
83
  end
84
84
 
85
+ def footnote_block_cleanup(xmldoc)
86
+ xmldoc.xpath("//footnoteblock").each do |f|
87
+ f.name = 'fn'
88
+ if id = xmldoc.at("//*[@id = '#{f.text}']")
89
+ f.children = id.remove.children
90
+ else
91
+ @log.add("Crossreferences", f,
92
+ "Could not resolve footnoteblock:[#{f.text}]")
93
+ f.children = "[ERROR]"
94
+ end
95
+ end
96
+ end
97
+
85
98
  def footnote_cleanup(xmldoc)
99
+ footnote_block_cleanup(xmldoc)
86
100
  title_footnote_move(xmldoc)
87
101
  table_footnote_renumber(xmldoc)
88
102
  other_footnote_renumber(xmldoc)
@@ -125,7 +125,7 @@ module Asciidoctor
125
125
  def concept_termbase_cleanup(x)
126
126
  text = x&.children&.first&.remove&.text
127
127
  termbase, key = x["key"].split(/:/, 2)
128
- x.add_child(%(<termref base="#{termbase}" target="#{key}">) +
128
+ x.add_child(%(<termref base="#{termbase}" target="#{key}">) +
129
129
  "#{text}</termref>")
130
130
  end
131
131
 
@@ -155,6 +155,8 @@ module Asciidoctor
155
155
  ret
156
156
  end
157
157
 
158
+ module_function :to_ncname
159
+
158
160
  def to_xreftarget(s)
159
161
  return to_ncname(s) unless /^[^#]+#.+$/.match(s)
160
162
  /^(?<pref>[^#]+)#(?<suff>.+)$/ =~ s
@@ -16,8 +16,7 @@ module Asciidoctor
16
16
  insert = refs&.at("./bibitem")&.previous_element
17
17
  refs.xpath("./bibitem").each { |b| b.remove }
18
18
  bib.reverse.each do |b|
19
- insert and insert.next = b.to_xml or
20
- refs.children.first.add_previous_sibling b.to_xml
19
+ insert and insert.next = b.to_xml or refs.children.first.add_previous_sibling b.to_xml
21
20
  end
22
21
  extract_notes_from_biblio(refs)
23
22
  refs.xpath("./references").each { |r| biblio_reorder1(r) }
@@ -49,12 +48,14 @@ module Asciidoctor
49
48
  # consecutively, but that standards codes are preserved as is:
50
49
  # only numeric references are renumbered
51
50
  def biblio_renumber(xmldoc)
52
- r = xmldoc.at("//references | //clause[.//references] | "\
53
- "//annex[.//references]") or return
54
- r.xpath(".//bibitem[not(ancestor::bibitem)]").each_with_index do |b, i|
55
- next unless docid = b.at("./docidentifier[@type = 'metanorma']")
56
- next unless /^\[\d+\]$/.match(docid.text)
57
- docid.children = "[#{i + 1}]"
51
+ i = 0
52
+ xmldoc.xpath("//bibliography//references | //clause//references | //annex//references").each do |r|
53
+ r.xpath("./bibitem").each do |b|
54
+ i += 1
55
+ next unless docid = b.at("./docidentifier[@type = 'metanorma']")
56
+ next unless /^\[\d+\]$/.match(docid.text)
57
+ docid.children = "[#{i}]"
58
+ end
58
59
  end
59
60
  end
60
61
 
@@ -123,8 +124,7 @@ module Asciidoctor
123
124
  xmldoc.xpath("//clause[@bibitem = 'true']").each do |c|
124
125
  bib = dl_bib_extract(c) or next
125
126
  validate_ref_dl(bib, c)
126
- bibitemxml = RelatonBib::BibliographicItem.new(
127
- RelatonBib::HashConverter::hash_to_bib(bib)).to_xml or next
127
+ bibitemxml = RelatonBib::BibliographicItem.new(RelatonBib::HashConverter::hash_to_bib(bib)).to_xml or next
128
128
  bibitem = Nokogiri::XML(bibitemxml)
129
129
  bibitem.root["id"] = c["id"] if c["id"] && !/^_/.match(c["id"])
130
130
  c.replace(bibitem.root)
@@ -135,14 +135,11 @@ module Asciidoctor
135
135
  id = bib["id"]
136
136
  id ||= c["id"] unless /^_/.match(c["id"]) # do not accept implicit id
137
137
  unless id
138
- @log.add("Anchors", c, "The following reference is missing "\
139
- "an anchor:\n" + c.to_xml)
138
+ @log.add("Anchors", c, "The following reference is missing an anchor:\n" + c.to_xml)
140
139
  return
141
140
  end
142
- bib["title"] or @log.add("Bibliography", c, "Reference #{id} "\
143
- "is missing a title")
144
- bib["docid"] or @log.add("Bibliography", c, "Reference #{id} "\
145
- "is missing a document identifier (docid)")
141
+ bib["title"] or @log.add("Bibliography", c, "Reference #{id} is missing a title")
142
+ bib["docid"] or @log.add("Bibliography", c, "Reference #{id} is missing a document identifier (docid)")
146
143
  end
147
144
 
148
145
  def extract_from_p(tag, bib, key)
@@ -173,8 +170,7 @@ module Asciidoctor
173
170
  return nil if dtd.children.empty?
174
171
  dtd.at("./dl") and return dl_bib_extract(dtd)
175
172
  elems = dtd.remove.elements
176
- return p_unwrap(dtd) unless elems.size == 1 &&
177
- %w(ol ul).include?(elems[0].name)
173
+ return p_unwrap(dtd) unless elems.size == 1 && %w(ol ul).include?(elems[0].name)
178
174
  ret = []
179
175
  elems[0].xpath("./li").each do |li|
180
176
  ret << p_unwrap(li)
@@ -192,8 +188,7 @@ module Asciidoctor
192
188
  bib = {}
193
189
  key = ""
194
190
  dl.xpath("./dt | ./dd").each do |dtd|
195
- dtd.name == "dt" and key = dtd.text.sub(/:+$/, "") or
196
- add_to_hash(bib, key, dd_bib_extract(dtd))
191
+ dtd.name == "dt" and key = dtd.text.sub(/:+$/, "") or add_to_hash(bib, key, dd_bib_extract(dtd))
197
192
  end
198
193
  c.xpath("./clause").each do |c1|
199
194
  key = c1&.at("./title")&.text&.downcase&.strip
@@ -221,8 +216,7 @@ module Asciidoctor
221
216
  File.file?(file) or return nil
222
217
  xml = Nokogiri::XML(File.read(file, encoding: "utf-8"))
223
218
  ret = xml.at("//*[local-name() = 'bibdata']") or return nil
224
- ret = Nokogiri::XML(ret.to_xml.sub(
225
- %r{(<bibdata[^>]*?) xmlns=("[^"]+"|'[^']+')}, "\\1")).root
219
+ ret = Nokogiri::XML(ret.to_xml.sub(%r{(<bibdata[^>]*?) xmlns=("[^"]+"|'[^']+')}, "\\1")).root
226
220
  ret.name = "bibitem"
227
221
  ins = ret.at("./*[local-name() = 'docidentifier']") or return nil
228
222
  ins.previous = %{<uri type="citation">#{uri}</uri>}
@@ -232,8 +226,7 @@ module Asciidoctor
232
226
 
233
227
  # if citation uri points to local file, get bibitem from it
234
228
  def fetch_local_bibitem(xmldoc)
235
- xmldoc.xpath("//bibitem[formattedref]"\
236
- "[uri[@type = 'citation']]").each do |b|
229
+ xmldoc.xpath("//bibitem[formattedref][uri[@type = 'citation']]").each do |b|
237
230
  uri = b&.at("./uri[@type = 'citation']")&.text
238
231
  bibitem = read_local_bibitem(uri) or next
239
232
  bibitem["id"] = b["id"]
@@ -1,3 +1,5 @@
1
+ require_relative "term_lookup_cleanup"
2
+
1
3
  module Asciidoctor
2
4
  module Standoc
3
5
  module Cleanup
@@ -45,10 +47,6 @@ module Asciidoctor
45
47
  end
46
48
  end
47
49
 
48
- def termdef_boilerplate_cleanup(xmldoc)
49
- xmldoc.xpath("//terms/p | //terms/ul").each(&:remove)
50
- end
51
-
52
50
  def termdef_subclause_cleanup(xmldoc)
53
51
  xmldoc.xpath("//terms[terms]").each { |t| t.name = "clause" }
54
52
  end
@@ -81,11 +79,12 @@ module Asciidoctor
81
79
  x.name = "note"
82
80
  end
83
81
  xmldoc.xpath("//termexample[not(ancestor::term)]").each do |x|
84
- x.name = "note"
82
+ x.name = "example"
85
83
  end
86
84
  end
87
85
 
88
86
  def termdef_cleanup(xmldoc)
87
+ Asciidoctor::Standoc::TermLookupCleanup.new(xmldoc, @log).call
89
88
  termdef_from_termbase(xmldoc)
90
89
  termdef_unnest_cleanup(xmldoc)
91
90
  termdef_stem_cleanup(xmldoc)
@@ -93,7 +92,6 @@ module Asciidoctor
93
92
  termdefinition_cleanup(xmldoc)
94
93
  termdomain1_cleanup(xmldoc)
95
94
  termnote_example_cleanup(xmldoc)
96
- termdef_boilerplate_cleanup(xmldoc)
97
95
  termdef_subclause_cleanup(xmldoc)
98
96
  term_children_cleanup(xmldoc)
99
97
  termdocsource_cleanup(xmldoc)
@@ -1,4 +1,7 @@
1
1
  require "asciidoctor"
2
+ require "fontist"
3
+ require "fontist/manifest/install"
4
+ require "metanorma/util"
2
5
  require "metanorma/standoc/version"
3
6
  require "asciidoctor/standoc/base"
4
7
  require "asciidoctor/standoc/front"
@@ -26,6 +29,7 @@ module Asciidoctor
26
29
  preprocessor Metanorma::Plugin::Datastruct::Json2TextPreprocessor
27
30
  preprocessor Metanorma::Plugin::Datastruct::Yaml2TextPreprocessor
28
31
  preprocessor Metanorma::Plugin::Lutaml::LutamlPreprocessor
32
+ preprocessor Metanorma::Plugin::Lutaml::LutamlUmlAttributesTablePreprocessor
29
33
  inline_macro Asciidoctor::Standoc::AltTermInlineMacro
30
34
  inline_macro Asciidoctor::Standoc::DeprecatedTermInlineMacro
31
35
  inline_macro Asciidoctor::Standoc::DomainTermInlineMacro
@@ -34,9 +38,14 @@ module Asciidoctor
34
38
  inline_macro Asciidoctor::Standoc::ConceptInlineMacro
35
39
  inline_macro Asciidoctor::Standoc::AutonumberInlineMacro
36
40
  inline_macro Asciidoctor::Standoc::VariantInlineMacro
41
+ inline_macro Asciidoctor::Standoc::FootnoteBlockInlineMacro
42
+ inline_macro Asciidoctor::Standoc::TermRefInlineMacro
43
+ inline_macro Asciidoctor::Standoc::IndexXrefInlineMacro
44
+ inline_macro Asciidoctor::Standoc::IndexRangeInlineMacro
37
45
  block Asciidoctor::Standoc::ToDoAdmonitionBlock
38
46
  treeprocessor Asciidoctor::Standoc::ToDoInlineAdmonitionBlock
39
47
  block Asciidoctor::Standoc::PlantUMLBlockMacro
48
+ block Metanorma::Plugin::Lutaml::LutamlDiagramBlock
40
49
  block Asciidoctor::Standoc::PseudocodeBlockMacro
41
50
  end
42
51
 
@@ -46,6 +55,7 @@ module Asciidoctor
46
55
  include ::Asciidoctor::Standoc::Base
47
56
  include ::Asciidoctor::Standoc::Front
48
57
  include ::Asciidoctor::Standoc::Lists
58
+ include ::Asciidoctor::Standoc::Refs
49
59
  include ::Asciidoctor::Standoc::Inline
50
60
  include ::Asciidoctor::Standoc::Blocks
51
61
  include ::Asciidoctor::Standoc::Section
@@ -63,6 +73,8 @@ module Asciidoctor
63
73
  basebackend "html"
64
74
  outfilesuffix ".xml"
65
75
  @libdir = File.dirname(self.class::_file || __FILE__)
76
+
77
+ install_fonts(opts)
66
78
  end
67
79
 
68
80
  class << self
@@ -75,7 +87,79 @@ module Asciidoctor
75
87
 
76
88
  # path to isodoc assets in child gems
77
89
  def html_doc_path(file)
78
- File.join(@libdir, File.join("../../isodoc/html", file))
90
+ File.join(@libdir, "../../isodoc/html", file)
91
+ end
92
+
93
+ def flavor_name
94
+ self.class.name.split("::")&.[](-2)&.downcase&.to_sym
95
+ end
96
+
97
+ def fonts_manifest
98
+ flavor = flavor_name
99
+ registry = Metanorma::Registry.instance
100
+ processor = registry.find_processor(flavor)
101
+
102
+ if processor.nil?
103
+ Metanorma::Util.log("[fontist] #{flavor} processor not found. " \
104
+ "Please go to github.com/metanorma/metanorma/issues to report " \
105
+ "this issue.", :warn)
106
+ return nil
107
+ elsif !defined? processor.fonts_manifest
108
+ Metanorma::Util.log("[fontist] #{flavor} processor don't require " \
109
+ "specific fonts", :debug)
110
+ return nil
111
+ end
112
+
113
+ processor.fonts_manifest
114
+ end
115
+
116
+ def install_fonts(options={})
117
+ if options[:no_install_fonts]
118
+ Metanorma::Util.log("[fontist] Skip font installation because" \
119
+ " --no-install-fonts argument passed", :debug)
120
+ return
121
+ end
122
+
123
+ manifest = fonts_manifest
124
+ return if manifest.nil?
125
+
126
+ agree_to_terms = options[:agree_to_terms]
127
+ continue_without_fonts = options[:continue_without_fonts]
128
+
129
+ install_fonts_safe(manifest, agree_to_terms, continue_without_fonts)
130
+ end
131
+
132
+ def install_fonts_safe(manifest, agree, continue)
133
+ begin
134
+ fontist_install(manifest, agree)
135
+ rescue Fontist::Errors::LicensingError
136
+ if !confirm
137
+ Metanorma::Util.log("[fontist] --agree-to-terms option missing." \
138
+ " You must accept font licenses to install fonts.", :debug)
139
+ elsif continue
140
+ Metanorma::Util.log("[fontist] Processing will continue without" \
141
+ " fonts installed", :debug)
142
+ else
143
+ Metanorma::Util.log("[fontist] Aborting without proper fonts" \
144
+ " installed", :fatal)
145
+ end
146
+ rescue Fontist::Errors::NonSupportedFontError => e
147
+ font = /Font '([^']+)'/.match(e.to_s)[1]
148
+ Metanorma::Util.log("[fontist] '#{font}' font is not supported. " \
149
+ "Please go to github.com/metanorma/metanorma-#{flavor_name}/issues" \
150
+ " to report this issue.", :info)
151
+ rescue Fontist::Errors::FormulaIndexNotFoundError
152
+ Metanorma::Util.log("[fontist] Missing formula index. Fetching it...", :debug)
153
+ Fontist::Formula.update_formulas_repo
154
+ fontist_install(manifest, agree)
155
+ end
156
+ end
157
+
158
+ def fontist_install(manifest, agree)
159
+ Fontist::Manifest::Install.from_hash(
160
+ manifest,
161
+ confirmation: agree ? "yes" : "no"
162
+ )
79
163
  end
80
164
 
81
165
  alias_method :embedded, :content