2

I have a piece of code after a list in a question. It is not getting syntax highlighted, even if I use SO code block, or indent it myself.

If I move it before the list, it works as expected. Also, if I use backticks (`), then it highlights the code.

FileSystemWatcher: Ignore first change to the file

The code is the last three lines, right in the end.

14
  • 1
    The list is preventing proper formatting. One solution, but an HTML comment in between, <?-- --> (as I have done for you) Commented Apr 24, 2019 at 2:46
  • @HovercraftFullOfEels that was quick :-) Commented Apr 24, 2019 at 2:47
  • 2
    Another solution -- indent it more, so that it is indented code that is part of the list. Commented Apr 24, 2019 at 2:47
  • Thanks @Hovercraft, that was quick. What did you change? I don't understand from the diff itself. Commented Apr 24, 2019 at 2:48
  • @AkshayKhot See: stackoverflow.com/posts/55820526/revisions, and click "side-by-side markdown" Commented Apr 24, 2019 at 2:49
  • 1
    @AkshayKhot: open the edit view to see what I did Commented Apr 24, 2019 at 2:50
  • @HovercraftFullOfEels The revisions you mean... Commented Apr 24, 2019 at 2:51
  • Got it. Thanks guys! Is this a bug in the editor, or do I need to keep this trick in mind whenever I want to add code snippet after a list? Commented Apr 24, 2019 at 2:51
  • Actually, opening the edit view worked as well! It shows the html comment. @U9-Forward. Commented Apr 24, 2019 at 2:52
  • @AkshayKhot Yup, regarding first comment, it's not a trick, just don't add the funny thing again... Commented Apr 24, 2019 at 2:54
  • Not sure I understand. What funny thing? Commented Apr 24, 2019 at 2:56
  • @AkshayKhot <?-- --> Commented Apr 24, 2019 at 3:05
  • Okay, so just indent it more, as the third comment suggests above? Commented Apr 24, 2019 at 3:06
  • If it is supposed to be part of the list, then indent 8 spaces Commented Apr 24, 2019 at 3:12

1 Answer 1

1

Code in a list that is part of a list:

  1. Item 1
  2. Item 2 with code

    public void main(String[] args) {
        // Code indented 8 spaces, not 4
    }
    
  3. Item 3 without code


Code that is after a list, put in a separator, such as an HTML comment, <!-- -->

  1. Item 1
  2. Item 2
  3. Item 3
// Separator, <!-- -->, is above this line but not shown
public void main(String[] args) {
    // Code indented 4 spaces, not 8
}
4
  • 2
    That is not the proper syntax for an HTML comment. You need an exclamation mark, not a question mark. <!-- -->
    – Cody Gray Mod
    Commented Apr 24, 2019 at 3:23
  • @CodyGray: oops, and darn. Need to brush up on my HTML! Thankfully the site is forgiving Commented Apr 24, 2019 at 3:24
  • 4
    The really sad thing is, you just got corrected on your HTML syntax by a C++ programmer. ;-)
    – Cody Gray Mod
    Commented Apr 24, 2019 at 3:26
  • 1
    Oh, the shame!!! Commented Apr 24, 2019 at 3:26

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.