metanorma-standoc 1.6.4 → 1.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asciidoctor/standoc/base.rb +8 -16
  3. data/lib/asciidoctor/standoc/basicdoc.rng +32 -0
  4. data/lib/asciidoctor/standoc/cleanup.rb +1 -1
  5. data/lib/asciidoctor/standoc/cleanup_ref.rb +17 -24
  6. data/lib/asciidoctor/standoc/cleanup_terms.rb +3 -0
  7. data/lib/asciidoctor/standoc/converter.rb +3 -0
  8. data/lib/asciidoctor/standoc/isodoc.rng +15 -0
  9. data/lib/asciidoctor/standoc/macros.rb +19 -63
  10. data/lib/asciidoctor/standoc/macros_terms.rb +82 -0
  11. data/lib/asciidoctor/standoc/ref.rb +12 -21
  12. data/lib/asciidoctor/standoc/table.rb +12 -0
  13. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +86 -0
  14. data/lib/metanorma/standoc/version.rb +1 -1
  15. data/spec/asciidoctor-standoc/blocks_spec.rb +8 -8
  16. data/spec/asciidoctor-standoc/cleanup_sections_spec.rb +6 -6
  17. data/spec/asciidoctor-standoc/cleanup_spec.rb +70 -9
  18. data/spec/asciidoctor-standoc/macros_plantuml_spec.rb +307 -0
  19. data/spec/asciidoctor-standoc/macros_spec.rb +228 -277
  20. data/spec/asciidoctor-standoc/section_spec.rb +11 -11
  21. data/spec/asciidoctor-standoc/table_spec.rb +86 -0
  22. data/spec/fixtures/diagram_definitions.lutaml +4 -4
  23. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +49 -49
  24. data/spec/vcr_cassettes/isobib_get_123.yml +14 -14
  25. data/spec/vcr_cassettes/isobib_get_123_1.yml +28 -28
  26. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +37 -37
  27. data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -14
  28. data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
  29. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
  30. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +51 -61
  31. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e30bd97d527914e60d6dfcd537620ba7d2d5ae82d9d9c07e24d5a535dd9ec8ee
4
- data.tar.gz: b8774965fcb7e698288f1793460fd67b982085e8d0951b35cfa6c4f102157e9a
3
+ metadata.gz: 5f510c7d84985eb301f3bfe71f4ebe89f39961a6b9ec113a9e019537056e3933
4
+ data.tar.gz: a0844efae9739bfd19ab8263dd9a5b1edff6883b443f5c7fb399a056cd528bfa
5
5
  SHA512:
6
- metadata.gz: 74e250a48b25dd82c3174b78b515e57fe11bc3f4f8767d6942048bb3ef01ddf6937a6c2ff24ddb5e17d8f747eeb582b77248b28bdf50bc120a3fcfafd6f78221
7
- data.tar.gz: a0fe35b39a730d18afe1cc7463b166377adb2137c4cfd9c650844e3a593e1a2312fa8242a8991a1508aaed44b7b7525a54cad7f747a177ea2848b27720cf644d
6
+ metadata.gz: f9fa2f578c9b742860c5464141a2efbe1d565061148e0aa701520cfe8cfe0ef0828c46ffa21883d893190af37efc7c31a792d4a11a6c8775a43ca6bae6b08aa9
7
+ data.tar.gz: 63a79d788f62977472a2ff3c21d1926dfb52b43722092f82f721cbcfb8748caba1adec96fb3062c02dab8fb7d74b9dc691bcb70dca9f91121d778122444158bc
@@ -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">
@@ -737,6 +738,37 @@
737
738
  </optional>
738
739
  </element>
739
740
  </define>
