From 025f82f9935a7648deb12a17d29d6d825ac1de3c Mon Sep 17 00:00:00 2001 From: Arne Heizmann Date: Fri, 11 Jul 2003 02:11:08 +0000 Subject: [PATCH] New apostrophe handling --- includes/OutputPage.php | 61 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index af099cc6b4..5a0337f7e2 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -679,7 +679,7 @@ class OutputPage { $text = preg_replace( "/(^|\n)-----*/", "\\1
", $text ); $text = str_replace ( "
", "
", $text ); - $text = $this->doQuotes( $text ); + $text = $this->doAllQuotes( $text ); $text = $this->doHeadings( $text ); $text = $this->doBlockLevels( $text, $linestart ); @@ -701,11 +701,62 @@ class OutputPage { return $text; } - /* private */ function doQuotes( $text ) + /* private */ function doAllQuotes( $text ) { - $text = preg_replace( "/'''(.+)'''/mU", "\$1", $text ); - $text = preg_replace( "/''(.+)''/mU", "\$1", $text ); - return $text; + $outtext = ""; + $lines = explode( "\r\n", $text ); + foreach ( $lines as $line ) { + $outtext .= $this->doQuotes ( "", $line, "" ) . "\r\n"; + } + return $outtext; + } + + /* private */ function doQuotes( $pre, $text, $mode ) + { + if ( preg_match( "/^(.*)''(.*)$/sU", $text, $m ) ) { + $m1_strong = ($m[1] == "") ? "" : "{$m[1]}"; + $m1_em = ($m[1] == "") ? "" : "{$m[1]}"; + if ( substr ($m[2], 0, 1) == "'" ) { + $m[2] = substr ($m[2], 1); + if ($mode == "em") { + return $this->doQuotes ( $m[1], $m[2], ($m[1] == "") ? "both" : "emstrong" ); + } else if ($mode == "strong") { + return $m1_strong . $this->doQuotes ( "", $m[2], "" ); + } else if (($mode == "emstrong") || ($mode == "both")) { + return $this->doQuotes ( "", $pre.$m1_strong.$m[2], "em" ); + } else if ($mode == "strongem") { + return "{$pre}{$m1_em}" . $this->doQuotes ( "", $m[2], "em" ); + } else { + return $m[1] . $this->doQuotes ( "", $m[2], "strong" ); + } + } else { + if ($mode == "strong") { + return $this->doQuotes ( $m[1], $m[2], ($m[1] == "") ? "both" : "strongem" ); + } else if ($mode == "em") { + return $m1_em . $this->doQuotes ( "", $m[2], "" ); + } else if ($mode == "emstrong") { + return "{$pre}{$m1_strong}" . $this->doQuotes ( "", $m[2], "strong" ); + } else if (($mode == "strongem") || ($mode == "both")) { + return $this->doQuotes ( "", $pre.$m1_em.$m[2], "strong" ); + } else { + return $m[1] . $this->doQuotes ( "", $m[2], "em" ); + } + } + } else { + $text_strong = ($text == "") ? "" : "{$text}"; + $text_em = ($text == "") ? "" : "{$text}"; + if ($mode == "") { + return $pre . $text; + } else if ($mode == "em") { + return $pre . $text_em; + } else if ($mode == "strong") { + return $pre . $text_strong; + } else if ($mode == "strongem") { + return (($pre == "") && ($text == "")) ? "" : "{$pre}{$text_em}"; + } else { + return (($pre == "") && ($text == "")) ? "" : "{$pre}{$text_strong}"; + } + } } /* private */ function doHeadings( $text ) -- 2.20.1