Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

URL autoreplacing is non-standard, only works unexpected if URLs are surrounded by '<>'URLs are not auto-replaced #36

Open
okurz opened this issue Dec 21, 2015 · 0 comments

Comments

@okurz
Copy link

okurz commented Dec 21, 2015

observation

$text =~ s{<((https?|ftp):[^'">\s]+)>}{<a href="$1">$1</a>}gi;
tells that there is an autoreplacement of https?|ftp URLs which is a nice feature. I stumpled upon the implementation as I tried to extend URL replacement in comments in
os-autoinst/openQA#490 where I assumed Perl::Markdown does not have this feature at all.

current behavior

Researching code I found out that it actually does but only if the URL is surrounded by '<>' which was unexpected. IIUC standard markdown does not foresee URL auto-replacement for http/https/ftp, see http://daringfireball.net/projects/markdown/syntax

expected behavior

  • EITHER: no replacement
  • OR: replacement of all http[s]?|ftp references without the '<>' in all cases where it stands free and is not already part of a HTML block (or verbatim block, of course)
  • OR: support the common [link](url) syntax

suggestion

Replace
$text =~ s{<((https?|ftp):[^'">\s]+)>}{<a href="$1">$1</a>}gi;
by
$text =~ s{(?<!['"(])((http[s]?|ftp)://[^\s]*)}{<a href="$1">$1</a>}gi;

  • using "negative look-behind" to not match within quotes or html-hrefs or as part of a markdown link (using []() syntax)
  • matching also references without '<>'
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant