Escaping and posting code



  • The various escaping methods in the markup schemes mentioned in another post generally tend to work, and may be required for day-to-day posting, and there are others that are available

    • using &lt; to produce <

    • backslash to escape the next character: \. \\ -> . \

    • single backticks to produce inline escaping (excuse the linefeed here):

      `&lt;` -> &lt;

    • <code> is also available for inline markup, as is <samp><samp> (techinically used for output however.)</samp>

    • triple backticks to produce block escaping:

    \`\`\`
    void foo(int bar){
       return bar*2;
    }
    \`\`\`

    ->

    void foo(int bar){
           return bar*2;
    }
    

    Add a language name on the same line and after the first triple backticks to hint the language instead of letting the software assume. Discourse appears to be using highlight.js, and the current list of supported languages is:

    [pjh@sofa discourse]$ grep hljs.registerLanguage . -r | sed "s/hljs.registerLanguage/\nhljs.registerLanguage/g" | cut -c -40 | sed 's/^[^"]*"\([^"]*\)".*$/\1/g' | sort
    ./public/javascripts/highlight.pack.js:v
    apache
    bash
    coffeescript
    cpp
    cs
    css
    diff
    http
    ini
    java
    javascript
    json
    makefile
    markdown
    nginx
    objectivec
    perl
    php
    python
    ruby
    sql
    xml
    
    • <pre> (used to create the previous example):

    <pre>\`\`\`
    void foo(int bar){
    return bar*2;
    }
    \`\`\`</pre>

    ->

    \`\`\`
    void foo(int bar){
       return bar*2;
    }
    \`\`\`

    Those who want to view the escaping needed to create the 'before' there can view the source of this post.

    □□□□ □□□□void foo(int bar){
    □□□□ □□□□ □□□□return bar*2;
    □□□□ □□□□}

    ->

        void foo(int bar){
            return bar*2;
        }
    

Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.