redcarpet icon indicating copy to clipboard operation
redcarpet copied to clipboard

URI encoding breaks linking to text fragments

Open dchacke opened this issue 1 year ago • 0 comments

Redcarpet seems to automatically URI encode the href for links. That’s fine in most cases except when linking to text fragments, where the tilde must not be encoded.

Current behavior:

'[foo](https://example.com#:~:text=bar)'
# => href: 'https://example.com#:%7E:text=bar'
#                                 ^

Expected behavior:

'[foo](https://example.com#:~:text=bar)'
# => href: 'https://example.com#:~:text=bar'
#                                ^

As a workaround, I use a heuristic for post processing:

def postprocess text
  text.gsub('#:%7E:text=', '#:~:text=')
end

dchacke avatar Oct 26 '24 21:10 dchacke