Personal tools

Difference between revisions of "Syntax highlighter"

From MohidWiki

Jump to: navigation, search
(New page: <htm> <pre name="code" class="html"> <head> <!-- ... --> <!-- Syntax highlighter --> <link type="text/css" rel="stylesheet" href="<?php $this->text('stylepath' ) ?>/../syntaxhi/Styles/Syn...)
 
Line 1: Line 1:
 +
This wiki allows to embed code with syntax highlighting.
 +
 +
==Syntax==
 +
Simply add in the wiki article edit box this code:
 +
&lt;htm&gt;&lt;pre name="code" class="ruby"&gt;
 +
File.open("sample.txt", "r") { |fs| 
 +
 
 +
    while line = fs.gets 
 +
      if line.match(pattern) 
 +
        puts "Line read was '#{line.chomp}'.\n" 
 +
      end 
 +
    end 
 +
    fs.close 
 +
 +
&lt;/pre&gt;&lt;/htm&gt;
 +
 +
Result:
 +
<htm><pre name="code" class="ruby">
 +
File.open("sample.txt", "r") { |fs| 
 +
 
 +
    while line = fs.gets 
 +
      if line.match(pattern) 
 +
        puts "Line read was '#{line.chomp}'.\n" 
 +
      end 
 +
    end 
 +
    fs.close 
 +
 +
</pre></htm>
 +
 +
==Installation procedure for mediawiki==
 +
 +
First, download and untar inside your wiki root folder the [http://code.google.com/p/syntaxhighlighter syntax highlighter] code.
 +
Then, simply add the following code snippets in your '''monobook.php''' file.
  
 
<htm>
 
<htm>
 
<pre name="code" class="html">
 
<pre name="code" class="html">
 +
 +
<!-- ... -->
 +
 
<head>
 
<head>
 
<!-- ... -->
 
<!-- ... -->
Line 9: Line 45:
 
<!-- ... -->
 
<!-- ... -->
 
</head>
 
</head>
 
 
<body>
 
<body>
 
 
<!-- ... -->
 
<!-- ... -->
 
 
<!-- Syntax highlighter -->
 
<!-- Syntax highlighter -->
 
<script class="javascript" src="<?php $this->text('stylepath' ) ?>/../syntaxhi/Scripts/shCore.js"></script>
 
<script class="javascript" src="<?php $this->text('stylepath' ) ?>/../syntaxhi/Scripts/shCore.js"></script>
Line 40: Line 73:
 
<!-- Syntax highlighter -->
 
<!-- Syntax highlighter -->
 
</body>
 
</body>
 +
<!-- ... -->
 
</pre>
 
</pre>
 
</htm>
 
</htm>
 +
 +
That's it! You can now test to see if it worked ...
 +
 +
==External references==
 +
 +
*[http://code.google.com/p/syntaxhighlighter syntaxhighlighter homepage]
  
 
[[Category:Wiki]]
 
[[Category:Wiki]]
 
[[Category:Extension]]
 
[[Category:Extension]]

Revision as of 00:09, 13 December 2008

This wiki allows to embed code with syntax highlighting.

Syntax

Simply add in the wiki article edit box this code:

<htm><pre name="code" class="ruby">
File.open("sample.txt", "r") { |fs|  
  
   while line = fs.gets  
     if line.match(pattern)  
        puts "Line read was '#{line.chomp}'.\n"  
     end  
   end  
   fs.close  
}  
</pre></htm>

Result:

 File.open("sample.txt", "r") { |fs|  
   
    while line = fs.gets  
      if line.match(pattern)  
         puts "Line read was '#{line.chomp}'.\n"  
      end  
    end  
    fs.close  
 }  

Installation procedure for mediawiki

First, download and untar inside your wiki root folder the syntax highlighter code. Then, simply add the following code snippets in your monobook.php file.








        



























That's it! You can now test to see if it worked ...

External references