15

When Linking to a Text Fragment, a tilde character ~ is used as part of the URL to identify text to highlight:

https://meta.stackexchange.com/q/370143/#:~:text=to%20identify%20text%20to%20highlight%3A

When using a link like this in Markdown, the tilde is escaped to %7E. In particular, this caused text highlighting to fail on three .gov and one .org sites that I encountered over a four day period. Today, I tested this on meta.stackexchange.com and had the same problem.

On StackExchange, text highlighting only works when the link is created with HTML anchor tags (<a>), with the link specified in the href attribute.

Link Type Typed Text Link Works? Example
HTML <a href="example.com#:~:text=test">text</a> Yes
~~
How do I search tags?
Markdown [text][1]
or
[text](example.com#:~:text=test)
No
~%7E
How do I search tags?

Markdown links are much easier to interpret when composing a post, but tildes are escaped when using them, which causes the highlight feature to fail.

In a previous question, Link with underscore does not work, a problem with underscores (_) being escaped to %5F was noted and has since been resolved.

Could a change be made to prevent escaping the tilde character (~) in Markdown links?


* - "Link to highlight" is a standard feature in Google Chrome, and is available as an addon for other browsers.

5
  • So, to clarify, links composed as HTML anchor elements (<a>) keep the ~ character unescaped, but Markdown footnote links do not. Does this happen with Markdown inline links ([link text](url)) as well?
    – zcoop98
    Sep 22 '21 at 19:04
  • @zcoop98 - Didn't try it. I don't normally use that form.
    – Rick Smith
    Sep 22 '21 at 19:07
  • 3
    It appears it's the same, inline links also escape the ~, breaking highlighting.
    – zcoop98
    Sep 22 '21 at 19:14
  • See also: stackoverflow.com/a/62162093
    – Rob
    Sep 22 '21 at 19:25
  • 1
    @Rick Just made a pretty substantial edit to try and improve the overall clarity of what's going on, and highlight specifically why the link isn't working. If you feel its too drastic, or strayed too far, please feel free to rollback or edit it to your linking.
    – zcoop98
    Sep 22 '21 at 19:51

You must log in to answer this question.

Browse other questions tagged .