Author Topic: [HELP] Customizing and Using cb|GeSHi-mod on your forum  (Read 43548 times)

codebirth

  • Administrator
  • *
  • Posts: 36
    • View Profile
    • c o d e b i r t h
« Last Edit: June 20, 2011, 02:06:16 PM by codebirth »
c o d e b i r t h

codebirth

  • Administrator
  • *
  • Posts: 36
    • View Profile
    • c o d e b i r t h
1. Customizing cb|GeSHi-mod
« Reply #1 on: June 20, 2011, 01:25:40 PM »
1. Customizing cb|GeSHi-mod

You can customize the appearance of highlighted code for each of your themes by going to Configuration -> Themes and Layout -> Theme Settings and clicking on the theme name. Scroll down and you will see the customizable options.

If you want to customize the active theme just go to Configuration -> Current Theme and scroll down.

List of customizable options

GeSHi Code Container

For reference please see 3.1 The Code Container.


Line numbers

For reference please see 3.2 Line Numbers.


Fancy line numbers

For reference please see 3.2 Line Numbers.


Line style

For reference please see 3.2.2 Styling Line Numbers.


Fancy line style

For reference please see 3.2.2 Styling Line Numbers.


Highlighted lines style

For reference please see 3.15.2 Styles for the Highlighted Lines.


Show header above GeSHi Code Container

If enabled, it will show the header specified in the next option.


Header above GeSHi Code Container

This header is similar to the headers that SMF shows above QUOTE and simple CODE containers when you use those bbc tags in a post. You can do your custom header and there are three keyword available that you can use.

{CODE} is the localized translation of Code for the active language, so if your forum users are using english they will see Code, if they are using spanish they will see Código, and so on...

{TAG} is the bbcode tag for the specified language. If you are highlighting C++ code with the tag code=cpp, it will show CPP

{LANGUAGE} is the full name of the specified programming language. If you are highlighting C++ code with the tag code=cpp, it will show C++


Show header inside GeSHi Code Container

If enabled, it will show the header specified in the next option.


Header inside GeSHi Code Container

You can use these keywords. For reference please see 3.12.2 Setting Header Content.


Show footer inside GeSHi Code Container

If enabled, it will show the footer specified in the next option.


Footer inside GeSHi Code Container

You can use these keywords. For reference please see 3.12.3 Setting Footer Content.


Show language selector

If enabled, there will be an additional select box in the text editor you see when posting a message. Since there are +200 programming languages supported and there are only a few that you will use often you can make a list with a set of predefined language that, when selected, will add the corresponding bbcode to the text area of your post.


Selectable languages

Here you can set the languages that will be available in the language selector. The format to add a new language is code:language_name. Since it would be a tedious task I'm not posting all them here at this moment. You can find a wide list here with their respective code and language name.

So for Visual Basic we'll do vb:Visual Basic and for C++ we'll do cpp:C++ and so on with all the languages you want to be shown in the select box. Separate them by commas and everything will work as expected.

cpp:C++,vb:Visual Basic

« Last Edit: June 20, 2011, 03:38:27 PM by codebirth »
c o d e b i r t h

codebirth

  • Administrator
  • *
  • Posts: 36
    • View Profile
    • c o d e b i r t h
2. Using cb|GeSHi-mod
« Reply #2 on: June 20, 2011, 02:01:38 PM »
2. Using cb|GeSHi-mod

Simple C++ example
Code: [Select]
[code=cpp]
Code: C++
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.    std::cout << "Hello, world!\n";
  6. }

