From a19696f5117e9d96dad628a92261b381cc06cc23 Mon Sep 17 00:00:00 2001 From: Gabriel Wicke Date: Sun, 4 Apr 2004 01:45:02 +0000 Subject: [PATCH] xhtml tweaks, please review! fixed problems: * surplus closing p's * invalid nesting of table / div (floated images) / hr in

's * generation of multiple empty p's * invalid nesting of section editing spans * invalid anchor names- attention! this might break links! Replacing [^a-z0-9] -> '_' now known issues: * needs a space at the beginning of the first line in the wikisource to parse leading ''', * and similar --- includes/Parser.php | 64 ++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index b7e88122e8..93d92bda87 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -317,7 +317,7 @@ class Parser $fc = substr ( $x , 0 , 1 ) ; if ( "{|" == substr ( $x , 0 , 2 ) ) { - $t[$k] = "fixTagAttributes ( substr ( $x , 3 ) ) . ">" ; + $t[$k] = "\n
fixTagAttributes ( substr ( $x , 3 ) ) . ">" ; array_push ( $td , false ) ; array_push ( $ltd , "" ) ; array_push ( $tr , false ) ; @@ -420,7 +420,6 @@ class Parser $text = str_replace ( "
", "
", $text ); $text = $this->doHeadings( $text ); - $text = $this->doBlockLevels( $text, $linestart ); if($this->mOptions->getUseDynamicDates()) { global $wgDateFormatter; @@ -435,6 +434,7 @@ class Parser $sk =& $this->mOptions->getSkin(); $text = $sk->transformContent( $text ); + $text = $this->doBlockLevels( $text, $linestart ); $text .= $this->categoryMagic () ; wfProfileOut( $fname ); @@ -887,7 +887,7 @@ class Parser /* private */ function closeParagraph() { $result = ""; - if ( 0 != strcmp( "", $this->mLastSection ) ) { + if ( '' != $this->mLastSection ) { $result = "mLastSection . ">"; } $this->mLastSection = ""; @@ -968,8 +968,8 @@ class Parser # and making lists from lines starting with * # : etc. # $a = explode( "\n", $text ); - $text = "

"; # ?? - $lastPref = ""; + $a[0] = "\n".$a[0]; + $lastPref = $text = ''; $this->mDTopen = $inBlockElem = false; if ( ! $linestart ) { $text .= array_shift( $a ); } @@ -1022,32 +1022,36 @@ class Parser } if ( 0 == $npl ) { # No prefix--go to paragraph mode if ( preg_match( - "/(closeParagraph(); $inBlockElem = true; + } else if ( preg_match("/(closeParagraph(); + $inBlockElem = false; } if ( ! $inBlockElem ) { if ( " " == $t{0} ) { $newSection = "pre"; # $t = wfEscapeHTML( $t ); - } else { - $newSection = "p"; } + else { $newSection = "p"; } - if ( 0 == strcmp( "", trim( $oLine ) ) ) { - $text .= $this->closeParagraph(); - $text .= "<" . $newSection . ">"; - } else if ( 0 != strcmp( $this->mLastSection, - $newSection ) ) { - $text .= $this->closeParagraph(); - if ( 0 != strcmp( "p", $newSection ) ) { + if ( '' == trim( $oLine ) ) { + if ( $this->mLastSection != 'p') { + $text .= $this->closeParagraph(); $text .= "<" . $newSection . ">"; + $this->mLastSection = $newSection; + } else if ( $this->mLastSection == 'p') { + $text .= '
'; } + } else if ( $this->mLastSection == $newSection and $newSection != 'p' ) { + $text .= $this->closeParagraph(); + $text .= "<" . $newSection . ">"; + $this->mLastSection = $newSection; } - $this->mLastSection = $newSection; } if ( $inBlockElem && - preg_match( "/(<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|<\\/p)/i", $t ) ) { + preg_match( "/(<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|<\\/p<\\/div|<\\/pre)/i", $t ) ) { $inBlockElem = false; } } @@ -1269,7 +1273,7 @@ class Parser "ruby", "rt" , "rb" , "rp", "p" ); $htmlsingle = array( - "br", "hr", "li", "dt", "dd", "hr/" + "br", "hr", "li", "dt", "dd" ); $htmlnest = array( # Tags that can be nested--?? "table", "tr", "td", "th", "div", "blockquote", "ol", "ul", @@ -1465,8 +1469,7 @@ class Parser $canonized_headline = preg_replace( "/<.*?" . ">/","",$canonized_headline ); $tocline = trim( $canonized_headline ); - $canonized_headline = str_replace( '"', "", $canonized_headline ); - $canonized_headline = str_replace( " ", "_", trim( $canonized_headline) ); + $canonized_headline = preg_replace( "/[^a-z0-9]/i", "_", trim( $canonized_headline ) ); $refer[$headlineCount] = $canonized_headline; # count how many in assoc. array so we can track dupes in anchors @@ -1499,25 +1502,14 @@ class Parser } $head[$headlineCount] .= $sk->editSectionLink($headlineCount+1); } - - - # the headline might have a link - if( preg_match( "/(.*)$headline"; - } - # give headline the correct tag - @$head[$headlineCount] .= ""; - - # Add the edit section link + # Add the edit section span if( $rightClickHack ) { - $head[$headlineCount] = $sk->editSectionScript($headlineCount+1,$head[$headlineCount]); + $headline = $sk->editSectionScript($headlineCount+1,$headline); } + + # give headline the correct tag + @$head[$headlineCount] .= ""; $headlineCount++; } -- 2.20.1