Extension talk:SyntaxHighlight GeSHi/Archive 2012

From mediawiki.org
Jump to navigation Jump to search

Where to save/load Geshi.css

Please add instructions on where to save the css file and, if necessary, how to telll geshi to use it. — Preceding unsigned comment added by (talkcontribs) 14:14, 23 January 2012‎

You don't have to save it anywhere. The extension automatically loads it from the MediaWiki:Geshi.css wiki page. You only need to edit that page. Krinkle 01:18, 24 January 2012 (UTC)
Hi Timo,
Yes, that seems to be working. Thanks.

Highlighting code from external links

Hi, I had a need to use syntax highlighting not on internaly written code but directly on external java source files so I added an "extlink" parameter to the <syntaxhighlight> tag. Now, just write something like:

<syntaxhighlight lang="java" extlink="http://my.server.com/my_dir/my_source.java"/>

and the content of http://my.server.com/my_dir/my_source.java will be inserted and highlighted in your page.

To add this to the extension, quite simple, just add the following lines

if ( isset( $args['extlink'] ) && $args['extlink'] ) {
  $text  = file_get_contents ( $args['extlink'] );

in SyntaxHighlight_GeSHi.php near line 50 just above the line

$geshi = self::prepare( $text, $lang );
Could this be added to the supported extension? I'd like this feature as well (but I would suggest using 'src' instead of 'extlink', analogous to HTML's <img src=.../>) In our case, the target URL would be elsewhere on our intranet, or even a File: in the wiki. Thus, ideally, the parameter would work with a File: page name (which would need to be a text file) --DavidBiesack (talk) 15:00, 10 July 2014 (UTC)

"<syntaxhighlight> is recommended"

Extension:Collection (which is used to create downloadable PDFs or books from WMF pages) doesn't support <syntaxhighlight>, only <source> (see bugzilla:29136). I wonder, therefore, if we should remove from this page the statement that "<syntaxhighlight> is recommended"? —RuakhTALK 20:10, 28 February 2012 (UTC)

Reopening the bug should be enough. syntaxhighlight is still recommended, but you can use source as a workaround until the Collection extension is fixed. Reach Out to the Truth (talk) 02:18, 29 February 2012 (UTC)
This seems to be working now, although it fails to honour the enclose=none parameter. —Phil | Talk 17:07, 27 November 2012 (UTC)

Vote to make box and border pre the default

Personally I think geshi should look like other pre boxes, should the following be included in MediaWiki:Geshi.css by default?

