Personal tools

Difference between revisions of "Syntax highlighter"

From MohidWiki

Jump to: navigation, search
 
(9 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
==Syntax==
 
==Syntax==
 
Simply add in the wiki article edit box this code:
 
Simply add in the wiki article edit box this code:
 +
 +
{|
 +
|
 
  <htm><pre name="code" class="ruby">
 
  <htm><pre name="code" class="ruby">
  File.open("sample.txt", "r") { |fs|
+
  File.open("sample.txt", "r") { |fs|  
    
+
   while line = fs.gets   
    while line = fs.gets   
+
    if line.match(pattern)   
      if line.match(pattern)   
+
      puts "Line read was '#{line.chomp}'.\n"
        puts "Line read was '#{line.chomp}'.\n"
+
    end
      end
+
  end
    end
+
  fs.close
    fs.close
+
  }
  }
 
 
  </pre></htm>
 
  </pre></htm>
 
+
||
Result:
 
 
<htm><pre name="code" class="ruby">
 
<htm><pre name="code" class="ruby">
 
  File.open("sample.txt", "r") { |fs|   
 
  File.open("sample.txt", "r") { |fs|   
Line 27: Line 28:
 
  }   
 
  }   
 
</pre></htm>
 
</pre></htm>
 +
|}
 +
 +
This works because of the [[html]] extension already installed in this wiki.
  
 
==Installation procedure for mediawiki==
 
==Installation procedure for mediawiki==
  
 
First, download and untar inside your wiki root folder the [http://code.google.com/p/syntaxhighlighter syntax highlighter] code.
 
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.
 
Then, simply add the following code snippets in your '''monobook.php''' file.
 
 
<htm>
 
<htm>
 
<pre name="code" class="html">
 
<pre name="code" class="html">
 
 
<!-- ... -->
 
<!-- ... -->
 
+
&lt;head&gt;
<head>
 
 
<!-- ... -->
 
<!-- ... -->
 
<!-- Syntax highlighter -->
 
<!-- Syntax highlighter -->
Line 44: Line 46:
 
<!-- Syntax highlighter -->
 
<!-- Syntax highlighter -->
 
<!-- ... -->
 
<!-- ... -->
</head>
+
&lt;/head&gt;
<body>
+
&lt;body&gt;
 
<!-- ... -->
 
<!-- ... -->
 
<!-- Syntax highlighter -->
 
<!-- Syntax highlighter -->
Line 72: Line 74:
 
     </script>
 
     </script>
 
<!-- Syntax highlighter -->
 
<!-- Syntax highlighter -->
</body>
+
&lt;/body&gt;
 
<!-- ... -->
 
<!-- ... -->
 
</pre>
 
</pre>
 
</htm>
 
</htm>
 
 
That's it! You can now test to see if it worked ...
 
That's it! You can now test to see if it worked ...
  

Latest revision as of 23:35, 12 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>
 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  
 }  

This works because of the html extension already installed in this wiki.

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.


<head>


        


</head>
<body>




















</body>

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

External references