summaryrefslogtreecommitdiff
path: root/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-01-14 19:24:18 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-01-14 19:24:18 +0100
commit224b22a051051f6c2e494c3a2fb4adb42898e2d1 (patch)
tree85a41a4cf8533bf740ec4c8d3affce88414daa56 /extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php
parent9937b8e6d6a8b4517c04c143daaf9ebd42ce8ba0 (diff)
Update to MediaWiki 1.22.1
Diffstat (limited to 'extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php')
-rw-r--r--extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php43
1 files changed, 37 insertions, 6 deletions
diff --git a/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php b/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php
index b1c9851d..7318574d 100644
--- a/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php
+++ b/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php
@@ -28,6 +28,12 @@ class SyntaxHighlight_GeSHi {
// Don't trim leading spaces away, just the linefeeds
$text = preg_replace( '/^\n+/', '', $text );
+ if( $wgUseTidy ) {
+ // HTML Tidy will convert tabs to spaces incorrectly (bug 30930).
+ // Preemptively replace the spaces in a more controlled fashion.
+ $text = self::tabsToSpaces( $text );
+ }
+
// Validate language
if( isset( $args['lang'] ) && $args['lang'] ) {
$lang = $args['lang'];
@@ -95,12 +101,6 @@ class SyntaxHighlight_GeSHi {
if( $enclose === GESHI_HEADER_DIV ) {
$out = str_replace( "\n", '', $out );
}
- // HTML Tidy will convert tabs to spaces incorrectly (bug 30930).
- // But the conversion from tab to space occurs while reading the input,
- // before the conversion from &#9; to tab, so we can armor it that way.
- if( $wgUseTidy ) {
- $out = str_replace( "\t", '&#9;', $out );
- }
// Register CSS
$parser->getOutput()->addHeadItem( self::buildHeadItem( $geshi ), "source-{$lang}" );
@@ -488,4 +488,35 @@ class SyntaxHighlight_GeSHi {
public static function hOldSpecialVersion_GeSHi( &$sp, &$extensionTypes ) {
return self::hSpecialVersion_GeSHi( $extensionTypes );
}
+
+ /**
+ * Convert tabs to spaces
+ *
+ * @param string $text
+ * @return string
+ */
+ private static function tabsToSpaces( $text ) {
+ $lines = explode( "\n", $text );
+ $lines = array_map( array( __CLASS__, 'tabsToSpacesLine' ), $lines );
+ return implode( "\n", $lines );
+ }
+
+ /**
+ * Convert tabs to spaces for a single line
+ *
+ * @param $line
+ * @internal param string $text
+ * @return string
+ */
+ private static function tabsToSpacesLine( $line ) {
+ $parts = explode( "\t", $line );
+ $width = 8; // To match tidy's config & typical browser defaults
+ $out = $parts[0];
+ foreach( array_slice( $parts, 1 ) as $chunk ) {
+ $spaces = $width - (strlen( $out ) % $width);
+ $out .= str_repeat( ' ', $spaces );
+ $out .= $chunk;
+ }
+ return $out;
+ }
}