def extract_passthroughs(text)
compat_mode = @document.compat_mode
text = text.gsub(PassInlineMacroRx) {
m = $~
preceding = nil
if (boundary = m[4]).nil_or_empty?
if m[6] == '\\'
next m[0][1..-1]
end
@passthroughs[pass_key = @passthroughs.size] = {:text => (unescape_brackets m[8]), :subs => (m[7].nil_or_empty? ? [] : (resolve_pass_subs m[7]))}
else
if compat_mode && boundary == '++'
next m[2].nil_or_empty? ?
%(
%(#{m[1]}[#{m[2]}]#{m[3]}++#{extract_passthroughs m[5]}++)
end
attributes = m[2]
if ::RUBY_ENGINE_OPAL
attributes = nil if attributes == ''
end
escape_count = m[3].size
content = m[5]
old_behavior = false
if attributes
if escape_count > 0
next "#{m[1]}[#{attributes}]#{'\\' * (escape_count - 1)}#{boundary}#{m[5]}#{boundary})"
elsif m[1] == '\\'
preceding = %([#{attributes}])
attributes = nil
else
if boundary == '++' && (attributes.end_with? 'x-')
old_behavior = true
attributes = attributes[0...-2]
end
attributes = parse_attributes attributes
end
elsif escape_count > 0
next "#{m[1]}[#{attributes}]#{'\\' * (escape_count - 1)}#{boundary}#{m[5]}#{boundary}"
end
subs = (boundary == '+++' ? [] : [:specialcharacters])
pass_key = @passthroughs.size
if attributes
if old_behavior
@passthroughs[pass_key] = {:text => content, :subs => SUBS[:normal], :type => :monospaced, :attributes => attributes}
else
@passthroughs[pass_key] = {:text => content, :subs => subs, :type => :unquoted, :attributes => attributes}
end
else
@passthroughs[pass_key] = {:text => content, :subs => subs}
end
end
%(#{preceding}#{PASS_START}#{pass_key}#{PASS_END})
} if (text.include? '++') || (text.include? '$$') || (text.include? 'ss:')
pass_inline_char1, pass_inline_char2, pass_inline_rx = PassInlineRx[compat_mode]
text = text.gsub(pass_inline_rx) {
m = $~
preceding = m[1]
attributes = m[2]
escape_mark = (m[3].start_with? '\\') ? '\\' : nil
format_mark = m[4]
content = m[5]
if ::RUBY_ENGINE_OPAL
attributes = nil if attributes == ''
end
if compat_mode
old_behavior = true
else
if (old_behavior = (attributes && (attributes.end_with? 'x-')))
attributes = attributes[0...-2]
end
end
if attributes
if format_mark == '`' && !old_behavior
next "#{preceding}[#{attributes}]#{escape_mark}`#{extract_passthroughs content}`"
end
if escape_mark
next "#{preceding}[#{attributes}]#{m[3][1..-1]}"
elsif preceding == '\\'
preceding = %([#{attributes}])
attributes = nil
else
attributes = parse_attributes attributes
end
elsif format_mark == '`' && !old_behavior
next "#{preceding}#{escape_mark}`#{extract_passthroughs content}`"
elsif escape_mark
next "#{preceding}#{m[3][1..-1]}"
end
pass_key = @passthroughs.size
if compat_mode
@passthroughs[pass_key] = {:text => content, :subs => [:specialcharacters], :attributes => attributes, :type => :monospaced}
elsif attributes
if old_behavior
subs = (format_mark == '`' ? [:specialcharacters] : SUBS[:normal])
@passthroughs[pass_key] = {:text => content, :subs => subs, :attributes => attributes, :type => :monospaced}
else
@passthroughs[pass_key] = {:text => content, :subs => [:specialcharacters], :attributes => attributes, :type => :unquoted}
end
else
@passthroughs[pass_key] = {:text => content, :subs => [:specialcharacters]}
end
%(#{preceding}#{PASS_START}#{pass_key}#{PASS_END})
} if (text.include? pass_inline_char1) || (pass_inline_char2 && (text.include? pass_inline_char2))
text = text.gsub(StemInlineMacroRx) {
m = $~
if m[0].start_with? '\\'
next m[0][1..-1]
end
if (type = m[1].to_sym) == :stem
type = ((default_stem_type = document.attributes['stem']).nil_or_empty? ? 'asciimath' : default_stem_type).to_sym
end
content = unescape_brackets m[3]
if m[2].nil_or_empty?
subs = (@document.basebackend? 'html') ? [:specialcharacters] : []
else
subs = resolve_pass_subs m[2]
end
@passthroughs[pass_key = @passthroughs.size] = {:text => content, :subs => subs, :type => type}
%(#{PASS_START}#{pass_key}#{PASS_END})
} if (text.include? ':') && ((text.include? 'stem:') || (text.include? 'math:'))
text
end