Index: trunk/phase3/includes/parser/Tidy.php |
— | — | @@ -41,9 +41,15 @@ |
42 | 42 | dechex( mt_rand( 0, 0x7fffffff ) ) . dechex( mt_rand( 0, 0x7fffffff ) ); |
43 | 43 | $this->mMarkerIndex = 0; |
44 | 44 | |
| 45 | + // Replace <mw:editsection> elements with placeholders |
45 | 46 | $wrappedtext = preg_replace_callback( ParserOutput::EDITSECTION_REGEX, |
46 | 47 | array( &$this, 'replaceEditSectionLinksCallback' ), $text ); |
47 | 48 | |
| 49 | + // Modify inline Microdata <link> and <meta> elements so they say <html-link> and <html-meta> so |
| 50 | + // we can trick Tidy into not stripping them out by including them in tidy's new-empty-tags config |
| 51 | + $wrappedtext = preg_replace( '!<(link|meta)([^>]*?)(/{0,1}>)!', '<html-$1$2$3', $wrappedtext ); |
| 52 | + |
| 53 | + // Wrap the whole thing in a doctype and body for Tidy. |
48 | 54 | $wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'. |
49 | 55 | ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'. |
50 | 56 | '<head><title>test</title></head><body>'.$wrappedtext.'</body></html>'; |
— | — | @@ -68,7 +74,13 @@ |
69 | 75 | * @return string |
70 | 76 | */ |
71 | 77 | public function postprocess( $text ) { |
72 | | - return $this->mTokens->replace( $text ); |
| 78 | + // Revert <html-{link,meta}> back to <{link,meta}> |
| 79 | + $text = preg_replace( '!<html-(link|meta)([^>]*?)(/{0,1}>)!', '<$1$2$3', $text ); |
| 80 | + |
| 81 | + // Restore the contents of placeholder tokens |
| 82 | + $text = $this->mTokens->replace( $text ); |
| 83 | + |
| 84 | + return $text; |
73 | 85 | } |
74 | 86 | |
75 | 87 | } |
Index: trunk/phase3/includes/tidy.conf |
— | — | @@ -18,4 +18,6 @@ |
19 | 19 | fix-uri: no |
20 | 20 | |
21 | 21 | # Don't strip html5 elements we support |
| 22 | +# html-{meta,link} is a hack we use to prevent Tidy from stripping <meta> and <link> used in the body for Microdata |
| 23 | +new-empty-tags: html-meta, html-link |
22 | 24 | new-inline-tags: data, time |