Quote special characters for LaTeX.

    (Incomplete, currently only deals with underscores, dollar and hash.)
7308
def latex_quote(s):
    
    special = {'_':r'\_', '$':r'\$', '#':r'\#'}
    s = str(s)
    for char,repl in special.items():
        new = s.replace(char, repl)
        s = new[:]
    return s
602295
private String escapeQuotes(String value)
   {
      StringBuilder sb = new StringBuilder();
      int length = value.length();
      char c;

      sb.append('"');
      for (int index = 0; index < length; index++)
      {
         c = value.charAt(index);
         sb.append(c);

         if (c == '"')
         {
            sb.append('"');
         }
      }
      sb.append('"');

      return (sb.toString());
   }
1121778
function quote(s) {
    if (typeof(s) === 'string') {
        return "'" + s.replace(/'/g, "''") + "'";
    } else if (s instanceof Array) {
        return _.map(s, quote).join(', ');
    }

    return s;
}
628022
public final void mQUOTED_VALUE() throws RecognitionException {
        try {
            int _type = QUOTED_VALUE;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // BELScript.g:281:13: ( '\"' ( EscapeSequence | '\\\\\\n' | '\\\\\\r\\n' | ~ ( '\\\\' | '\"' ) )* '\"' )
            // BELScript.g:282:5: '\"' ( EscapeSequence | '\\\\\\n' | '\\\\\\r\\n' | ~ ( '\\\\' | '\"' ) )* '\"'
            {
            match('\"'); 
            // BELScript.g:282:9: ( EscapeSequence | '\\\\\\n' | '\\\\\\r\\n' | ~ ( '\\\\' | '\"' ) )*
            loop8:
            do {
                int alt8=5;
                int LA8_0 = input.LA(1);

                if ( (LA8_0=='\\') ) {
                    switch ( input.LA(2) ) {
                    case '\"':
                    case '\'':
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '\\':
                    case 'b':
                    case 'f':
                    case 'n':
                    case 'r':
                    case 't':
                    case 'u':
                        {
                        alt8=1;
                        }
                        break;
                    case '\n':
                        {
                        alt8=2;
                        }
                        break;
                    case '\r':
                        {
                        alt8=3;
                        }
                        break;

                    }

                }
                else if ( ((LA8_0>='\u0000' && LA8_0<='!')||(LA8_0>='#' && LA8_0<='[')||(LA8_0>=']' && LA8_0<='\uFFFF')) ) {
                    alt8=4;
                }


                switch (alt8) {
            	case 1 :
            	    // BELScript.g:282:11: EscapeSequence
            	    {
            	    mEscapeSequence(); 

            	    }
            	    break;
            	case 2 :
            	    // BELScript.g:282:28: '\\\\\\n'
            	    {
            	    match("\\\n"); 


            	    }
            	    break;
            	case 3 :
            	    // BELScript.g:282:37: '\\\\\\r\\n'
            	    {
            	    match("\\\r\n"); 


            	    }
            	    break;
            	case 4 :
            	    // BELScript.g:282:48: ~ ( '\\\\' | '\"' )
            	    {
            	    if ( (input.LA(1)>='\u0000' && input.LA(1)<='!')||(input.LA(1)>='#' && input.LA(1)<='[')||(input.LA(1)>=']' && input.LA(1)<='\uFFFF') ) {
            	        input.consume();

            	    }
            	    else {
            	        MismatchedSetException mse = new MismatchedSetException(null,input);
            	        recover(mse);
            	        throw mse;}


            	    }
            	    break;

            	default :
            	    break loop8;
                }
            } while (true);

            match('\"'); 

            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
175537
def _quote(str, LegalChars=_LegalChars):
    
    """
    if all(c in LegalChars for c in str):
        return str
    else:
        return '"' + _nulljoin(_Translator.get(s, s) for s in str) + '"'
564201
def t_QUOTED_STRING(t):
    '
    # TODO: Add support for:
    # - An undefined escape sequence (such as "\a" in a context where "a"
    # has no special meaning) is interpreted as if there were no backslash
    # (in this case, "\a" is just "a"), though that may be changed by
    # extensions.
    # - Non-printing characters such as tabs, CRLF, and control characters
    # are permitted in quoted strings.  Quoted strings MAY span multiple
    # lines.  An unencoded NUL (US-ASCII 0) is not allowed in strings.
    t.value = t.value.strip('"').replace(r'\"', '"').replace(r'\\', '\\')
    return t
332252
def hitalic(*content, sep=' '):
    
    return _md(quote_html(_join(*content, sep=sep)), symbols=MD_SYMBOLS[5])
565205
def clean_text(s):
    """"""
    SPACES_RE = re.compile(r'\s+')
    SPECIAL_CHARS_RE = re.compile(r'[^\w\s\.\-\(\)]')
    s = SPACES_RE.sub(' ', s)
    s = s.strip()
    s = SPECIAL_CHARS_RE.sub('', s)
    return s
497205
function shortCode( $_atts, $latex ) {
		$atts = shortcode_atts( array(
		    'size' => 0,
		    'color' => false,
		    'background' => false,
			), $_atts );

		$latex = preg_replace( array( '#<br\s*/?>#i', '#</?p>#i' ), ' ', $latex );

		$latex = str_replace(
			array( '&lt;', '&gt;', '&quot;', '&#8220;', '&#8221;', '&#039;', '&#8125;', '&#8127;', '&#8217;', '&#038;', '&amp;', "\n", "\r", "\xa0", '&#8211;' ),
			array( '<',    '>',    '"',      '``',       "''",     "'",      "'",       "'",       "'",       '&',      '&',     ' ',  ' ',  ' ',    '-' ),
			$latex
		);

		$latex_object = $this->latex( $latex, $atts['background'], $atts['color'], $atts['size'] );

		$url = esc_url( $latex_object->url );
		$alt = esc_attr( is_wp_error( $latex_object->error ) ? $latex_object->error->get_error_message() . ": $latex_object->latex" : $latex_object->latex  );

		return "<img src='$url' alt='$alt' title='$alt' class='latex' />";
	}
765050
def remove_quotes(self, value):
        
        # beware the empty string
        if not value:
            return value

        if value[0] == value[-1] == '"':
            return value[1:-1].replace('\\"', '"')
        if value[0] == value[-1] == "'":
            return value[1:-1].replace("\\'", "'")
        return value
976881
function(string) {
            // If the string contains no control characters, no quote characters, and no
            // backslash characters, then we can simply slap some quotes around it.
            // Otherwise we must also replace the offending characters with safe
            // sequences.    
            var m = {
                '\b': '\\b',
                '\t': '\\t',
                '\n': '\\n',
                '\f': '\\f',
                '\r': '\\r',
                '"' : '\\"',
                '\\': '\\\\'
            };
            if(/["\\\x00-\x1f]/.test(string)) {
                return '"' + string.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                    var c = m[b];
                    if(c) {
                        return c;
                    }
                    c = b.charCodeAt();
                    return '\\u00' +
                        Math.floor(c / 16).toString(16) +
                        (c % 16).toString(16);
                }) + '"';
            }
            return '"' + string + '"';
        }
857984
def optimize_quoted_uri_escapes!(escaped)
      escaped.gsub!('%3D', '=')
      escaped.gsub!('%3A', ':')
      escaped.gsub!('%2F', '/')
      escaped.gsub!('%27', "'")
      escaped.tr!('+', ' ')
    end
1087996
def escape(s, quote=True):
    
    s = s.replace("&", "&amp;") # Must be done first!
    s = s.replace("<", "&lt;")
    s = s.replace(">", "&gt;")
    if quote:
        s = s.replace('"', "&quot;")
        s = s.replace('\'', "&#x27;")
    return s
7341
function (str) {
    /**
     * Make our own "punctuation" character class, because the POSIX-style
     * [:PUNCT:] is only available in Perl 5.6 or later:
     *
     * JavaScript don't have punctuation class neither.
     */
    var punct_class = '[!"#\$\%\'()*+,-./:;<=>?\@\[\\\]\^_`{|}~]';
    /**
     * Special case if the very first character is a quote
     * followed by punctuation at a non-word-break. Close the quotes by brute force:
     */
    str = str.replace(new RegExp("^'(?=" + punct_class + "B)"), '&#8217;');
    str = str.replace(new RegExp("^\"(?=" + punct_class + "B)"), '&#8221;');
    /**
     * Special case for double sets of quotes, e.g.:
     *   <p>He said, "'Quoted' words in a larger quote."</p>
     */
    str = str.replace(/"'(?=\w)/, '&#8220;&#8216;');
    str = str.replace(/'"(?=\w)/, '&#8216;&#8220;');
    /**
     * Special case for decade abbreviations (the '80s):
     */
    str = str.replace(/'(?=\d\d)/, '&#8217;');
    var close_class = '[^\ \t\r\n\[\{\(\-]';
    var dec_dashes = '&#8211;|&#8212;';
    /**
     * Get most opening single quotes:
     * s {
     *     (
     *         \s          |   # a whitespace char, or
     *         &nbsp;      |   # a non-breaking space entity, or
     *         --          |   # dashes, or
     *         &[mn]dash;  |   # named dash entities
     *         $dec_dashes |   # or decimal entities
     *         &\#x201[34];    # or hex
     *     )
     *     '                   # the quote
     *     (?=\w)              # followed by a word character
     * } {$1&#8216;}xg;
     */
    str = str.replace(new RegExp("(s|&nbsp;|--|&[mn]dash;|" + dec_dashes + "|&#x201[34])'(?=w)", 'g'), '\$1&#8216;');
    /**
     * Single closing quotes:
     * s {
     *     ($close_class)?
     *     '
     *     (?(1)|          # If $1 captured, then do nothing;
     *       (?=\s | s\b)  # otherwise, positive lookahead for a whitespace
     *     )               # char or an 's' at a word ending position. This
     *                     # is a special case to handle something like:
     *                     # "<i>Custer</i>'s Last Stand."
     * } {$1&#8217;}xgi;
     */
    str = str.replace(new RegExp("(" + close_class + ")'", 'g'), '\$1&#8217;');
    str = str.replace(new RegExp("'(?=s|s\b)", 'g'), '\$1&#8217;');
    /**
     * Any remaining single quotes should be opening ones:
     */
    str = str.replace(/'/g, '&#8216;');
    /**
     * Get most opening double quotes:
     * s {
     *     (
     *         \s          |   # a whitespace char, or
     *         &nbsp;      |   # a non-breaking space entity, or
     *         --          |   # dashes, or
     *         &[mn]dash;  |   # named dash entities
     *         $dec_dashes |   # or decimal entities
     *         &\#x201[34];    # or hex
     *     )
     *     "                   # the quote
     *     (?=\w)              # followed by a word character
     * } {$1&#8220;}xg;
     */
    str = str.replace(new RegExp("(s|&nbsp;|--|&[mn]dash;|" + dec_dashes + "|&#x201[34])\"(?=w)", 'g'), '\$1&#8220;');
    /**
     * Double closing quotes:
     * s {
     *     ($close_class)?
     *     "
     *     (?(1)|(?=\s))   # If $1 captured, then do nothing;
     *                        # if not, then make sure the next char is whitespace.
     * } {$1&#8221;}xg;
     */
    str = str.replace(new RegExp("(" + close_class + ")\"", 'g'), '\$1&#8221;');
    str = str.replace(new RegExp("'(?=s)", 'g'), '\$1&#8221;');
    /**
     * Any remaining quotes should be opening ones.
     */
    str = str.replace(/"/g, '&#8220;');
    return str;
  }
261626
def quote_etag(etag, weak=False):
    
    if '"' in etag:
        raise ValueError('invalid etag')
    etag = '"%s"' % etag
    if weak:
        etag = 'w/' + etag
    return etag
644643
def format_h3(s, format="text", indents=0):
    

    _CHAR = "~"
    if format.startswith("text"):
        return format_underline(s, _CHAR, indents)
    elif format.startswith("markdown"):
        return ["### {}".format(s)]
    elif format.startswith("rest"):
        return format_underline(s, _CHAR, 0)
75848
def _add_escape_character_for_quote_prime_character(self, text):
        
        if text is not None:
          if "'" in text:
            return text.replace("'","\\'")
          elif '"' in text:
            return text.replace('"','\\"')
          else:
            return text
        else:
            return text