15

Here, I tried to write a sentence

Use [local variable type inference]1 ...

but it didn't get parsed well, so I had to add an extra space after the tag

Use local variable type inference ...

I've checked some other scenarios.

  1. [] [text]1
  2. [text]1
  3. text

It appears that [] before a link cause the issue.

1. [] [text][1]  
2. [tag:java-10] [text][1]  
3. [tag:java-10]  [text][1]  
2

2 Answers 2

14

Markdown need escaping:

[] [text][1]

[] [text]1

The right way to do this:

\[\] [text][1]

[] text

It's true even for tags (well I'm surprised too)

\[tag:javascript\] [text][1]

text

In fact, you don't need to escape the closing bracket:

\[tag:python] [text][1]

text

8
  • I don't want to escape them, they are the part of the syntax [tag:TAG_NAME] Commented Jan 2, 2019 at 11:43
  • you mean \[tag:java-10\] [text][1] is a valid construction? Commented Jan 2, 2019 at 11:45
  • 2
    @AndrewTobilko See update, really surprising.
    – iBug
    Commented Jan 2, 2019 at 11:47
  • Yes, it works, thank you. It looks like I should escape either bracket (at least one of them), not only the closing one Commented Jan 2, 2019 at 11:53
  • 6
    O_o Wat. Why would as escaped bracket (\[tag:javascript\] be rendered as the tag thing? thinks ...Is link generation a post-Markdown thing?
    – jpmc26
    Commented Jan 2, 2019 at 18:56
  • 1
    Putting an HTML comment between them (like <!-- -->) also seems to work.
    – Radiodef
    Commented Jan 2, 2019 at 18:57
  • @jpmc26 That appears to be the case.
    – Sinjai
    Commented Jan 2, 2019 at 19:18
  • The question is whether Markdown really needs escaping, or if you found an unlucky workaround. Which Markdown specification says that escaping is needed? Commented Jan 3, 2019 at 15:42
7

So this is a conflict between tags (which are not Markdown syntax) and standard Markdown syntax.

Note that Markdown links allow a space between the label and the reference:

[link] [1]

[1]: http://example.com

which renders as1:

link

And, as Markdown parses left-to-right, the Markdown parser sees the tag followed by a link and assumes the tag is the first half of a reference style link. However, as no reference matches, then Markdown ignores the reference link and continues after the end of the reference. Of course, what Markdown say as a reference was actually intended to be the label of the link. So it starts back up with the actual reference, which does exist. And as Markdown allows for single reference style links (the label and reference is one and the same), it sees that reference as a link and processes it.

The point is that from a Markdown perspective, this is totally expected behavior. Thus the suggestion to escape the tag. Escaping the tag causes Markdown to not see it as part of a link (two spaces accomplish the same thing). The Markdown parser then picks up after the tag and now correctly pairs the label and reference parts of the link. And with the escape characters removed by Markdown, the postprocessor can recognize it as a tag and handle it appropriately.

So, the question is: how can SO fix this so that Markdown does not incorrectly recognize a tag as part of a link? I see a few options, none of which are great:

  1. Change the syntax for marking up tags.
  2. Alter the Markdown parser in some way:
    • Remove the allowance for a space between label and reference.
    • Extend the markdown parser to natively parse tags.
  3. Some other backward-incompatable change I haven't thought of.

1 Weirdly, the space between label and reference does not work within a quoteblock. In that case, it is not recognized as a link. Thus, I did not use a quoteblock above.

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