def read_link(src, con)
src.ignore_char
children = read_span(src, EscapedCharInText, ']')
src.ignore_char
if src.cur_char == ' ' && ['[', '('].include?(src.next_char)
src.shift_char
end
case src.cur_char
when '('
src.ignore_char
src.consume_whitespace
url = read_url(src, [' ', "\t", ")"]) || ''
src.consume_whitespace
title = nil
if src.cur_char != ')'
quote_char = src.cur_char
title = read_quoted(src, con)
if not title
maruku_error 'Must quote title', src, con
else
unless src.next_matches(/\s*\)/)
rest = read_simple(src, nil, ')', nil)
rest.chop!
title << quote_char << rest
end
end
end
src.consume_whitespace
closing = src.shift_char
if closing != ')'
maruku_error 'Unclosed link', src, con, "No closing ): I will not create" +
" the link for #{children.inspect}"
con.push_elements children
return
end
con.push_element md_im_link(children, url, title)
when '['
ref_id = read_ref_id(src, con)
if ref_id
con.push_element md_link(children, ref_id)
else
maruku_error "Could not read ref_id", src, con, "I will not create the link for " +
"#{children.inspect}"
con.push_elements children
return
end
else
con.push_element md_link(children, nil)
end
end