2

In here I wrote a comment with markdown:

This is roughly true, but the actual conditions are "(1)one-char String and
this character is not one of the RegEx's meta characters ".$|()[{^?*+\\",
or (2)two-char String and the first char is the backslash and the second is
not the ascii digit or ascii letter." ([source]
(http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk
/8u40-b25/java/lang/String.java#String.split%28java.lang.String%2Cint%29))

This seems to be rendered like

enter image description here

When it really should make only the word "source" a link.

The problem doesn't seem to exist in answers or questions, just in comments. In questions only the word "source" would be made a link.

0

1 Answer 1

3

Notice that where the link starts in your comment is where you have a [ character in the comment (as a part of the regex).

This is a meaningful character in markdown, the start of link character. You can escape it with a slash (\) to ensure that it's treated as a literal.

Below is that same comment with the escaped character, as a comment. Here is the markdown for that comment:

This is roughly true, but the actual conditions are "(1)one-char String and this character is not one of the RegEx's meta characters ".$|()\[{^?*+\\", or (2)two-char String and the first char is the backslash and the second is not the ascii digit or ascii letter." ([source](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/lang/String.java#String.split%28java.lang.String%2Cint%29))

(Note that adding line breaks can potentially also affect how the markdown is rendered, so I've not included any.)

7
  • This is roughly true, but the actual conditions are "(1)one-char String and this character is not one of the RegEx's meta characters ".$|()[{^?*+\\", or (2)two-char String and the first char is the backslash and the second is not the ascii digit or ascii letter." (source)
    – Servy
    Commented Jul 1, 2015 at 21:08
  • 1) this does not explain why it would behave differently in comments than in the question, and 2) it really should be changed to lazy regex instead of greedy, right?
    – eis
    Commented Jul 1, 2015 at 21:10
  • 1
    @eis 1) Markdown isn't really standardized; what documentation there is on it really leaves this particular behavior ambiguous. But consistency within the site would be nice, sure. 2) I don't think that that would address the problem. The parser sees a [, assumes that this is the start of a a linked text block, it sees a ] later on immediately followed by a (, a link, and then a ). It takes everything between the [ and ] and links it to the parenthesized link. It'd need to be a non-greedy algorithm for it to skip the first [ and try to find the one closest to the ].
    – Servy
    Commented Jul 1, 2015 at 21:13
  • 2) yeah. Anyway, IMO changing it would make sense, it does seem more logical to assume the closest [ is the one related to the link.
    – eis
    Commented Jul 1, 2015 at 21:24
  • 1
    @eis "why it would behave differently in comments than in the question" Comments only support a subset of Markdown, so they're parsed differently. StackExchange's parser also adds some interesting quirks, such as requiring backslashes to escape backticks in inline code blocks (`I'm a backtick: \``) instead of the standard multiple backticks (`` I'm a backtick: ` ``). Commented Jul 1, 2015 at 21:24
  • @ThisSuitIsBlackNot even if only subset is supported, I don't think there's a reason not to have questions and comments to work consistently in this regard
    – eis
    Commented Jul 1, 2015 at 21:28
  • 3
    @eis At this point, there's probably a compelling reason in the form of "don't potentially break tons of existing comments". If I remember correctly, comments are formatted from Markdown on the fly, while questions and answers are cached as HTML. Commented Jul 1, 2015 at 21:30

You must log in to answer this question.

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