5

Fundamentally, I want to create this link in a comment and have it go to the right place: String(byte[],Charset)

source:

 [`String(byte[],Charset)`](http://developer.android.com/reference/java/lang/String.html#String(byte[],%20java.nio.charset.Charset)) 

Two issues emerge:

  1. The actual link strips the square brackets (presumably because they're improperly encoded), this is livable but undesirable, I can url-encode them myself
  2. Comments incorrectly fail to escape the brackets, leading to a messy rendering of:

[String(byte[],Charset)](http://developer.android.com/reference/java/lang/String.html#String(byte%5B%5D,%20java.nio.charset.Charset))

Without the code format I recognize it's possible to escape the slashes, rendering correctly as String(byte[],Charset)

However, with inline code formatting and escaped slashes, I simply see the slashes:

[String(byte\[\],Charset)](http://developer.android.com/reference/java/lang/String.html#String(byte%5B%5D,%20java.nio.charset.Charset))

8
  • e.g. String(byte[],Charset) Commented Jul 7, 2011 at 3:25
  • Note that it isn't switched to a link but rather a [name] next to an link. Commented Jul 7, 2011 at 3:30
  • I wish there was some way to count the number of people who have just tried to replicate (in these comments) your bug... Commented Jul 7, 2011 at 3:31
  • 1
    @M.: Lance tried at least 4 times, I saw 3 other alerts since then. Commented Jul 7, 2011 at 3:32
  • Note: they should be encoded according to this question. Commented Jul 7, 2011 at 3:35
  • @M.: Unfortunately Google is failing to encode them =/ Commented Jul 7, 2011 at 3:37
  • So in other words, this: String(byte\[\],Charset) still fails. Commented Jul 7, 2011 at 3:52
  • @M.: precisely. Commented Jul 7, 2011 at 3:53

3 Answers 3

3

You cannot escape anything in code spans (because you shouldn't have to), with one exception: If the code span is delimited by single backticks, you can escape backticks (for historical reasons). If it's enclosed by multiple backticks, e.g. ``here is a backtick: ` <-- see?``, you can't (and don't have to) escape anything anymore. See this answer for more.

The fact that the closing bracket broke stuff was merely a bug; that's fixed in the next build. Your original version will then work, except for – as you noted – the requirement to url-encode brackets in the link.

[`String(byte[],Charset)`](http://example.org) 
7
  • You are fast!!! Commented Jul 7, 2011 at 7:16
  • @balpha: The escaping of backticks ` in inline code in comments is not purely for historical reasons. How else could I produce `? Commented Jul 7, 2011 at 9:06
  • @HendrikVogt: By enclosing the code in multiple backticks (like my example above). Until the change from the answer I linked to (on your question), multiple backtick blocks were not supported in comments, so back then the only way to have a backtick in code was escaping, and for historical reasons (call it backwards-compatibility if you will) we left that in. Try it in a post -- real Markdown doesn't have that escaping thing. Commented Jul 7, 2011 at 9:27
  • @balpha: Try it yourself: `` ` `` gives `` ` ``. Commented Jul 7, 2011 at 9:29
  • @balpha: And ````` gives `````. The problem is that spaces are no longer allowed at the start and end of inline code in comments. (I wonder why!) Commented Jul 7, 2011 at 9:30
  • @HendrikVogt: Well yeah, but that's nothing new -- I'm also mentioning that in my answer. That's certainly not the reason for leaving backslash-escaping in. Commented Jul 7, 2011 at 9:38
  • @balpha: No, indeed not new. So I'm even more puzzled why you write "By enclosing the code in multiple backticks" as an answer to my question "How else could I produce `?". (Ah, maybe this wasn't clear to you: I meant producing this very inline code `, consisting of a single backtick. See, yesterday I was asked how one does this on meta.math.sx!) Commented Jul 7, 2011 at 9:43
2

You can, but there's a couple things with your link. The square brackets can be escaped with a \, but the link should also really be encoded properly. I will add a comment on this answer using the following, (note the \[\]):

[String(byte\[\],Charset)](http://developer.android.com/reference/java/lang/String.html#String(byte%5b%5d, java.nio.charset.Charset))


After OP's edit:

Comments are parsed with mini-markdown, which intentionally supports a subset of the markdown syntax. This is very much intentional, as comments are just for quick things and should not need the full formatting that markdown in posts use.

10
  • 2
    String(byte[],Charset) Commented Jul 7, 2011 at 3:39
  • Your link fails to go to the right place, the square brackets are dropped from the actual href. Commented Jul 7, 2011 at 3:41
  • Further, escaping fails when using inline code ticks: String(byte\[\],Charset) Commented Jul 7, 2011 at 3:41
  • @Rebecca, your link strips out the []. I think you need to encode the [] to %5b%5d (But only in the actual link) Commented Jul 7, 2011 at 3:42
  • @MarkElliot Meh, copy/paste error, but just encode the url correctly. I think you need to escape the code ticks too maybe? Comments use mini-markdown which is only a subset of the markdown syntax that posts use. They aren't meant for complicated formatting like this. Commented Jul 7, 2011 at 3:43
  • Eh, I shouldn't need to escape my code ticks, I want to link code format, e.g.: String(byte<>,Charset) Commented Jul 7, 2011 at 3:44
  • Sorry, I've partially invalidated your answer by refining my question to be more accurate and more concise. Commented Jul 7, 2011 at 3:49
  • @MarkElliot, so...you've edited to be an exact dupe of stackoverflow.com/q/40568/181481? Commented Jul 7, 2011 at 3:52
  • @Rebecca: nope, I've edited to indicate that I cannot both escape slashes and use inline code formatting for links. My actual link contains the url-encoded square brackets, the issue is in the label. Commented Jul 7, 2011 at 3:53
  • @MarkElliot, you edited after my comment again. I've now edited my answer to match...I think. Commented Jul 7, 2011 at 3:57
2

So to get this to work, as @RebeccaChernoff noted, you must escape the [] in the link text and encode them in the link itself. Check out this page on URL Encoding.

Update: So what you want is achieved by this:

[`String(byte`\[\]`,Charset)`](http://developer.android.com/reference/java/lang/String.html#String(byte%5b%5d,%20java.nio.charset.Charset)) note the double '`' 

Update 2:

[`String(byte['\]',Charset)`](http://developer.android.com/reference/java/lang/String.html#String(byte%5b%5d,%20java.nio.charset.Charset)) 

Will get you the opening bracket but not the closing one. See below in comments. (After experimenting for 30 minutes, this is the closest I can get. See my last comment)

8
  • 1
    String(byte[],Charset) Commented Jul 7, 2011 at 3:44
  • Yeah, that was a copy/paste fail on my part. I edited. Commented Jul 7, 2011 at 3:45
  • My word. Eight tries for me to get that link right!!. eek. Commented Jul 7, 2011 at 3:46
  • Unfortunately this doesn't resolve the problem as I'd like to use inline code formatting, too. (edited question to be more precise) Commented Jul 7, 2011 at 3:50
  • String(byte[],Charset) Commented Jul 7, 2011 at 3:54
  • That's close, but I want code formatted square brackets. Seeing as the behavior is unexpected I'd still call this a bug -- though maybe this is a (poor?) workaround. Commented Jul 7, 2011 at 3:56
  • So you want [String(byte[],Charset)] to link as above. I can't get it to work. Commented Jul 7, 2011 at 3:58
  • String(byte[],Charset) Commented Jul 7, 2011 at 4:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.