Issues

Issue #2 resolved

Ignore links already wrapped in HTML tags

Joram van den Boezem
created an issue

Is it possible to add an option to ignore URLs already wrapped in HTML tags? I'm using a WYSIWYG editor with a limited range of formatting options, one of which is the option to include links. The WYSIWYG editor wraps the linked text in an A element, but I also use UrlLinker module to link all (not manually inserted) URLs. However, these two options are not compatible as I get output like

<a href="a href=" http:="" example.com="" 421"="" target="_blank" 421="" a"="">this is a link</a>

Thanks for your time and otherwise excellent module!

Comments (4)

  1. soupangel

    I happened to come across this issue today also. Being not too talented with the regexes, I implemented a very ugly hack until something more elegant can be concocted. Simply replace line 69 with:

    if ((preg_match('{^\.[0-9]{1,3}$}', $tld) || isset($validTlds[$tld])) && (strcmp(substr($text, $urlPosition -1, 1), '>') != 0) && (strcmp(substr($text, $urlPosition -1, 1), '\'') != 0) && (strcmp(substr($text, $urlPosition -1, 1), '"') != 0))
    

    Note this may glitch if you try to put your urls "in quotes", as the script will assume the quotes are from a href tag.

  2. Søren Løvborg repo owner

    This is a recurring request, but quite difficult to implement properly. As I note in my stackoverflow.com answer: "Handling plain text is complex enough; adding support for HTML (or any other markup language) in a safe way is much harder. If the input does contain tags, they should be stripped before processing." Obviously that suggestion doesn't help you, since you want to preserve tags.

    I'll leave this open for now, in the hope that I (or someone else) will get around to finding and implementing a good solution. :)

  3. Log in to comment