3
\$\begingroup\$

I encountered this bug a few minutes ago, and decided to bring it up here. It happens when both asking and answering a question.

Steps to reproduce

1. Create bulleted list with a couple/few items. I checked, the size of the list doesn't matter, whether it's one or seven items .

2. Post a piece of code, formatted with four spaces below the list

3. Observe code not being formatted

It was really frustrating as I was trying to answer a users question, and the code wasn't formatting. The solution was I had to type something after the list, but is that really required?

\$\endgroup\$
3
  • \$\begingroup\$ You can often get around this sort of inconvenience by using the triple-backtick code block format. \$\endgroup\$ Jul 25, 2019 at 10:53
  • 1
    \$\begingroup\$ @VisualMelon Yea, don't do that. It creates an even bigger mess. \$\endgroup\$
    – Mast Mod
    Jul 25, 2019 at 11:12
  • \$\begingroup\$ @Mast I'd have to disagree: it means you can still use the make code block button for depth-1 lists, rather than having to do the indenting yourself/with some other tool. \$\endgroup\$ Jul 25, 2019 at 11:31

1 Answer 1

9
\$\begingroup\$

This is kind-of working as intended. What you observe, is the code being taken as a point in the bulleted list.

If you want this, add another 4 spaces of indentation and the code will be formatted correctly.

  • Point
  • Point 2

    import code
    code.do()
    

If you don't want this, break the bulleted list by inserting something else in between. Even an invisible HTML comment does the trick there (<!-- -->).

  • Point
  • Point 2

Code:

import code
code.do()

Notice how the codeblock itself is indented in the first example while not in the latter?


It's not a bug, it's a feature. So you can do this:

  • Point
  • Indented 4 spaces and given code fences

    import code
    code.do()
    
  • Indented 8 spaces instead of 4

    import moar_code
    moar_code.do()
    

VisualMelon suggested adding triple-backtick formatting to fix it. Personally, I'm not in favour of this as it's mixing formatting styles and makes copying the code to an IDE more work. But it does 'fix' your situation. Just like adding 4 more spaces does.

\$\endgroup\$
3
  • 4
    \$\begingroup\$ The easy way to indent 2 (or more) levels is to put a temporary line (with text in column 0) immediately before or after the code that's already indented one level. Select the code and the temporary line, and use C-k to indent. Then delete the (now indented) temporary line. \$\endgroup\$ Jul 25, 2019 at 16:41
  • \$\begingroup\$ @TobySpeight Or use an IDE that supports Ctrl + A, Tab (with tabs to 4 spaces). Like Notepad++, Atom, Pyzo and plenty of others. \$\endgroup\$
    – Mast Mod
    Jul 25, 2019 at 17:26
  • \$\begingroup\$ That html-comment trick is neat. I have written lots of Code: headers I didn't want to. \$\endgroup\$
    – dfhwze
    Aug 10, 2019 at 8:47

You must log in to answer this question.

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