public Method

BlueCloth.escape_special_chars( str )

Escape special characters in the given str

Source Code

# File bluecloth.rb, line 395
def escape_special_chars( str )
        @log.debug "  Escaping special characters"
        text = ''

        # The original Markdown source has something called '$tags_to_skip'
        # declared here, but it's never used, so I don't define it.

        tokenize_html( str ) {|token, str|
                @log.debug "   Adding %p token %p" % [ token, str ]
                case token

                # Within tags, encode * and _
                when :tag
                        text += str.
                                gsub( /\*/, EscapeTable['*'][:md5] ).
                                gsub( /_/, EscapeTable['_'][:md5] )

                # Encode backslashed stuff in regular text
                when :text
                        text += encode_backslash_escapes( str )
                else
                        raise TypeError, "Unknown token type %p" % token
                end
        }

        @log.debug "  Text with escapes is now: %p" % text
        return text
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.