diff --git a/inc/functions.php b/inc/functions.php index 0902c764..f4acc0d0 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1306,6 +1306,8 @@ } function markup_url($matches) { + global $markup_urls; + $url = $matches[0]; $after = ''; @@ -1314,11 +1316,27 @@ $after = $match[1]; } + $markup_urls[] = $url; + return '' . $url . '' . $after; } + function unicodify($body) { + $body = str_replace('...', '…', $body); + $body = str_replace('<--', '←', $body); + $body = str_replace('-->', '→', $body); + + // En and em- dashes are rendered exactly the same in + // most monospace fonts (they look the same in code + // editors). + $body = str_replace('---', '–', $body); // em dash + $body = str_replace('--', '—', $body); // en dash + + return $body; + } + function markup(&$body, $track_cites = false) { - global $board, $config; + global $board, $config, $markup_urls; $body = utf8tohtml($body); @@ -1330,21 +1348,19 @@ } if($config['markup_urls']) { + $markup_urls = Array(); + $body = preg_replace_callback($config['url_regex'], 'markup_url', $body, -1, $num_links); if($num_links > $config['max_links']) error($config['error']['toomanylinks']); - }//exit; - + } + if($config['auto_unicode']) { - $body = str_replace('...', '…', $body); - $body = str_replace('<--', '←', $body); - $body = str_replace('-->', '→', $body); - - // En and em- dashes are rendered exactly the same in - // most monospace fonts (they look the same in code - // editors). - $body = str_replace('---', '–', $body); // em dash - $body = str_replace('--', '—', $body); // en dash + $body = unicodify($body); + + foreach($markup_urls as &$url) { + $body = str_replace(unicodify($url), $url, $body); + } } // replace tabs with 8 spaces