# File lib/maruku/input/parse_span.rb, line 624
  def read_image(src, con)
    src.ignore_chars(2) # opening "!["
    alt_text = read_span(src, EscapedCharInText, ']')
    src.ignore_char # closing bracket
    # ignore space
    if src.cur_char == ' ' && ['[', '('].include?(src.next_char)
      src.ignore_char
    end
    case src.cur_char
    when '('
      src.ignore_char # opening (
      src.consume_whitespace
      url = read_url(src, [' ', "\t", ')'])
      unless url
        maruku_error "Could not read url from #{src.cur_chars(10).inspect}", src, con
      end
      src.consume_whitespace
      title = nil
      if src.cur_char != ')' # we have a title
        quote_char = src.cur_char
        title = read_quoted(src, con)
        if !title
          maruku_error 'Must quote title', src, con
        else
          # Tries to read a title with quotes: ![a](url "ti"tle")
          # this is the most ugly thing in Markdown
          if !src.next_matches(/\s*\)/)
            # if there is not a closing par ), then read
            # the rest and guess it's title with quotes
            rest = read_simple(src, nil, ')', nil)
            # chop the closing char
            rest.chop!
            title << quote_char << rest
          end
        end
      end
      src.consume_whitespace
      closing = src.shift_char # closing )
      if closing != ')'
        maruku_error "Unclosed link: '#{closing}'" +
          " Read url=#{url.inspect} title=#{title.inspect}", src, con
      end
      con.push_element md_im_image(alt_text, url, title)
    when '[' # link ref
      ref_id = read_ref_id(src, con)
      if !ref_id # TODO: check around
        maruku_error 'Reference not closed.', src, con
        ref_id = ""
      end

      con.push_element md_image(alt_text, ref_id)
    else # no stuff
      ref_id = alt_text.join
      con.push_element md_image(alt_text, ref_id)
    end
  end