r81865 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81864‎ | r81865 | r81866 >
Date:01:59, 10 February 2011
Author:reedy
Status:resolved
Tags:
Comment:
*(bug 10081) Allow html attribute on SyntaxHighlight GeSHi extension

Patch by Umherirrender

(Seems to be all but based on the Poem implementation, as per Brions suggestion)
Modified paths:
  • /trunk/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php
@@ -89,15 +89,35 @@
9090 $out = str_replace( "\n", '', $out );
9191 // Register CSS
9292 $parser->mOutput->addHeadItem( self::buildHeadItem( $geshi ), "source-{$lang}" );
 93+
 94+ $encloseTag = $enclose === GESHI_HEADER_NONE ? 'span' : 'div';
 95+ $attribs = Sanitizer::validateTagAttributes( $args, $encloseTag );
 96+
 97+ //lang is valid in HTML context, but also used on GeSHi
 98+ unset( $attribs['lang'] );
 99+
93100 if ( $enclose === GESHI_HEADER_NONE ) {
94 - $out = '<span class="mw-geshi '.$lang.' source-'.$lang.'">' . $out . '</span>';
 101+ $attribs = self::addAttribute( $attribs, 'class', 'mw-geshi ' . $lang . ' source-' . $lang );
95102 } else {
96 - $out = '<div dir="ltr" class="mw-geshi" style="text-align: left;">' . $out . '</div>';
 103+ $attribs = self::addAttribute( $attribs, 'dir', 'ltr' );
 104+ $attribs = self::addAttribute( $attribs, 'class', 'mw-geshi' );
 105+ $attribs = self::addAttribute( $attribs, 'style', 'text-align: left;' );
97106 }
 107+ $out = Xml::tags( $encloseTag, $attribs, $out );
 108+
98109 wfProfileOut( __METHOD__ );
99110 return $out;
100111 }
101112
 113+ private static function addAttribute( $attribs, $name, $value ) {
 114+ if( isset( $attribs[$name] ) ) {
 115+ $attribs[$name] = $value . ' ' . $attribs[$name];
 116+ } else {
 117+ $attribs[$name] = $value;
 118+ }
 119+ return $attribs;
 120+ }
 121+
102122 /**
103123 * Take an input specifying a list of lines to highlight, returning
104124 * a raw list of matching line numbers.

Follow-up revisions

RevisionCommit summaryAuthorDate
r81925Minor followup to r81865, only set dir to ltr if it's not already set to some...reedy00:31, 11 February 2011

Status & tagging log