What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 133 Stack Exchange communities.

I'm aware that I can do this:

  1. This code is python:

    print "Hello"
    print "World"
    
  2. And this is javascript:

    console.log("Hello")
    console.log("World")
    

But is it possible to correctly format this?

  1. print "Hello" print "World"

    That code was python

  2. console.log("Hello") console.log("World")

    And that was javascript

Which I've marked up as:

1.      print "Hello"
        print "World"

    That code was python

2.      console.log("Hello")
        console.log("World")

    And that was javascript

Currently, my attempts either:

  • Drop the numbering for no obvious reason
  • Result in a blank line before the code block
  • Work only for a single line of code using `s
share|improve this question
1  
You need a block of code, or a single line? If the latter, just use backticks. –  Bart Feb 10 '13 at 17:45
    
@bart: Aiming for a block of code, hence me listing `s as a failed attempt. Updated the question to be more clear –  Eric Feb 10 '13 at 17:48
    
Ah, I glanced over that single character in the last line. –  Bart Feb 10 '13 at 17:50

1 Answer 1

Sure, although it's a bit messy:

  1. print "Hello World"
    

    That code was python

  2. console.log("Hello World")
    

    And that was javascript

Source:

1.  

        print "Hello World"

    That code was python

2. 

        console.log("Hello World")

    And that was javascript

However, be aware that WebKit based browsers won't show the list item numbers with this structure, due to a long-standing bug. The produced HTML is still as expected, though.

share|improve this answer
    
This was the behaviour I was describing in my first bullet point. I'd assumed it was a quirk in the markdown parser, not my browser's rendering. –  Eric Feb 10 '13 at 17:57
    
Nope, unfortunately it's a browser bug that still hasn't been fixed. Probably worth double-checking if there's any way the CSS here could be changed to work around the issue, I'll make a note to meddle with it a bit later. –  Tim Stone Feb 10 '13 at 17:59
    
Simply unchecking overflow: auto for pre in the chrome inspector makes this behave for me. Of course, that's there for the scrolling behaviour for large code boxes. –  Eric Feb 10 '13 at 18:00
    
test-case here –  Eric Feb 10 '13 at 18:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .