diff options
-rw-r--r-- | inc/parser.php | 43 |
1 files changed, 20 insertions, 23 deletions
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("#<nowiki>(.*?)</nowiki>#","",$line); $line = preg_replace("#%%(.*?)%%#","",$line); $line = preg_replace("#<code( (\w+))?>(.*?)</code>#","",$line); - $line = preg_replace("#<file>(.*?)</file>#","",$line); - $line = preg_replace("#<html>(.*?)</html>#","",$line); - $line = preg_replace("#<php>(.*?)</php>#","",$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','<strong>\1</strong>',$text); //bold $text = preg_replace('/\'\'(.+?)\'\'/s','<code>\1</code>',$text); //code $text = preg_replace('#<del>(.*?)</del>#is','<del>\1</del>',$text); //deleted - $text = preg_replace('/^(\s)*----+(\s*)$/m',"</p>\n<hr noshade=\"noshade\" size=\"1\" />\n<p>",$text); //hr + $text = preg_replace('/^\s*----+\s*$/m',"</p>\n<hr noshade=\"noshade\" size=\"1\" />\n<p>",$text); //hr //sub and superscript - $text = preg_replace('#<sub>(.*?)</sub>#is','<sub>\1</sub>',$text); - $text = preg_replace('#<sup>(.*?)</sup>#is','<sup>\1</sup>',$text); + $text = preg_replace('#<su([bp])>(.*?)</su\1>#is','<su\1>\2</su\1>',$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('/(?<!-)--(?!-)/s','–',$text); //endash + $text = preg_replace('/(?<!-)---(?!-)/s','—',$text); //emdash + $text = preg_replace('/"([^\"]+?)"/s','“\1”',$text); //curly quotes + $text = preg_replace('/(?<=\s)\'(?=\S)/m','‘',$text); //single open quote + $text = preg_replace('/(?<=\S)\'/','’',$text); //single closing quote or apostroph + $text = preg_replace('/\.\.\./','…',$text); //ellipse + $text = preg_replace('/(?<=\d)x(?=\d)/i','×',$text); //640x480 $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('/=>/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)#',"<br />\\1",$text); + $text = preg_replace('#\\\\\\\\(?=\s)#',"<br />",$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] = '<img src="'.DOKU_BASE.'smileys/'.$sm[1].'" align="middle" alt="'.$sm[0].'" />'; $sm[0] = preg_quote($sm[0],'/'); - firstpass($table,$text,'/(\W)'.$sm[0].'(\W)/s',$sm[1],"\\1","\\2"); + firstpass($table,$text,'/(?<!\w)'.$sm[0].'(?!\w)/s',$sm[1]); } } @@ -489,7 +486,7 @@ function acronyms(&$table,&$text){ if(empty($acro)) continue; list($ac,$desc) = preg_split('/\s+/',$acro,2); $ac = preg_quote($ac,'/'); - firstpass($table,$text,'/(\b)('.$ac.')(\b)/s',"<acronym title=\"$desc\">\\2</acronym>","\\1","\\3"); + firstpass($table,$text,'/\b('.$ac.')\b/s',"<acronym title=\"$desc\">\\1</acronym>"); } } |