From a76e8f10c49a9ee0902d00d9d12df1c8b8573a29 Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Mon, 20 Feb 2012 02:12:48 +0000 Subject: [PATCH] Followup r111903; Introduce a new Tidy hack to prevent tidy from stripping the and elements from the body which are used in Microdata. We do this by replacing every and with a or element and adding html-link and html-meta to tidy's new-empty-tags config so that Tidy doesn't strip it, and then restoring the elements back to normal. --- includes/parser/Tidy.php | 14 +++++++++++++- includes/tidy.conf | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/includes/parser/Tidy.php b/includes/parser/Tidy.php index 8bd80b2b73..2ae9e99dff 100644 --- a/includes/parser/Tidy.php +++ b/includes/parser/Tidy.php @@ -41,9 +41,15 @@ class MWTidyWrapper { dechex( mt_rand( 0, 0x7fffffff ) ) . dechex( mt_rand( 0, 0x7fffffff ) ); $this->mMarkerIndex = 0; + // Replace elements with placeholders $wrappedtext = preg_replace_callback( ParserOutput::EDITSECTION_REGEX, array( &$this, 'replaceEditSectionLinksCallback' ), $text ); + // 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 + $wrappedtext = preg_replace( '!<(link|meta)([^>]*?)(/{0,1}>)!', ''. 'test'.$wrappedtext.''; @@ -68,7 +74,13 @@ class MWTidyWrapper { * @return string */ public function postprocess( $text ) { - return $this->mTokens->replace( $text ); + // Revert back to <{link,meta}> + $text = preg_replace( '!]*?)(/{0,1}>)!', '<$1$2$3', $text ); + + // Restore the contents of placeholder tokens + $text = $this->mTokens->replace( $text ); + + return $text; } } diff --git a/includes/tidy.conf b/includes/tidy.conf index b0ff73bc73..6ae8d4515b 100644 --- a/includes/tidy.conf +++ b/includes/tidy.conf @@ -18,4 +18,6 @@ fix-backslash: no fix-uri: no # Don't strip html5 elements we support +# html-{meta,link} is a hack we use to prevent Tidy from stripping and used in the body for Microdata +new-empty-tags: html-meta, html-link new-inline-tags: data, time -- 2.20.1