Made strong/em handling more forgiving against unbalanced ticks
authorGabriel Wicke <gwicke@users.mediawiki.org>
Fri, 14 May 2004 00:18:43 +0000 (00:18 +0000)
committerGabriel Wicke <gwicke@users.mediawiki.org>
Fri, 14 May 2004 00:18:43 +0000 (00:18 +0000)
* close any open em's or strong tags before each heading
* close any open em's or strong's at the end of the text

includes/Parser.php
includes/Tokenizer.php

index e65acb3..05c6786 100644 (file)
@@ -861,6 +861,19 @@ class Parser
                                        # empty token
                                        $txt="";
                                        break;
+                               case "h": 
+                                       #heading- used to close all unbalanced bold or em tags in this section
+                                       $txt = '';
+                                       if( $state['em'] !== false and 
+                                       ( $state['strong'] === false or $state['em'] > $state['strong'] ) )
+                                       { 
+                                               $s .= '</em>';
+                                               $state['em'] = false;
+                                       }
+                                       if ( $state['strong'] !== false ) $txt .= '</strong>';
+                                       if ( $state['em'] !== false ) $txt .= '</em>';
+                                       $state['strong'] = $state['em'] = false;
+                                       break;
                                case "RFC ":
                                        if ( $tagIsOpen ) {
                                                $txt = "RFC ";
@@ -904,6 +917,19 @@ class Parser
                                $s .= $txt;
                        }
                } #end while
+
+               # make 100% sure all strong and em tags are closed
+               # doBlockLevels often messes the last bit up though, but invalid nesting is better than unclosed tags
+               # tidy solves this though
+               if( $state['em'] !== false and 
+               ( $state['strong'] === false or $state['em'] > $state['strong'] ) )
+               { 
+                       $s .= '</em>';
+                       $state['em'] = false;
+               }
+               if ( $state['strong'] !== false ) $s .= '</strong>';
+               if ( $state['em'] !== false ) $s .= '</em>';
+
                if ( count( $tokenStack ) != 0 )
                {
                        # still objects on stack. opened [[ tag without closing ]] tag.
index 0b313d5..ab18b10 100644 (file)
@@ -147,7 +147,7 @@ class Tokenizer {
                                                }
                                                break;
                                        case "\n": // for block levels, actually, only "----" is handled.
-                                       case "\r":
+                                       case "\r": // headings are detected to close any unbalanced em or strong tags in a section
                                                if ( $this->continues( "----" ) )
                                                {
                                                        $queueToken["type"] = "----";
@@ -160,6 +160,21 @@ class Tokenizer {
                                                                $this->mPos ++;
                                                        }
                                                        break 2;
+                                               } else if ( 
+                                                       $this->continues( "<h" ) and (
+                                                               $this->continues( "<h1" ) or
+                                                               $this->continues( "<h2" ) or 
+                                                               $this->continues( "<h3" ) or 
+                                                               $this->continues( "<h4" ) or 
+                                                               $this->continues( "<h5" ) or
+                                                               $this->continues( "<h6" ) 
+                                                       )
+                                               ) { // heading
+                                                       $queueToken["type"] = "h";
+                                                       $queueToken["text"] = "";
+                                                       $this->mQueuedToken[] = $queueToken;
+                                                       $this->mPos ++;
+                                                       break 2; // switch + while
                                                }
                                                break;
                                        case "!": // French spacing rules have a space before exclamation