Don't convert URLs inside `<pre>` and `<code>` tags when parsing string using `make_clickable()`.
Adds Unit Tests. Props johnjamesjacoby, helen, nacin, adamsilverstein, sirbrillig. Fixes #23756. Built from https://develop.svn.wordpress.org/trunk@26052 git-svn-id: http://core.svn.wordpress.org/trunk@25977 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
6bf2d27c98
commit
275f39216a
|
@ -1606,8 +1606,15 @@ function _make_email_clickable_cb($matches) {
|
|||
function make_clickable( $text ) {
|
||||
$r = '';
|
||||
$textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags
|
||||
$nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code>
|
||||
foreach ( $textarr as $piece ) {
|
||||
if ( empty( $piece ) || ( $piece[0] == '<' && ! preg_match('|^<\s*[\w]{1,20}+://|', $piece) ) ) {
|
||||
|
||||
if ( preg_match( '|^<code[\s>]|', $piece ) || preg_match( '|^<pre[\s>]|', $piece ) )
|
||||
$nested_code_pre++;
|
||||
elseif ( ( '</code>' === $piece || '</pre>' === $piece ) && $nested_code_pre )
|
||||
$nested_code_pre--;
|
||||
|
||||
if ( $nested_code_pre || empty( $piece ) || ( $piece[0] === '<' && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) ) ) {
|
||||
$r .= $piece;
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue