8

I had a heck of time while editing my What factors decide when/why a status-planned tag is added? question. But, I guess, I discovered a new weird problem in the editor while formatting hyperlink text next to tag.

To illustrate this problem better, I would like to give the following examples:

Has problem with one or none white-space in between:

[meta-tag:status-planned] [details page reads:][2]
[meta-tag:status-planned][details page reads:][2]  

Gives weird output as:

[details page reads:]2

[details page reads:]2

But, its okay with two white-spaces in between:

[meta-tag:status-planned]  [details page reads:][2]

Gives the correct output as:

details page reads:

Something is strange here. I don't understand why do I have to insert two white-spaces instead of just one? Are the two white-spaces are mandatory when using [meta-tag:some-tag] with hyperlink text adjacent to it? Or, is it one of those thing?

But wait, it's get even further complicated if I do like:

1. No white-spaces in between:

[meta-tag:status-planned][meta-tag:status-completed][Moderator-only Tags][3]

Moderator-only Tags

2. One white-space in between:

[meta-tag:status-planned] [meta-tag:status-completed] [Moderator-only Tags][3]

Moderator-only Tags

3. Two white-spaces in between:

[meta-tag:status-planned]  [meta-tag:status-completed]  [Moderator-only Tags][3]

Moderator-only Tags

They all seems to work perfectly fine. Now, thats very strange! Why would the two [meta-tag:some-tag] works like a charm with or without requiring to insert any white-spaces? Can anyone explain this in a better way. I don't want to jump on the conclusion by calling this as a bug yet, so I used tag instead of tag. Please share your thoughts.

2
  • Happens with [tag:] as well. – Nathan Tuggy Jul 11 '15 at 0:01
  • @NathanTuggy animuson's answer solves the mystery. Read when you get chance. – HackerKarma Jul 11 '15 at 1:15
7

This occurs because the tag syntax interferes with the original Markdown syntax for creating a link. The [text][id] style syntax creates a link with the text "text" pointing at the URL defined by "id". This syntax allows up to one space to be present between the two identifiers.

So in your first example, it looks at this part:

[meta-tag:status-planned][details page reads:]

As trying to define a link. But there is no ID for "details page reads:" so the link is invalid and doesn't get rendered. The [2] after that does create a link because it follows the Markdown syntax of [id] for creating a link, which creates a link with the text of the ID pointing to the URL defined by the ID. This results in an unrendered first link, followed by a rendered link.

Since the syntax only allows up to one space in between the identifiers, adding two or more spaces between them will cause the Markdown parser to not try and render the fist part as a link, and display the result you expected to occur.

In your second set of examples, the same thing happens, it's just that that you've added another piece into the puzzle so it produces different results. It looks at the [meta-tag:status-planned][meta-tag:status-completed] first and determines that it's not a valid link, so it doesn't do anything with it. Then it looks at the [Moderator-only Tags][3] part and determines that is a valid link, and renders it as such. If you added another tag in to create this:

[meta-tag:status-planned][meta-tag:status-completed][meta-tag:status-declined][Moderator-only Tags][3]

You would begin experiencing the same problems as you had in your original scenario with only one tag, because the [meta-tag:status-declined][Moderator-only Tags] part does not create a valid link, resulting in the [3] at the end being rendered as a "3" pointing to the URL identified by ID 3.


The "Markdown" for the tag styling always gets applied last. If you similarly use a tag syntax followed by an ID-only syntax, it would display as a simple link rather than a tag followed by a link, like so:

[meta-tag:status-planned][2]

  [2]: http://stackexchange.com

meta-tag:status-planned

As well, if you had [meta-tag:status-deferred], for example, defined as a link via the Markdown syntax, it would get rendered as a link via the [id] link syntax, like so:

[meta-tag:status-deferred][2]

  [meta-tag:status-deferred]: http://stackexchange.com

meta-tag:status-deferred

The hyperlink syntax always takes precedence over the tag syntax.

4
  • +100... Epic answer! You explained it in a great detail and I learned something new about Markdown. Thanks. – HackerKarma Jul 11 '15 at 1:11
  • Commonmark spec (more specifically example 511) doesn't behave this way with a single space spec.commonmark.org/dingus/… – Braiam Mar 23 '17 at 14:43
  • @Braiam Yeah, CommonMark got rid of the optional space. I honestly don't know why it was ever an option in Markdown. It doesn't really make sense that two thing separated by a space would be considered as one thing. But this irritant will disappear whenever we upgrade to CommonMark. – animuson ModStaff Mar 23 '17 at 14:57
  • So, there's hope! – Braiam Mar 23 '17 at 15:05

You must log in to answer this question.

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