From 86770f3ea6c33f97b6755d11ed9700e756ef6e88 Mon Sep 17 00:00:00 2001
From: andi
Date: Sat, 5 Mar 2005 12:38:19 +0100
Subject: regexp tuning
darcs-hash:20050305113819-9977f-019a17bfa6bc398167b50cc96d5083c642cb23ed.gz
---
inc/parser.php | 43 ++++++++++++++++++++-----------------------
1 file changed, 20 insertions(+), 23 deletions(-)
(limited to 'inc/parser.php')
diff --git a/inc/parser.php b/inc/parser.php
index 5c3c78851..0fe04afba 100644
--- a/inc/parser.php
+++ b/inc/parser.php
@@ -169,9 +169,7 @@ function preparse($text,&$table,&$hltable){
$line = preg_replace("#(.*?)#","",$line);
$line = preg_replace("#%%(.*?)%%#","",$line);
$line = preg_replace("#(.*?)
#","",$line);
- $line = preg_replace("#(.*?)#","",$line);
- $line = preg_replace("#(.*?)#","",$line);
- $line = preg_replace("#(.*?)#","",$line);
+ $line = preg_replace("#<(file|html|php)>(.*?)\\1>#","",$line);
//check for start of multiline noparse areas
if(preg_match('#^.*?<(nowiki|code|php|html|file)( (\w+))?>#',$line,$matches)){
list($noparse) = split(" ",$matches[1]); //remove options
@@ -346,7 +344,7 @@ function linkformat($match){
if(strpos($link['url'],'>')){
// InterWiki
$link = format_link_interwiki($link);
- }elseif(preg_match('#^([a-z0-9]+?){1}://#i',$link['url'])){
+ }elseif(preg_match('#^([a-z0-9]+?)://#i',$link['url'])){
// external URL
$link = format_link_externalurl($link);
}elseif(preg_match("/^\\\\\\\\([a-z0-9\-_.]+)\\\\(.+)$/",$link['url'])){
@@ -383,35 +381,34 @@ function simpleformat($text){
$text = preg_replace('/\*\*(.+?)\*\*/s','\1',$text); //bold
$text = preg_replace('/\'\'(.+?)\'\'/s','\1
',$text); //code
$text = preg_replace('#<del>(.*?)</del>#is','\1',$text); //deleted
- $text = preg_replace('/^(\s)*----+(\s*)$/m',"
\n
\n",$text); //hr
+ $text = preg_replace('/^\s*----+\s*$/m',"
\n
\n",$text); //hr
//sub and superscript
- $text = preg_replace('#<sub>(.*?)</sub>#is','\1',$text);
- $text = preg_replace('#<sup>(.*?)</sup>#is','\1',$text);
+ $text = preg_replace('#<su([bp])>(.*?)</su\1>#is','\2',$text);
//do quoting
$text = preg_replace("/\n((>)[^\n]*?\n)+/se","'\n'.quoteformat('\\0').'\n'",$text);
// Typography
if($conf['typography']){
- $text = preg_replace('/([^-])--([^-])/s','\1–\2',$text); //endash
- $text = preg_replace('/([^-])---([^-])/s','\1—\2',$text); //emdash
- $text = preg_replace('/"([^\"]+?)"/s','“\1”',$text); //curly quotes
- $text = preg_replace('/(\s)\'(\S)/m','\1‘\2',$text); //single open quote
- $text = preg_replace('/(\S)\'/','\1’',$text); //single closing quote or apostroph
- $text = preg_replace('/\.\.\./','\1…\2',$text); //ellipse
- $text = preg_replace('/(\d+)x(\d+)/i','\1×\2',$text); //640x480
+ $text = preg_replace('/(?>
$text = preg_replace('/<</i','«',$text); // <<
- $text = preg_replace('/<->/i','↔',$text); // <->
- $text = preg_replace('/<-/i','←',$text); // <-
- $text = preg_replace('/->/i','→',$text); // ->
+ $text = preg_replace('/<->/i','↔',$text); // <->
+ $text = preg_replace('/<-/i','←',$text); // <-
+ $text = preg_replace('/->/i','→',$text); // ->
- $text = preg_replace('/<=>/i','⇔',$text); // <=>
- $text = preg_replace('/<=/i','⇐',$text); // <=
- $text = preg_replace('/=>/i','⇒',$text); // =>
+ $text = preg_replace('/<=>/i','⇔',$text); // <=>
+ $text = preg_replace('/<=/i','⇐',$text); // <=
+ $text = preg_replace('/=>/i','⇒',$text); // =>
$text = preg_replace('/\(c\)/i','©',$text); // copyrigtht
$text = preg_replace('/\(r\)/i','®',$text); // registered
@@ -419,7 +416,7 @@ function simpleformat($text){
}
//forced linebreaks
- $text = preg_replace('#\\\\\\\\(\s)#',"
\\1",$text);
+ $text = preg_replace('#\\\\\\\\(?=\s)#',"
",$text);
// lists (blocks leftover after blockformat)
$text = preg_replace("/(\n( {2,}|\t)[\*\-][^\n]+)(\n( {2,}|\t)[^\n]*)*/se","\"\\n\".listformat('\\0')",$text);
@@ -472,7 +469,7 @@ function smileys(&$table,&$text){
$sm = preg_split('/\s+/',$smiley,2);
$sm[1] = '
';
$sm[0] = preg_quote($sm[0],'/');
- firstpass($table,$text,'/(\W)'.$sm[0].'(\W)/s',$sm[1],"\\1","\\2");
+ firstpass($table,$text,'/(?\\2","\\1","\\3");
+ firstpass($table,$text,'/\b('.$ac.')\b/s',"\\1");
}
}
--
cgit v1.2.3