Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autolinking - URL surrounded by parentheses #266

Closed
joemun opened this issue Jun 14, 2016 · 7 comments
Closed

Autolinking - URL surrounded by parentheses #266

joemun opened this issue Jun 14, 2016 · 7 comments
Assignees

Comments

@joemun
Copy link

joemun commented Jun 14, 2016

Input:
(https://www.something.com/1234)

Results in:
(<a href="https://www.something.com/1234)">https://www.something.com/1234)</a>

Note that the trailing paren is included in the target URL.

@ghost
Copy link

ghost commented Jun 15, 2016

@joemunriq

(https://www.something.com/1234)

Input:

https://www.something.com/1234

Once parsed it becomes:

<a href="https://www.something.com/1234">https://www.something.com/1234</a>

Input:

Follow this [link] to learn more.

[link]: https://www.something.com/1234

Once parsed it becomes:

<a href="https://www.something.com/1234">link</a>

Input:

[link](https://www.something.com/1234)

Once parsed it becomes:

<a href="https://www.something.com/1234">link</a>

Input:

( https://www.something.com/1234 )

Once parsed it becomes:

( <a href="https://www.something.com/1234">https://www.something.com/1234</a> )

@joemun
Copy link
Author

joemun commented Jun 15, 2016

@wifiextender Thank you for the info... but I'm calling out one specific buggy behavior using Showdown's GFM auto-linking feature, which automatically creates a link when it identifies a URL (without using Markdown's link syntax). If the URL is contained within parens (without spaces), it will include the closing paren as part of the anchor's HREF.

@joemun
Copy link
Author

joemun commented Jun 15, 2016

It looks like GitHub and RedCarpet (the MD parser that GitHub uses) handles this case specifically. It looks for enclosing parens:

https://github.com/vmg/redcarpet/blob/00d4e02a2cc3ada39c2547529b29fb2f871a83fb/ext/redcarpet/autolink.c

(Example: https://github.com/vmg/redcarpet/blob/00d4e02a2cc3ada39c2547529b29fb2f871a83fb/ext/redcarpet/autolink.c#L115)

Can we get these same rules applied to Showdown?

Thanks!

@tivie
Copy link
Member

tivie commented Jun 16, 2016

This is a tricky situation because parenthesis are allowed in urls and there can be situations where the rules used by RedCarpet will wrongly exclude the parentehsis from the url.

For instance:

The url is http://www.example.com/a/link/that/ends/in/parenthesis)

So this:

(http://www.example.com/a/link/that/ends/in/parenthesis) is a link with parentehsis)

gets converted into this:

(http://www.example.com/a/link/that/ends/in/parenthesis) is a link with parentehsis)

<p>(<a href="http://www.example.com/a/link/that/ends/in/parenthesis">http://www.example.com/a/link/that/ends/parenthesis</a>) is a link with parentehsis)</p>

which is wrong.

Sure, this is an edge case, and it's highly unlikely that an URL will end in a single unpaired parenthesis but...

@tivie
Copy link
Member

tivie commented Jun 16, 2016

on the other hand, it's really easy to workaround this issue:

(<https://www.something.com/1234>)

@tivie
Copy link
Member

tivie commented Jun 16, 2016

Regardless, since we have a "GitHub markdown flavour", that tries to follow github rules, I will create an option that implements the rules of github regarding parentehsis in autolinks.

This option will be disabled by default, and you would need to explicitely enable it.

@tivie
Copy link
Member

tivie commented Dec 1, 2016

This was added as a new option called excludeTrailingPunctuationFromURLs. Enabling this option will remove trailing punctuation and parenthesis from URL parsing in auto linking.

@tivie tivie closed this as completed in d2fc2a0 Dec 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants