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



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/metanorma/standoc/macros_inline.rb', line 65

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



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/metanorma/standoc/macros_inline.rb', line 78

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