Here is another (much more elaborate) attempt at fixing the
pentuple-apostrophe problem (patch below).
This should handle all situations correctly where users enter
correctly nested mark-up, e.g. '' text ''' text
'''''.
Even for incorrectly nested mark-up, it often returns desirable
results:
'' text ''' text '' text '''
is turned into
<em> text <strong> text </strong></em><strong> text
</strong>
However, for incorrect mark-up, it sometimes returns weird results.
For example, for the following input:
'' text ''' text '' text
if I'm not mistaken (remember I don't have an installation to test
it on), it will return:
<em> text <strong> text </strong></em>''' text
which is at least correct HTML.
Anyway, here's the patch.
Greetings,
Timwi
--- OutputPage-orig.php Sun Jun 29 15:36:00 2003
+++ OutputPage.php Sun Jun 29 15:35:08 2003
@@ -675,9 +675,67 @@
/* private */ function doQuotes( $text )
{
- $text = preg_replace( "/'''(.+)'''/mU",
"<strong>\$1</strong>", $text );
- $text = preg_replace( "/''(.+)''/mU",
"<em>\$1</em>", $text );
- return $text;
+ if ( preg_match( "/^(.*)''(.*)$/mU", $text, $m ) ) {
+ if ( substr ($m[2], 0, 1) == "'" ) {
+ return $m[1] . doQuotesStrong ( substr ($m[2], 1) );
+ } else {
+ return $m[1] . doQuotesEm ( $m[2] );
+ }
+ } else {
+ return $text;
+ }
+ }
+
+ /* private */ function doQuotesEm( $text )
+ {
+ if ( preg_match( "/^(.*)''(.*)$/mU", $text, $m ) ) {
+ if ( substr ($m[2], 0, 1) == "'" ) {
+ return doQuotesEmStrong ( $m[1], substr ($m[2], 1) );
+ } else {
+ return "<em>" . $m[1] . "</em>" . doQuotes ( $m[2]
);
+ }
+ } else {
+ return "''" . $text;
+ }
+ }
+
+ /* private */ function doQuotesStrong( $text )
+ {
+ if ( preg_match( "/^(.*)''(.*)$/mU", $text, $m ) ) {
+ if ( substr ($m[2], 0, 1) == "'" ) {
+ return "<strong>" . $m[1] . "</strong>" . doQuotes (
substr ($m[2], 1) );
+ } else {
+ return doQuotesStrongEm ( $m[1], $m[2] );
+ }
+ } else {
+ return "'''" . $text;
+ }
+ }
+
+ /* private */ function doQuotesEmStrong( $pre, $text )
+ {
+ if ( preg_match( "/^(.*)''(.*)$/mU", $text, $m ) ) {
+ if ( substr ($m[2], 0, 1) == "'" ) {
+ return doQuotesEm ( $pre . "<strong>" . $m[1] .
"</strong>" . substr ($m[2], 1) );
+ } else {
+ return "<em>" . $pre . "<strong>" . $m[1] .
"</strong></em>" . doQuotesStrong ( $m[2] );
+ }
+ } else {
+ return "'''''" . $text;
+ }
+ }
+
+ /* private */ function doQuotesStrongEm( $pre, $text )
+ {
+ if ( preg_match( "/^(.*)''(.*)$/mU", $text, $m ) ) {
+ if ( substr ($m[2], 0, 1) == "'" ) {
+ return "<strong>" . $pre . "<em>" . $m[1] .
"</em></strong>" . doQuotesEm ( substr ($m[2],
1) );
+ } else {
+ return doQuotesStrong ( $pre . "<em>" . $m[1] .
"</em>" . $m[2] );
+ }
+ } else {
+ return "'''''" . $text;
+ }
}
/* private */ function doHeadings( $text )