We can has /properly formatted/ code in COMMENTS!

Hi folks!

Just enabled “Jetpack”… Jetpack Comment… and MARKDOWN on this blog.

WHAT THIS MEANS FOR YOU

You can now enter properly formatted code in comments! YES!

Or at least I’m led to believe this, heh. I shall try this as replies to this post.

HERE’S HOW:

  1. Enter three backticks ( ``` ) BEFORE and AFTER your code block, OR
  2. Wrap your code block with the HTML tags <pre> and </pre>

That should do it! Please do check out the replies to this post.

2 thoughts on “We can has /properly formatted/ code in COMMENTS!

  1. # this is a test, adapted from a comment by a reader, 
    # trying traditional HTML tags first, to see if they
    # work to preserve proper code formatting, i.e.
    # indentation.
    #
    # SO PLEASE NOTE:  This entire comment was pasted in 
    # between "<pre>" and "</pre>" HTML tags.
    #
    # And... if you're really clever, you'll quickly 
    # discover that showing those tags above IN
    # THIS COMMENT requires the writer to use
    # escapes to display a tag for proper display e.g.
    # type "&lt;pre>" in order to display "<pre>"
    #
    x,y,z = 33,50,9
    if x%2 != 0 and y%2 != 0 and z%2 !=0:
        if x > y and x > z:
            print x,'x {} is largest'
        elif y > z:
            print y,'y is largest'
        elif z > x and z > y:
            print z,'z is largest'
    else:
        print 'eh? got no odds in your inputs'
    
  2. Here’s another example, but using “markdown” syntax. Go google it!

    (And for the impatient đŸ™‚ here’s the Markdown basics from GitHub.)

    The special character you need to know about is the “grave accent“, described as follows:

    Programmers have used the grave accent symbol as a separate character (i.e., not combined with any letter) for a number of tasks. In this role, it is known as a backquote or backtick.

    The backtick character often found above the ‘tab’ key on many US-layout keyboards.

    HOW TO USE IT FOR CODE

    Enter triple backticks (```) before and after your multi-line code fragment. Here is an example!

    # Test of code fragment paste into a comment, with three 
    # backticks before and after it
    
    x,y,z = 33,50,9
    if x%2 != 0 and y%2 != 0 and z%2 !=0:
        if x > y and x > z:
            print x,'x {} is largest'
        elif y > z:
            print y,'y is largest'
        elif z > x and z > y:
            print z,'z is largest'
    else:
        print 'eh? got no odds in your inputs'
    

Leave a Reply