div.mw-geshi {
  padding: 1em; 
  margin: 1em 0; 
  border: 1px dashed #2f6fab;
  background-color: #f9f9f9;

Better still could be to remove the problem css that strips the skin default. CSS like this...

.source-winbatch li, .source-winbatch pre {
  line-height: normal;
  border: 0px none white;


.winbatch.source-winbatch .de1, .winbatch.source-winbatch .de2 {
font: normal normal 1em/1.2em monospace;
margin: 0;
padding: 0;
background: none;
vertical-align: top;

Just my thoughts. Thanks for a great extension.

I hope that maybe Gerrit change 15781 improves the situation (with empty MediaWiki:Geshi.css, which is the MediaWiki default).  « Saper // talk »  11:33, 17 July 2012 (UTC)

README still suggests to use 'source' tag

README file still suggests to use "source" tag - probably should be updated --Richlv (talk) 11:06, 2 April 2012 (UTC)

Not displaying colors when formatting?

Having this issue on 1.18, anyone else experiencing this? How do I fix?

  • Whats your sample code? did you use a valid value inside of, lang?

Support for additional class

The standard gray background and dashed border looks great for most of the snippets but we have a scenario where we have examples of good and bad snippets of code. With our previous manual way of syntax highlighting code, we were able to apply a different class to highlight the code light green with a check in the upper right for good code, light red with an X in the upper right for bad code. In order to support the same functionality with this extension, we added a new attribute to the tag and had to modify SyntaxHighlight_GeSHi.class.php, line 122 to support it. Note that you may want to add the change to the other part of the condition there.

$attribs = self::addAttribute( $attribs, 'class', 'mw-geshi mw-content-' . $attribs['dir'] . ' ' );
$addclass = isset( $args['addclass'] ) ? $args['addclass'] : '' ;
$attribs = self::addAttribute( $attribs, 'class', 'mw-geshi mw-content-' . $attribs['dir'] . ' ' . $addclass );

In addition, we had to add !important to our CSS to get it to override the other selectors:

div.code-good {
	background: #efffef url(/mediawiki-1.19/skins/common/tmhp/silk-icons/tick.png) no-repeat top right !important;
	border-color: #6c6 !important;
div.code-bad {
	background: #ffefef url(/mediawiki-1.19/skins/common/tmhp/silk-icons/cancel.png) no-repeat top right !important;
	border: 1px dashed #c66 !important;

So now we can use the new addclass attribute on the extension:

  <syntaxhighlight lang='html' addclass='code-good'>
    Some code here.

Mattsmith321 (talk) 20:35, 25 August 2012 (UTC)

I like this idea in concept, do you have a link to an example page with a few examples of this in action? ShoeMaker   ( Contributions Message )   12:15, 12 March 2013 (UTC)
Here is an example screenshot from our wiki:
SyntaxHighlight with custom class.png
Mattsmith321 (talk) 21:21, 16 October 2013 (UTC)

Dynamic CSS styles overwrite the ones from MediaWiki:Geshi.css

Hello. With MediaWiki 1.19.1 and SyntaxHighlight the dynamic CSS styles are added after the link to the MediaWiki:Geshi.css and MediaWiki:Common.css stylesheets. As a result most of the attributes defined in MediaWiki:Geshi.css are overwritten by Geshi and it is impossible to extensively modify the styles without modifying the php files.

This can be fixed by removing the "addHeadItem" call in SyntaxHighlight_GeSHi.class.php (line 105) but then all styles must be statically defined in MediaWiki:Geshi.css.

-- 00:13, 28 August 2012 (UTC)

Empty page as a result of highlighter's work

MediaWiki v.1.17.0

I installed SyntaxHighlight GeSHi like it is said in the manual:

1) got the extension into /extensions

svn co http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/SyntaxHighlight_GeSHi

2) edited LocalSettings.php


Then I tried to use it in example from manual:

    $v = "string";    // sample initialization
html text
    echo $v;         // end of php code

And it gave me empty page both at preview and saved page. Like, completly empty, blank page. What do I do wrong? 17:19, 12 September 2012 (UTC)

Got the empty page of death too. I couldn't solve the problem and I was realy frustrated, but after updating from MW 1.17 to MW 1.19.2 the problem went away by itself. I mean, I installed the extension the same way and now it works. Abagnale OS Ubuntu 11.04; MW 1.19.2; MySQL 5.1.61; PHP 5.2.17 19:24, 27 September 2012 (UTC)

Font size small in 1.20

I had a problem with the most recent version of this extension on my installation of 1.20 MediaWiki. It being that the size of the text, being rather small. I added this to MediaWiki:Geshi.css:

/* Fix so <syntaxhighlight> tags, and .css and .js pages, get normal text size 
   also in some versions of Firefox, Safari, Konqueror, Chrome etc. */
div.mw-geshi div,
pre {
	font-family: monospace, "Courier New" !important;

This seems to fix the small text. --Inops (talk) 23:45, 25 November 2012 (UTC)
Oh, and I was getting the problems with the latest stable release of Google Chrome. --Inops (talk) 23:51, 25 November 2012 (UTC)

I'am using MW 1.20.7 with enclose="none" and the above did not work. I replaced it by
/* Fix so <syntaxhighlight> tags, and .css and .js pages, get normal text size 
   also in some versions of Firefox, Safari, Konqueror, Chrome etc. */
pre {
	font-family: monospace, "Courier New" !important;
Sigbert (talk) 19:24, 1 November 2013 (UTC)

Download does not work


trying to obtain a download from http://www.mediawiki.org/wiki/Special:ExtensionDistributor/SyntaxHighlight_GeSHi I receive the error message Invalid response from Extension Distributor remote client. .

Any help (to get the version for MW 1.17) would be appreciated!


-- 14:05, 7 December 2012 (UTC)

Now it did work, must have been a temporary dysfunction.
-- 08:19, 10 December 2012 (UTC)