PHP example highlighting line 6
Code: [Select]
[code=php,6]
Code: PHP
  1. class Person {
  2.    public $firstName;
  3.    public $lastName;
  4.  
  5.    public function __construct($firstName, $lastName = '') { //Optional parameter
  6.        $this->firstName = $firstName;
  7.        $this->lastName = $lastName;
  8.    }
  9.  
  10.    public function greet() {
  11.        return "Hello, my name is " . $this->firstName . " " . $this->lastName . ".";
  12.    }
  13.  
  14.    static public function staticGreet($firstName, $lastName) {
  15.        return "Hello, my name is " . $firstName . " " . $lastName . ".";
  16.    }
  17. }
  18.  
  19. $he = new Person('John', 'Smith');
  20. $she = new Person('Sally', 'Davis');
  21. $other= new Person('Joe');
  22.  
  23. echo $he->greet(); // prints "Hello, my name is John Smith."
  24. echo '<br />';
  25. echo $she->greet(); // prints "Hello, my name is Sally Davis."
  26. echo '<br />';
  27. echo $other->greet(); // prints "Hello, my name is Joe  ."
  28. echo '<br />';
  29. echo Person::staticGreet('Jane', 'Doe'); // prints "Hello, my name is Jane Doe."
  30.  

Java example starting numbering lines from 9 and highlighting lines 2 and 6
Code: [Select]
[code=java.9,2,6]
Code: Java
  1. // OddEven.java
  2. import javax.swing.JOptionPane;
  3.  
  4. public class OddEven {
  5.     // "input" is the number that the user gives to the computer
  6.     private int input; // a whole number("int" means integer)
  7.  
  8.     /*
  9.      * This is the constructor method. It gets called when an object of the OddEven type
  10.      * is being created.
  11.      */
  12.     public OddEven() {
  13.     /*
  14.      * In most Java programs constructors can initialize objects with default values, or create
  15.      * other objects that this object might use to perform its functions. In some Java programs, the
  16.      * constructor may simply be an empty function if nothing needs to be initialized prior to the
  17.      * functioning of the object.  In this program's case, an empty constructor would suffice, even if
  18.      * it is empty. A constructor must exist, however if the user doesn't put one in then the compiler
  19.      * will create an empty one.
  20.      */
  21.     }
  22.  
  23.     // This is the main method. It gets called when this class is run through a Java interpreter.
  24.     public static void main(String[] args) {
  25.         /*
  26.          * This line of code creates a new instance of this class called "number" (also known as an
  27.          * Object) and initializes it by calling the constructor.  The next line of code calls
  28.          * the "showDialog()" method, which brings up a prompt to ask you for a number
  29.          */
  30.         OddEven number = new OddEven();
  31.         number.showDialog();
  32.     }
  33.  
  34.     public void showDialog() {
  35.         /*
  36.          * "try" makes sure nothing goes wrong. If something does,
  37.          * the interpreter skips to "catch" to see what it should do.
  38.          */
  39.         try {
  40.             /*
  41.              * The code below brings up a JOptionPane, which is a dialog box
  42.              * The String returned by the "showInputDialog()" method is converted into
  43.              * an integer, making the program treat it as a number instead of a word.
  44.              * After that, this method calls a second method, calculate() that will
  45.              * display either "Even" or "Odd."
  46.              */
  47.             input = Integer.parseInt(JOptionPane.showInputDialog("Please Enter A Number"));
  48.             calculate();
  49.         } catch (NumberFormatException e) {
  50.             /*
  51.              * Getting in the catch block means that there was a problem with the format of
  52.              * the number. Probably some letters were typed in instead of a number.
  53.              */
  54.             System.err.println("ERROR: Invalid input. Please type in a numerical value.");
  55.         }
  56.     }
  57.  
  58.     /*
  59.      * When this gets called, it sends a message to the interpreter.
  60.      * The interpreter usually shows it on the command prompt (For Windows users)
  61.      * or the terminal (For Linux users).(Assuming it's open)
  62.      */
  63.     private void calculate() {
  64.         if (input % 2 == 0) {
  65.             System.out.println("Even");
  66.         } else {
  67.             System.out.println("Odd");
  68.         }
  69.     }
  70. }
  71.  
c o d e b i r t h