Class: Metanorma::Standoc::HTML5RubyMacro

Inherits:
Asciidoctor::Extensions::InlineMacroProcessor
  • Object
show all
Defined in:
lib/metanorma/standoc/macros_inline.rb

Instance Method Summary collapse

Instance Method Details

#preprocess_attrs(text) ⇒ Object

ruby:annotation



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/metanorma/standoc/macros_inline.rb', line 24

def preprocess_attrs(text)
  ret = {}
  while m = /^(?<key>lang|script|type)=(?<val>[^,]+),(?<rest>.+)$/
      .match(text)
    text = m[:rest]
    ret[m[:key].to_sym] = m[:val]
  end
  ret[:text] = text
  ret[:type] ||= "pronunciation"
  ret[:type] == "annotation" or ret[:type] = "pronunciation"
  ret
end

#process(parent, target, attributes) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/metanorma/standoc/macros_inline.rb', line 37

def process(parent, target, attributes)
  args = preprocess_attrs(attributes["text"])
  out = Nokogiri::XML(
    create_block(parent, :paragraph, [args[:text]], {},
                 subs: [:macros], content_model: :simple).convert,
  ).root.children.to_xml # force recurse macros
  attrs = " value='#{target}'"
  x = args[:lang] and attrs += " lang='#{x}'"
  x = args[:script] and attrs += " script='#{x}'"
  "<ruby><#{args[:type]} #{attrs}/>#{out}</ruby>"
end