• It would be great if this plugin could preserve links from HTML.

    Example?:

    <a >my website</a>

    becomes in plain text?:

    my website (https://mywebsite.tld)

    Here is a line of code to do this?:

    +		// preserve links into brackets
    +		$text = preg_replace( '@<a .*href="(.*)".*>(.*)</a>@iu', "\$2 (\$1)", $text );
    +
    		// strip all remaining HTML tags
    		$text = strip_tags( $text );
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Benjamin Danon

    (@bndn)

    I updated the regex to accept double quote, single quotes or empty (space) url delimiters?:

    +		// preserve links into brackets
    +		$text = preg_replace( '@<a .*href=(?:"|')?([^"' ]*).*>(.*)</a>@iu', "\$2 (\$1)", $text );
    +
    		// strip all remaining HTML tags
    		$text = strip_tags( $text );
    Thread Starter Benjamin Danon

    (@bndn)

    Sorry, the previous code was broken due to missing escaping. It had not been fully tested.

    +		// preserve links into brackets
    +		$text = preg_replace( '@<a .*href=(?:"|\')?([^"\' ]*).*>(.*)</a>@iu', "\$2 (\$1)", $text );
    +
    		// strip all remaining HTML tags
    		$text = strip_tags( $text );
    Plugin Author Danny van Kooten

    (@dvankooten)

    Thank you @bndn, v1.2.0 includes this (albeit with a slightly modified regex).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Proposed feature : preserve links’ is closed to new replies.