module Metanorma
module Standoc
class InheritInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
use_dsl
named :inherit
parse_content_as :text
using_format :short
def process(parent, _target, attrs)
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
%{#{out}}
end
end
class IndexXrefInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
use_dsl
named :index
def preprocess_attrs(attrs)
return unless attrs.size > 1 && attrs.size < 5
ret = { primary: attrs[1], target: attrs[attrs.size] }
ret[:secondary] = attrs[2] if attrs.size > 2
ret[:tertiary] = attrs[3] if attrs.size > 3
ret
end
def process(_parent, target, attr)
args = preprocess_attrs(attr) or return
ret = ""\
"#{args[:primary]}"
ret += "#{args[:secondary]}" if args[:secondary]
ret += "#{args[:tertiary]}" if args[:tertiary]
ret + "#{args[:target]}"
end
end
class IndexRangeInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
use_dsl
named :"index-range"
parse_content_as :text
def process(parent, target, attr)
text = attr["text"]
text = "((#{text}))" unless /^\(\(.+\)\)$/.match?(text)
out = parent.sub_macros(text)
out.sub(//, "")
end
end
class HTML5RubyMacro < Asciidoctor::Extensions::InlineMacroProcessor
use_dsl
named :ruby
parse_content_as :text
option :pos_attrs, %w(rpbegin rt rpend)
# for example, html5ruby:楽聖少女[がくせいしょうじょ]
def process(_parent, target, attributes)
rpbegin = "("
rpend = ")"
if (attributes.size == 1) && attributes.key?("text")
rt = attributes["text"]
elsif (attributes.size == 2) && attributes.key?(1) &&
attributes.key?("rpbegin")
rt = attributes[1] || ""
else
rpbegin = attributes["rpbegin"]
rt = attributes["rt"]
rpend = attributes["rpend"]
end
"#{target}"\
""
end
end
class AutonumberInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
use_dsl
named :autonumber
parse_content_as :text
def process(parent, target, attrs)
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
%{#{out}}
end
end
class VariantInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
use_dsl
named :lang
parse_content_as :text
def process(parent, target, attrs)
/^(?[^-]*)(?:-(?