741
+ <define name="index-xref">
742
+ <element name="index-xref">
743
+ <attribute name="also">
744
+ <data type="boolean"/>
745
+ </attribute>
746
+ <element name="primary">
747
+ <oneOrMore>
748
+ <ref name="PureTextElement"/>
749
+ </oneOrMore>
750
+ </element>
751
+ <optional>
752
+ <element name="secondary">
753
+ <oneOrMore>
754
+ <ref name="PureTextElement"/>
755
+ </oneOrMore>
756
+ </element>
757
+ </optional>
758
+ <optional>
759
+ <element name="tertiary">
760
+ <oneOrMore>
761
+ <ref name="PureTextElement"/>
762
+ </oneOrMore>
763
+ </element>
764
+ </optional>
765
+ <element name="target">
766
+ <oneOrMore>
767
+ <ref name="PureTextElement"/>
768
+ </oneOrMore>
769
+ </element>
770
+ </element>
771
+ </define>
740
772
  <!-- bare ID element, used for referencing arbitrary spans of text -->
741
773
  <define name="bookmark">
742
774
  <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
@@ -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
@@ -86,6 +88,7 @@ module Asciidoctor
86
88
  end
87
89
 
88
90
  def termdef_cleanup(xmldoc)
91
+ Asciidoctor::Standoc::TermLookupCleanup.new(xmldoc, @log).call
89
92
  termdef_from_termbase(xmldoc)
90
93
  termdef_unnest_cleanup(xmldoc)
91
94
  termdef_stem_cleanup(xmldoc)
@@ -39,6 +39,8 @@ module Asciidoctor
39
39
  inline_macro Asciidoctor::Standoc::AutonumberInlineMacro
40
40
  inline_macro Asciidoctor::Standoc::VariantInlineMacro
41
41
  inline_macro Asciidoctor::Standoc::FootnoteBlockInlineMacro
42
+ inline_macro Asciidoctor::Standoc::TermRefInlineMacro
43
+ inline_macro Asciidoctor::Standoc::IndexInlineMacro
42
44
  block Asciidoctor::Standoc::ToDoAdmonitionBlock
43
45
  treeprocessor Asciidoctor::Standoc::ToDoInlineAdmonitionBlock
44
46
  block Asciidoctor::Standoc::PlantUMLBlockMacro
@@ -52,6 +54,7 @@ module Asciidoctor
52
54
  include ::Asciidoctor::Standoc::Base
53
55
  include ::Asciidoctor::Standoc::Front
54
56
  include ::Asciidoctor::Standoc::Lists
57
+ include ::Asciidoctor::Standoc::Refs
55
58
  include ::Asciidoctor::Standoc::Inline
56
59
  include ::Asciidoctor::Standoc::Blocks
57
60
  include ::Asciidoctor::Standoc::Section
@@ -246,6 +246,9 @@
246
246
  <data type="boolean"/>
247
247
  </attribute>
248
248
  </optional>
249
+ <optional>
250
+ <ref name="colgroup"/>
251
+ </optional>
249
252
  <optional>
250
253
  <ref name="tname"/>
251
254
  </optional>
@@ -764,6 +767,18 @@
764
767
  </define>
765
768
  </include>
766
769
  <!-- end overrides -->
770
+ <define name="colgroup">
771
+ <element name="colgroup">
772
+ <oneOrMore>
773
+ <ref name="col"/>
774
+ </oneOrMore>
775
+ </element>
776
+ </define>
777
+ <define name="col">
778
+ <element name="col">
779
+ <attribute name="width"/>
780
+ </element>
781
+ </define>
767
782
  <define name="TextElement" combine="choice">
768
783
  <ref name="concept"/>
769
784
  </define>
@@ -3,6 +3,7 @@ require "fileutils"
3
3
  require "uuidtools"
4
4
  require "yaml"
5
5
  require_relative "./macros_plantuml.rb"
6
+ require_relative "./macros_terms.rb"
6
7
  require_relative "./datamodel/attributes_table_preprocessor.rb"
7
8
  require_relative "./datamodel/diagram_preprocessor.rb"
8
9
  require "metanorma-plugin-datastruct"
@@ -10,42 +11,6 @@ require "metanorma-plugin-lutaml"
10
11
 
11
12
  module Asciidoctor
12
13
  module Standoc
