6

Embedded URLs are automatically linked by default, like e.g. http://localhost/.

Is there a way to avoid this auto-linking besides enclosing them in backticks (formatting them as code), like http://localhost/?

3
  • 3
    Can you describe a situation where code formatting is not appropriate, and the URL shouldn't auto-link?
    – user247702
    Oct 12, 2016 at 11:43
  • 1
    http://localhost is already a good example where you don't want to have auto-links, see stackoverflow.com/a/39997673/432681 as concrete example. Oct 12, 2016 at 11:48
  • 3
    @SebastianZartner: Code blocks are perfectly valid, there.
    – Cerbrus
    Oct 12, 2016 at 13:16

3 Answers 3

6

Sure there is. Replace one of the characters in the url with an html entity:

http://www.google.com
Raw: http://www.google.com

As you can see, I replaced one of the slashes with /, and the last period with ., which breaks the url, as far as markdown is concerned.

Apparently the edit preview still renders the url, but the actual post doesn't.

11
  • Good point! I didn't think of that. But this rather looks like a workaround for a missing escape feature. I wonder if there's a "clean" solution for it. Oct 12, 2016 at 11:46
  • 1
    @SebastianZartner: This is the only way to escape HTML, though.
    – Cerbrus
    Oct 12, 2016 at 11:48
  • I just realized that this solution does not work for comments, unfortunately. Oct 12, 2016 at 11:50
  • @SebastianZartner: I don't know of any option that works, in comments, other than code: http://localhost/
    – Cerbrus
    Oct 12, 2016 at 12:06
  • This answers my question, thank you! I just waited if somebody else has a better solution. Can this be seen as a feature request or do I have to post it somewhere else to be seen by the Stack Exchange developers? Oct 13, 2016 at 6:40
  • @SebastianZartner: You can submit a FR, but you'll have to come up with a very good reason you need unformatted urls in comments.
    – Cerbrus
    Oct 13, 2016 at 6:43
  • I'm asking at meta.stackexchange.com/questions/285778/…. Oct 14, 2016 at 9:00
  • this doesn't work on stackoverflow, at least in the preview.
    – user3064538
    Mar 16, 2022 at 8:22
  • @Boris: Hm, that's odd. The preview is inconsistent with the rendered output, apparently.
    – Cerbrus
    Mar 16, 2022 at 8:25
  • oh yea, if I click to Edit on your answer it links the url text in the preview
    – user3064538
    Mar 16, 2022 at 8:32
  • 2
    @Cerbrus I swear you could make a drinking game out of whenever SO breaks the editor in some or another way
    – Zoe is on strike Mod
    Mar 16, 2022 at 19:01
3

You can put a backslash before the colon:

http://localhost/

http\://localhost/

For some reason, the preview doesn't work properly with this (and you cannot use WYSIWYG mode on the new Stacks editor, not even for a second — but then again not much works with that).

Because of these limitations, I prefer using code format.

1

As suggested by Jeremy in an answer to a similar question on the global Meta site, you can insert <nolink>.

For example, http<nolink>://www.google.com would render like this:

http://www.google.com

1
  • 4
    This is risky to use. I used to use a similar trick and it was ruined when markdown parsing changed slightly. Your hack doesn't work in the new Stacks editor.
    – Laurel
    Mar 16, 2022 at 22:32

You must log in to answer this question.

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