From: Max Semenik Date: Fri, 25 Oct 2013 18:02:11 +0000 (+0400) Subject: Fix Tidy quietly breaking TOC disabling X-Git-Tag: 1.31.0-rc.0~18386^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=d6f673c1157b75b33f9eeb3169fc2be25fb99da0;p=lhc%2Fweb%2Fwiklou.git Fix Tidy quietly breaking TOC disabling The functionality was introduced in I2889bcb9 but doesn't work in presence if Tidy. Change-Id: Ibf96cc3bc94fac75fd92ec5b9205011fcb68f0c2 --- diff --git a/includes/parser/Tidy.php b/includes/parser/Tidy.php index 06251402dd..32b16aafa8 100644 --- a/includes/parser/Tidy.php +++ b/includes/parser/Tidy.php @@ -61,7 +61,10 @@ class MWTidyWrapper { // Replace elements with placeholders $wrappedtext = preg_replace_callback( ParserOutput::EDITSECTION_REGEX, - array( &$this, 'replaceEditSectionLinksCallback' ), $text ); + array( &$this, 'replaceCallback' ), $text ); + // ...and markers + $wrappedtext = preg_replace_callback( '/\<\\/?mw:toc\>/', + array( &$this, 'replaceCallback' ), $wrappedtext ); // Modify inline Microdata and elements so they say and so // we can trick Tidy into not stripping them out by including them in tidy's new-empty-tags config @@ -80,7 +83,7 @@ class MWTidyWrapper { * * @return string */ - function replaceEditSectionLinksCallback( $m ) { + function replaceCallback( $m ) { $marker = "{$this->mUniqPrefix}-item-{$this->mMarkerIndex}" . Parser::MARKER_SUFFIX; $this->mMarkerIndex++; $this->mTokens->setPair( $marker, $m[0] ); diff --git a/tests/phpunit/includes/parser/TidyTest.php b/tests/phpunit/includes/parser/TidyTest.php new file mode 100644 index 0000000000..57a88b9d24 --- /dev/null +++ b/tests/phpunit/includes/parser/TidyTest.php @@ -0,0 +1,44 @@ +markTestSkipped( 'Tidy not found' ); + } + } + + /** + * @dataProvider provideTestWrapping + */ + public function testTidyWrapping( $expected, $text, $msg = '' ) { + $text = MWTidy::tidy( $text ); + // We don't care about where Tidy wants to stick is

s + $text = trim( preg_replace( '##', '', $text ) ); + // Windows, we love you! + $text = str_replace( "\r", '', $text ); + $this->assertEquals( $expected, $text, $msg ); + } + + public function provideTestWrapping() { + return array( + array( + 'foo', + 'foo', + ' should survive tidy' + ), + array( + 'foo', + 'foo', + ' should survive tidy' + ), + array( 'foo', 'foo', ' should survive tidy' ), + array( "\nfoo", 'foo', ' should survive tidy' ), + array( "\nfoo", 'foo', ' should survive tidy' ), + ); + } +} \ No newline at end of file