micromark / micromark-extension-gfm-autolink-literal

micromark extension to support GFM autolink literals
https://unifiedjs.com
MIT License
7 stars 3 forks source link

Escaped characters within a URL should be treated as literals #9

Closed robfig closed 1 year ago

robfig commented 1 year ago

Initial checklist

Affected packages and versions

Latest

Link to runnable example

No response

Steps to reproduce

import {micromark} from 'micromark'
import {
  gfmAutolinkLiteral,
  gfmAutolinkLiteralHtml
} from 'micromark-extension-gfm-autolink-literal'

const output = micromark('Just a URL: www.example.com/help\\_me .', {
  extensions: [gfmAutolinkLiteral()],
  htmlExtensions: [gfmAutolinkLiteralHtml()]
})

console.log(output)

I maintain a rich-text editor that stores content in Markdown. Literal underscores are escaped so that they are not interpreted. Markdown is the storage format, but the user is not typing markdown and they should not have to escape markdown special characters. The result is that underscores within a URL are escaped.

I believe there are two options:

The second option seems pretty difficult to me. I don't see other options.

The first option seems reasonable even for use cases other than my own -- the autolinker is used at display-time, yet it places restrictions on the way users author their markdown. That dependency seems undesirable.

Expected behavior

<p>Just a URL: <a href="http://www.example.com/help_me">www.example.com/help_me</a> .</p>

Actual behavior

<p>Just a URL: <a href="http://www.example.com/help%5C_me">www.example.com/help\_me</a> .</p>

Runtime

No response

Package manager

No response

OS

No response

Build and bundle tools

No response

wooorm commented 1 year ago

That’s how they work in GH: Just a URL: www.example.com/help_me .

ChristianMurphy commented 1 year ago

Welcome @robfig! 👋 Sorry you ran into a spot of trouble.

The current behavior matches GitHub Flavored markdown

You can confirm this by taking your example

Just a URL: www.example.com/help\\_me .

pasting it into GitHub


Just a URL: www.example.com/help\_me .


and inspecting the result

<a href="http://www.example.com/help%5C%5C_me" rel="nofollow">www.example.com/help\\_me</a>

micromark-extension-gfm-autolink matches the autolinking behavior to GitHub.

I maintain a rich-text editor that stores content in Markdown. Literal underscores are escaped so that they are not interpreted. Markdown is the storage format, but the user is not typing markdown and they should not have to escape markdown special characters. The result is that underscores within a URL are escaped.

My humble suggestion is have the editor generate valid GFM. Rather than creating yet another bespoke flavor of markdown.

wooorm commented 1 year ago

Markdown is the storage format, but the user is not typing markdown and they should not have to escape markdown special characters.

So is HTML. And users needs to know how to handle things like < too

github-actions[bot] commented 1 year ago

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.