It would be nice if autolink could be matched on more leading punctuations #235

Closed
opened 2026-01-29 14:31:01 +00:00 by claunia · 4 comments
Owner

Originally created by @jijiechen on GitHub (Oct 27, 2018).

In current implementation of Markdig as of 0.15.2, links are not automatically created if there are more kinds of leading punctuations than the ones recognized by Markdig at here:

https://github.com/lunet-io/markdig/blob/master/src/Markdig/Extensions/AutoLinks/AutoLinkParser.cs#L34

(Only whitespace, *, *, _, ~ ( are accepted for now).

So if links could be matched and created on more kinds of leading punctuations, that'll be nice. Either list more allowed punctuations or make the IsValidPreviousCharacter method an instance method and overridable is helpful.

I know and fully understand that it's a normal manner to put whitespaces before links in English (because links are just new words in sentences.) But in other languages, like Chinese, it's also normal there are other punctuations before links.

For instance:

请访问网址查看更多:https://share.weiyun.com/5D8g7nO

Punctuations need to be matched are:

new []{ ':', '。', ',', '、', '—', ';', '!', '?', '(' };
Originally created by @jijiechen on GitHub (Oct 27, 2018). In current implementation of Markdig as of 0.15.2, links are not automatically created if there are more kinds of leading punctuations than the ones recognized by Markdig at here: https://github.com/lunet-io/markdig/blob/master/src/Markdig/Extensions/AutoLinks/AutoLinkParser.cs#L34 (Only whitespace, `*`, `*`, `_`, `~` `(` are accepted for now). So if links could be matched and created on more kinds of leading punctuations, that'll be nice. Either list more allowed punctuations or make the `IsValidPreviousCharacter` method an instance method and overridable is helpful. I know and fully understand that it's a normal manner to put whitespaces before links in English (because links are just new words in sentences.) But in other languages, like Chinese, it's also normal there are other punctuations before links. For instance: ``` 请访问网址查看更多:https://share.weiyun.com/5D8g7nO ``` Punctuations need to be matched are: ```cs new []{ ':', '。', ',', '、', '—', ';', '!', '?', '(' }; ```
claunia added the enhancementPR Welcome! labels 2026-01-29 14:31:01 +00:00
Author
Owner

@xoofx commented on GitHub (Oct 29, 2018):

Yes, markdig should follow what GitHub is actually expecting for autolinks.

You can make a PR by changing the test:

c.IsWhiteSpaceOrZero() || c == '*' || c == '_' || c == '~' || c == '(';

and using a string instead:

public string ValidPreciousCharacters {get; set; }

ValidPreciousCharacters = "*_~( \t";

ValidPreciousCharacters.Contains(c)  (check other whitespace characters)

PR welcome!

@xoofx commented on GitHub (Oct 29, 2018): Yes, markdig should follow what [GitHub is actually expecting](https://github.github.com/gfm/#autolinks-extension-) for autolinks. You can make a PR by changing the test: ``` c.IsWhiteSpaceOrZero() || c == '*' || c == '_' || c == '~' || c == '('; ``` and using a string instead: ``` public string ValidPreciousCharacters {get; set; } ValidPreciousCharacters = "*_~( \t"; ValidPreciousCharacters.Contains(c) (check other whitespace characters) ``` PR welcome!
Author
Owner

@MihaZupan commented on GitHub (Oct 29, 2018):

Would something like #264 be okay?

(Most of it is just exposing the public field)

@MihaZupan commented on GitHub (Oct 29, 2018): Would something like #264 be okay? (Most of it is just exposing the public field)
Author
Owner

@jijiechen commented on GitHub (Oct 29, 2018):

This is a just-pushed commit!
I think so, it should match the requirement. Many thanks!

@jijiechen commented on GitHub (Oct 29, 2018): This is a just-pushed commit! I think so, it should match the requirement. Many thanks!
Author
Owner

@MihaZupan commented on GitHub (Apr 5, 2019):

Closing as resolved

@MihaZupan commented on GitHub (Apr 5, 2019): Closing as resolved
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#235