def extract_passthroughs(text)
compat_mode = @document.compat_mode
text = text.gsub(InlinePassMacroRx) {
m = $~
preceding = nil
if (boundary = m[4])
if compat_mode && boundary == '++'
next m[2] ?
%(#{m[1]}[#{m[2]}]#{m[3]}++#{extract_passthroughs m[5]}++) :
%(#{m[1]}#{m[3]}++#{extract_passthroughs m[5]}++)
end
attributes = m[2]
escape_count = m[3].length
content = m[5]
old_behavior = false
if attributes
if escape_count > 0
next %(
elsif m[1] == RS
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 %(
end
subs = (boundary == '+++' ? [] : BASIC_SUBS)
pass_key = @passthroughs.size
if attributes
if old_behavior
@passthroughs[pass_key] = {:text => content, :subs => NORMAL_SUBS, :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
else
if m[6] == RS
next m[0][1..-1]
end
@passthroughs[pass_key = @passthroughs.size] = {:text => (unescape_brackets m[8]), :subs => (m[7] ? (resolve_pass_subs m[7]) : [])}
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 = RS if m[3].start_with? RS
format_mark = m[4]
content = m[5]
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 %(
end
if escape_mark
next %(
elsif preceding == RS
preceding = %([#{attributes}])
attributes = nil
else
attributes = parse_attributes attributes
end
elsif format_mark == '`' && !old_behavior
next %(
elsif escape_mark
next %(
end
pass_key = @passthroughs.size
if compat_mode
@passthroughs[pass_key] = {:text => content, :subs => BASIC_SUBS, :attributes => attributes, :type => :monospaced}
elsif attributes
if old_behavior
subs = (format_mark == '`' ? BASIC_SUBS : NORMAL_SUBS)
@passthroughs[pass_key] = {:text => content, :subs => subs, :attributes => attributes, :type => :monospaced}
else
@passthroughs[pass_key] = {:text => content, :subs => BASIC_SUBS, :attributes => attributes, :type => :unquoted}
end
else
@passthroughs[pass_key] = {:text => content, :subs => BASIC_SUBS}
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(InlineStemMacroRx) {
m = $~
if m[0].start_with? RS
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]
subs = m[2] ? (resolve_pass_subs m[2]) : ((@document.basebackend? 'html') ? BASIC_SUBS : [])
@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