def parse_inline(str)
until str.empty?
case str
when /\A(\~)?((https?|ftps?):\/\/\S+?)(?=([\,.?!:;"'\)]+)?(\s|$))/
str = $'
if $1
@out << escape_html($2)
else
if uri = make_direct_link($2)
@out << '<a href="' << escape_html(uri) << '">' << escape_html($2) << '</a>'
else
@out << escape_html($&)
end
end
when /\A\[\[\s*([^|]*?)\s*(\|\s*(.*?))?\s*\]\]/m
str = $'
link, content = $1, $3
if uri = make_explicit_link(link)
@out << '<a href="' << escape_html(uri) << '">'
if content
until content.empty?
content = parse_inline_tag(content)
end
else
@out << escape_html(link)
end
@out << '</a>'
else
@out << escape_html($&)
end
else
str = parse_inline_tag(str)
end
end
end