4

If I select some text in a post and try to turn it into a link (CTRL + L) the render isn't formatting it correctly:

https://docs.microsoft.com/en-us/powershell/scripting/developer/module/how-to-write-a-powershell-module-manifest?view=powershell-7.2&viewFallbackFrom=powershell-6#:~:text=MyCmdlet%22%2C%20%22Test-MyCmdlet%22)-,variablestoexport

[Can't make this a link][1]

Here is how I got the text fragment link:

getting a text fragment link from chrome screenshot

Reference: text fragment links: https://mgearon.com/html/text-fragments/

[1]: https://docs.microsoft.com/en-us/powershell/scripting/developer/module/how-to-write-a-powershell-module-manifest?view=powershell-7.2&viewFallbackFrom=powershell-6#:~:text=MyCmdlet%22%2C%20%22Test-MyCmdlet%22)-,variablestoexport

8
  • Ctrl + K is used to create preformatted text. Did you mean Ctrl + L?
    – Justin
    Commented Aug 3, 2022 at 14:02
  • 1
    yep, thanks! fixed ✅. (CTRL + K in most apps except SO 🤷‍♂️) @Justin Commented Aug 3, 2022 at 16:27
  • 1
    I'm fairly sure there's a duplicate of this somewhere. I know I've discussed where and how such links work have at least in comments on either MSO or MSE.
    – Makyen Mod
    Commented Aug 3, 2022 at 16:59
  • 2
    Note: Scroll-To-Text Fragment is non-standard, but something like it will, probably, eventually be standard. It's primarily supported by Chrome and browsers based on Chromium, but not other browsers. So, while I agree that this should be supported in SE's backend conversion of Markdown➞HTML, it's debatable what level of priority this should be for SE.
    – Makyen Mod
    Commented Aug 3, 2022 at 17:16
  • 1
    I'd note that the issue could/should be considered a bug in Chromium, in that it's not recognizing :%7E:text= as a valid alternate for :~:text=. Even the IETF RFC3986 section 2.4 says 'For example, the octet corresponding to the tilde ("~") character is often encoded as "%7E" by older URI processing implementations; the "%7E" can be replaced by "~" without changing its interpretation.' So, technically, this looks like a bug in Chromium's implementation. At a minimum, people will likely point fingers back and forth as to responsibility.
    – Makyen Mod
    Commented Aug 3, 2022 at 17:33
  • 1
    Duplicate on MSE: "Prevent Markdown links from escaping the tilde character (~) on Stack Exchange"
    – Makyen Mod
    Commented Aug 3, 2022 at 17:41
  • seems like I should close this as a duplicate of that other post you mentioned, thoughts @Makyen? Commented Aug 4, 2022 at 14:06
  • 2
    @spottedmahn: It's not possible to close questions on MSO as duplicates of questions on MSE.
    – Justin
    Commented Aug 4, 2022 at 14:11

1 Answer 1

6

The reason this particular link breaks markdown so much is because of the unescaped ")". This is effectively ending the URL parsing.

The standard markdown for links looks like:

[display text](url)

The expectation is that the url does not contain an unescaped or unencoded ")", since this is used to represent the end of link markdown (with one exception).

Under normal circumstances the ) could be escaped with a slash \). In comments, chat, and in the preview display of posts escaping the parenthesis is enough.

The following markdown will work in all of the above mentioned locations:

[VariablesToExport](https://docs.microsoft.com/en-us/powershell/scripting/developer/module/how-to-write-a-powershell-module-manifest?view=powershell-7.2&viewFallbackFrom=powershell-6#:%7E:text=MyCmdlet%22%2C%20%22Test%2DMyCmdlet%22\)-,VariablesToExport,-Type%3A%20String)

However, that will not fully work in this case, because the tilde character (~) gets converted to %7E on the server side which will cause the scroll-to-text fragment link not to function in the rendered post. e.g. (This will not work) VariablesToExport

Really the only option, currently, to have a working text fragment link in a post is a standard anchor element (<a>) e.g. VariablesToExport

Markdown:

<a href="https://docs.microsoft.com/en-us/powershell/scripting/developer/module/how-to-write-a-powershell-module-manifest?view=powershell-7.2&viewFallbackFrom=powershell-6#:~:text=MyCmdlet%22%2C%20%22Test%2DMyCmdlet%22)-,VariablesToExport,-Type%3A%20String">VariablesToExport</a>

As Makyen mentioned, it's arguably an implementation error on the Chrome/Chromium side treating the ~ (an unreserved character) as distinct from the encoded %7E, but as it stands the only way to have functional text fragment links in Stack Exchange questions and answers is to use an anchor element above.

It's also important to note that scroll-to-text fragment links are currently not widely supported. Even when they are rendered correctly, they will not work for everyone. It is still a good idea to use more widely supported links instead of the scroll-to-text fragment when possible and to describe where on the page the link is pointing when using them.

2
  • I'd also note that while it is SE's backend Markdown➞HTML that converts "~" to "%7E", it's arguably a bug in Chrome's/Chromium's implementation that they don't convert that "%7E" back to "~" prior to using it as a delimiter. Given that the :~:text= is not a standard, I'd argue that it's actually Chrome's/Chromium's responsibility to do that.
    – Makyen Mod
    Commented Aug 3, 2022 at 17:51
  • The Scroll-To-Text Fragment link in my initial comment here didn't work, because the URL in the question is wrong/non-functional, even without the issues introduced with Markdown/SE's conversion. You've corrected that URL in your answer here. This link, which uses the URL you're using here should be functional.
    – Makyen Mod
    Commented Aug 3, 2022 at 18:02

You must log in to answer this question.

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