13
- class AltTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
14
- use_dsl
15
- named :alt
16
- parse_content_as :text
17
- using_format :short
18
-
19
- def process(parent, _target, attrs)
20
- out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
21
- %{<admitted>#{out}</admitted>}
22
- end
23
- end
24
-
25
- class DeprecatedTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
26
- use_dsl
27
- named :deprecated
28
- parse_content_as :text
29
- using_format :short
30
-
31
- def process(parent, _target, attrs)
32
- out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
33
- %{<deprecates>#{out}</deprecates>}
34
- end
35
- end
36
-
37
- class DomainTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
38
- use_dsl
39
- named :domain
40
- parse_content_as :text
41
- using_format :short
42
-
43
- def process(parent, _target, attrs)
44
- out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
45
- %{<domain>#{out}</domain>}
46
- end
47
- end
48
-
49
14
  class InheritInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
50
15
  use_dsl
51
16
  named :inherit
@@ -58,33 +23,24 @@ module Asciidoctor
58
23
  end
59
24
  end
60
25
 
61
- class ConceptInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
26
+ class IndexInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
62
27
  use_dsl
63
- named :concept
64
- name_positional_attributes "id", "word", "term"
65
- # match %r{concept:(?<target>[^\[]*)\[(?<content>|.*?[^\\])\]$}
66
- match /\{\{(?<content>|.*?[^\\])\}\}/
67
- using_format :short
28
+ named :index
68
29
 
69
- # deal with locality attrs and their disruption of positional attrs
70
30
  def preprocess_attrs(attrs)
71
- attrs.delete("term") if attrs["term"] && !attrs["word"]
72
- attrs.delete(3) if attrs[3] == attrs["term"]
73
- a = attrs.keys.reject { |k| k.is_a?(String) || [1, 2].include?(k) }
74
- attrs["word"] ||= attrs[a[0]] if !a.empty?
75
- attrs["term"] ||= attrs[a[1]] if a.length > 1
76
- attrs
31
+ return unless attrs.size > 1 && attrs.size < 5
32
+ ret = { primary: attrs[1], target: attrs[attrs.size] }
33
+ ret[:secondary] = attrs[2] if attrs.size > 2
34
+ ret[:tertiary] = attrs[3] if attrs.size > 3
35
+ ret
77
36
  end
78
37
 
79
- def process(parent, _target, attr)
80
- attr = preprocess_attrs(attr)
81
- localities = attr.keys.reject { |k| %w(id word term).include? k }.
82
- reject { |k| k.is_a? Numeric }.
83
- map { |k| "#{k}=#{attr[k]}" }.join(",")
84
- text = [localities, attr["word"]].reject{ |k| k.nil? || k.empty? }.
85
- join(",")
86
- out = Asciidoctor::Inline.new(parent, :quoted, text).convert
87
- %{<concept key="#{attr['id']}" term="#{attr['term']}">#{out}</concept>}
38
+ def process(_parent, target, attr)
39
+ args = preprocess_attrs(attr) or return
40
+ ret = "<index-xref also='#{target == 'also'}'><primary>#{args[:primary]}</primary>"
41
+ ret += "<secondary>#{args[:secondary]}</secondary>" if args[:secondary]
42
+ ret += "<tertiary>#{args[:tertiary]}</tertiary>" if args[:tertiary]
43
+ ret + "<target>#{args[:target]}</target></index-xref>"
88
44
  end
89
45
  end
90
46
 
@@ -135,7 +91,7 @@ module Asciidoctor
135
91
  if (attributes.size == 1) && attributes.key?("text")
136
92
  rt = attributes["text"]
137
93
  elsif (attributes.size == 2) && attributes.key?(1) &&
138
- attributes.key?("rpbegin")
94
+ attributes.key?("rpbegin")
139
95
  # for example, html5ruby:楽聖少女[がくせいしょうじょ]
140
96
  rt = attributes[1] || ""
141
97
  else
@@ -158,7 +114,7 @@ module Asciidoctor
158
114
  attrs["name"] = "todo"
159
115
  attrs["caption"] = "TODO"
160
116
  create_block parent, :admonition, reader.lines, attrs,
161
- content_model: :compound
117
+ content_model: :compound
162
118
  end
163
119
  end
164
120
 
@@ -171,7 +127,7 @@ module Asciidoctor
171
127
  para.set_attr("caption", "TODO")
172
128
  para.lines[0].sub!(/^TODO: /, "")
173
129
  todo = Block.new parent, :admonition, attributes: para.attributes,
174
- source: para.lines, content_model: :compound
130
+ source: para.lines, content_model: :compound
175
131
  parent.blocks[parent.blocks.index(para)] = todo
176
132
  end
177
133
  end
@@ -197,8 +153,8 @@ module Asciidoctor
197
153
  /^(?<lang>[^-]*)(-(?<script>.*))?$/ =~ target
198
154
  out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
199
155
  script ?
200
- %{<variant lang=#{lang} script=#{script}>#{out}</variant>} :
201
- %{<variant lang=#{lang}>#{out}</variant>}
156
+ %{<variant lang=#{lang} script=#{script}>#{out}</variant>} :
157
+ %{<variant lang=#{lang}>#{out}</variant>}
202
158
  end
203
159
  end
204
160
 
@@ -0,0 +1,82 @@
1
+ module Asciidoctor
2
+ module Standoc
3
+ class AltTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
4
+ use_dsl
5
+ named :alt
6
+ parse_content_as :text
7
+ using_format :short
8
+
9
+ def process(parent, _target, attrs)
10
+ out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
11
+ %{<admitted>#{out}</admitted>}
12
+ end
13
+ end
14
+
15
+ class DeprecatedTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
16
+ use_dsl
17
+ named :deprecated
18
+ parse_content_as :text
19
+ using_format :short
20
+
21
+ def process(parent, _target, attrs)
22
+ out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
23
+ %{<deprecates>#{out}</deprecates>}
24
+ end
25
+ end
26
+
27
+ class DomainTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
28
+ use_dsl
29
+ named :domain
30
+ parse_content_as :text
31
+ using_format :short
32
+
33
+ def process(parent, _target, attrs)
34
+ out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
35
+ %{<domain>#{out}</domain>}
36
+ end
37
+ end
38
+
39
+ # Macro to transform `term[X,Y]` into em, termxref xml
40
+ class TermRefInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
41
+ use_dsl
42
+ named :term
43
+ name_positional_attributes 'name', 'termxref'
44
+ using_format :short
45
+
46
+ def process(_parent, _target, attrs)
47
+ termref = attrs['termxref'] || attrs['name']
48
+ "<em>#{attrs['name']}</em> (<termxref>#{termref}</termxref>)"
49
+ end
50
+ end
51
+
52
+ class ConceptInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
53
+ use_dsl
54
+ named :concept
55
+ name_positional_attributes "id", "word", "term"
56
+ # match %r{concept:(?<target>[^\[]*)\[(?<content>|.*?[^\\])\]$}
57
+ match /\{\{(?<content>|.*?[^\\])\}\}/
58
+ using_format :short
59
+
60
+ # deal with locality attrs and their disruption of positional attrs
61
+ def preprocess_attrs(attrs)
62
+ attrs.delete("term") if attrs["term"] && !attrs["word"]
63
+ attrs.delete(3) if attrs[3] == attrs["term"]
64
+ a = attrs.keys.reject { |k| k.is_a?(String) || [1, 2].include?(k) }
65
+ attrs["word"] ||= attrs[a[0]] if !a.empty?
66
+ attrs["term"] ||= attrs[a[1]] if a.length > 1
67
+ attrs
68
+ end
69
+
70
+ def process(parent, _target, attr)
71
+ attr = preprocess_attrs(attr)
72
+ localities = attr.keys.reject { |k| %w(id word term).include? k }.
73
+ reject { |k| k.is_a? Numeric }.
74
+ map { |k| "#{k}=#{attr[k]}" }.join(",")
75
+ text = [localities, attr["word"]].reject{ |k| k.nil? || k.empty? }.
76
+ join(",")
77
+ out = Asciidoctor::Inline.new(parent, :quoted, text).convert
78
+ %{<concept key="#{attr['id']}" term="#{attr['term']}">#{out}</concept>}
79
+ end
80
+ end
81
+ end
82
+ end