-8

I have been stuck with the following format problem a couple of hours and read many post style documents on SO. Finally I found there is one ` more than normal in the beginning of the code.

This is a little bit confusing. The code block interpreted the extra tick mark as code, but it cannot end it without any delimiter and users may be confused. It is better to not transfer the block as code. I just share it for others like me and may be it is helpful.

public class Main
{
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
```

This is not code; I cannot end the code by delimiter.


12
  • 4
    Code fences need to start and end with the same number of backticks (`). You start with ````java (that's 4 back ticks) and end with ``` (that's 3 back ticks), and so the code fence is not closed because 3 != 4.
    – Thom A
    Commented Jul 13, 2021 at 14:28
  • 1
    Indeed, adding the fourth backtick to the closing line will close the block as intended (I didn't know you could use more than 3, that's potentially handy in edge-cases).
    – zcoop98
    Commented Jul 13, 2021 at 14:29
  • @Larnu I mention it, I just say it is a little confusing. Commented Jul 13, 2021 at 14:29
  • 2
    It’s all documented here: Implement ```-style (fenced) Markdown code blocks. I’m not sure what the goal of this discussion is. The title is: “Code delimiter not work when you wrong start it” — in other words: when you use it wrong, it doesn’t work! What are we supposed to do about it? Commented Jul 13, 2021 at 14:33
  • I wasn't aware that more than three backticks actually works.
    – Gimby
    Commented Jul 13, 2021 at 14:33
  • 4
    I'm having a hard time fully understanding what you're actually asking here. But given that SO is following the CommonMark Markdown specification (just like a bunch of other websites, such as GitHub), changing it would probably be even more confusing for those who are used to it.
    – Ivar
    Commented Jul 13, 2021 at 14:35
  • 3
    Nothing is being asked, Majid is sharing his experience with the rest of us as a heads up.
    – Gimby
    Commented Jul 13, 2021 at 14:38
  • @Gimby. Thanks. You understand me. I shared my experience because I confused for a while. Commented Jul 13, 2021 at 14:43
  • 3
    @Gimby yes, you can use any amount of matching backticks. I think I've seen one instance where this was useful - to format some markdown and include ``` inside the formatting, so the outer code fence used ```` (or something along those lines).
    – VLAZ
    Commented Jul 13, 2021 at 14:44
  • 2
    "I just say it is a little confusing" not really, if I am honest. As someone that codes do you think it confusing to ensure you close all your parenthesis..? If you do, I would suggest that coding isn't the right thing for you; correct use of parenthesis is really important. :)
    – Thom A
    Commented Jul 13, 2021 at 14:54
  • 1
    @VLAZ I guess you need something to support that corner case, I'd wish they had used something a little less triggered-by-typo though :) Regardless... the backticks are the method to format code so if the code formatting is not working as expected... there is little reason to look anywhere else than at the backticks.
    – Gimby
    Commented Jul 13, 2021 at 15:04
  • @Gimby If I recall, you can also use ~~~ as a fence too, so you'd only really need four or more of either if you were using both triple ` and triple ~ in the code block.
    – zcoop98
    Commented Jul 13, 2021 at 15:11

1 Answer 1

5

There is guidance when you click on the ? right in the toolbar of the editor. Under the code tab there is an example how to apply code formatting.

Enter image description here

There is no indication that you can use any arbitrary number of characters to start a code fence and then end with a different number of characters. As far as I know, no Markdown flavor properly handles unbalanced code fence start/end characters. For reference: here is the GitHub markdown flavor and here is the CommonMark specification (that is used on SO/SE).

In the preview it is pretty clear the code block wasn't closed properly. The OP can then edit to rectify any mishaps.

Do note that clicking the code button was and still is confusing. And it certainly didn't get the memo on code fences...

3
  • When you click on the code it just say you 'enter code here' with spaces not by backtick delimiter. So if I use backtick delimiter with a mistake in number of it, the problem arises. Commented Jul 13, 2021 at 14:45
  • @MajidHajibaba if you click the code button you're put in "4 spaces" mode. Either stick to that mode or use code fences but then you have to abide the markdown spec.
    – rene
    Commented Jul 13, 2021 at 14:51
  • And 4 spaces mode has a bunch of gotchas. For example, it doesn't work quite right after a numbered or dotted list. Commented Jul 13, 2021 at 17:00

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