Difference between revisions of "GeSHi"

From Organic Design wiki
(Add comment about geshi extension used on OD)
(Technical: add another note)
Line 24: Line 24:
  
 
== Technical ==
 
== Technical ==
 +
{{Note| This is working with [[MW:Extension:GeSHiCodeTag]]}}
 +
 
To get around these issues, I've added a few extra lines after the GeSHi include to allow the tags to be added before parsing if a language template is transcluded. Here's the additional code which as added at the end of the GeSHiCodeTag.php file.
 
To get around these issues, I've added a few extra lines after the GeSHi include to allow the tags to be added before parsing if a language template is transcluded. Here's the additional code which as added at the end of the GeSHiCodeTag.php file.
 
{{code|<php>
 
{{code|<php>

Revision as of 02:21, 5 June 2010


Note.svg Note: The syntax highlighting extension used on OD is old -MW:Extension:GeSHiCodeTag

There is a newer syntax highlighting extension MW:Extension:SyntaxHighlight GeSHi


Syntax highlighting on Organic Design

The standard GeSHi MediaWiki extensions don't quite suit our purposes because our articles containing code are usually directly executed which means that we can't include GeSHi code tags, but this problem can be easily fixed by a quick hack which I've included here.

Another problem is that we'd often like the ability to use MediaWiki templates even if the content is code, for example when defining LocalSettings articles by transcluding the wiki template and extension templates. So I've also added an extra line of code into the GeSHi extension before it parses the content to achieve this:

Using syntax highlighting on Organic Design wikis

Blocks of source code can be wrapped in language tags like usual, as follows:

<php>
print "foo";
</php>

but also template syntax can be used to make the entire article be rendered by the GeSHi parser. The templates expand to nothing, so they can be placed anywhere in the article without affecting its execution (if the raw article is requested, templates=expand will need to be included in the query-string to make the template reduce to nothing). It's probably best to put the template in a comment so that the execution is not affected even if templates do not expand. Here's an example:

# {{per1}}
print "bar";

Technical

Note.svg Note: This is working with MW:Extension:GeSHiCodeTag


To get around these issues, I've added a few extra lines after the GeSHi include to allow the tags to be added before parsing if a language template is transcluded. Here's the additional code which as added at the end of the GeSHiCodeTag.php file.

Templates or variables must be added which expand to nothing so they don't render as a red link. Also an extra line must be added to the GeSHiCodeTag.php file just before the geshi object is instantiated in the hook function to force the templates to expand.

{{{1}}}

The end of the function needs to have a hack added to remove some spurious &lt;'s and &gt;'s that crop up on transcluded code:

{{{1}}}

Bugs

The geshi syntax highlighter has a language called <div>, this interferes with any wiki site <div> tags. To suppress this bug either delete the language file, of rename it to <div-lang>.

See also