# File lib/bluecloth.rb, line 964
        def transform_images( str, rs )
                @log.debug " Transforming images: %p" % [ str ]

                # Handle reference-style labeled images: ![alt text][id]
                str.
                        gsub( ReferenceImageRegexp ) {|match|
                                whole, alt, linkid = $1, $2, $3.downcase
                                @log.debug "Matched %p" % match
                                res = nil
                                alt.gsub!( /"/, '"' )

                                # for shortcut links like ![this][].
                                linkid = alt.downcase if linkid.empty?

                                if rs.urls.key?( linkid )
                                        url = escape_md( rs.urls[linkid] )
                                        @log.debug "Found url '%s' for linkid '%s' " % [ url, linkid ]

                                        # Build the tag
                                        result = %{<img src="%s" alt="%s"} % [ url, alt ]
                                        if rs.titles.key?( linkid )
                                                result += %{ title="%s"} % escape_md( rs.titles[linkid] )
                                        end
                                        result += EmptyElementSuffix

                                else
                                        result = whole
                                end

                                @log.debug "Replacing %p with %p" % [ match, result ]
                                result
                        }.

                        # Inline image style
                        gsub( InlineImageRegexp ) {|match|
                                @log.debug "Found inline image %p" % match
                                whole, alt, title = $1, $2, $5
                                url = escape_md( $3 )
                                alt.gsub!( /"/, '&quot;' )

                                # Build the tag
                                result = %{<img src="%s" alt="%s"} % [ url, alt ]
                                unless title.nil?
                                        title.gsub!( /"/, '&quot;' )
                                        result += %{ title="%s"} % escape_md( title )
                                end
                                result += EmptyElementSuffix

                                @log.debug "Replacing %p with %p" % [ match, result ]
                                result
                        }
        end