- # GeSHi21 User Manual
- **Version:** 2.1.0
- GeSHi21 is a modern PHP syntax highlighting engine inspired by GeSHi 1.0. It provides a clean, object‑oriented API for highlighting source code in various programming languages using language definition files.
- ---
- ## Installation
- Place the `geshi21.php` file in your project and create a directory for language files (e.g., `geshi/`). Download language definition files from the GeSHi 1.0 repository and place them in this directory.
- <?php
- /**
- * Function linked to the integrate_bbc_codes hook.
- *
- * @param array $codes Array of BB codes passed by reference.
- */
- {
- // Remove native definitions of the 'code' tag
- });
- // Insert the [code] tag without parameters
- 'tag' => "code",
- 'type' => 'unparsed_content',
- 'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a> <a class="codeoperation smf_expand_code hidden" data-shrink-txt="' . $txt['code_shrink'] . '" data-expand-txt="' . $txt['code_expand'] . '">' . $txt['code_expand'] . '</a></div><code class="bbc_code">$1</code>',
- {
- '[]' => '[]',
- '['' => '['',
- '<br />' => "\n",
- ));
- $data = un_htmlspecialchars($data);
- $geshi->set_overall_class('geshi');
- $geshi->set_header_type(GESHI_HEADER_PRE);
- },
- 'block_level' => true,
- );
- // Insert the [code=language] tag with parameters
- 'tag' => 'code',
- 'type' => 'unparsed_equals_content',
- 'content' => '$1',
- {
- $data[0] = un_htmlspecialchars(str_replace(['[]', '['', '<br />'], ['[]', '['', "\n"], $data[0]));
-
-
- $geshi->set_overall_class('geshi');
- $geshi->start_line_numbers_at($data[1][1]);
- {
- $geshi->set_highlight_lines_extra_style($settings['geshi_highlight_lines_extra_style']);
-
- $geshi->highlight_lines_extra($data[1]);
- }
- $geshi->enable_classes(true);
- $geshi->set_header_type(GESHI_HEADER_PRE);
- $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
-
- $geshi->set_line_style($settings['geshi_line_style'], $settings['geshi_line_style_fancy']);
- $geshi->set_header_content($settings['geshi_header']);
-
- $geshi->set_footer_content($settings['geshi_footer']);
- //var_dump($data[0]);
- $data[0] = '
- <div class="codeheader">
- <span class="code floatleft">' . $txt['code'] . '</span> ('. $geshi->get_language() .') <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a> <a class="codeoperation smf_expand_code hidden" data-shrink-txt="' . $txt['code_shrink'] . '" data-expand-txt="' . $txt['code_expand'] . '">' . $txt['code_expand'] . '</a></div>
- <code class="bbc_code">'. $geshi->parse_code() .'</code>
- </div>';
-
- //echo '<pre>' . print_r($data) . '</pre>';
- },
- 'block_level' => true,
- );
- }
- {
- }
- ?>
- -- Single-line comments start with a double dash
- -- [[ Multi-line comments look like this ]]
- -----------------------------------------
- -- 1. VARIABLES & DATA TYPES
- -----------------------------------------
- -- Variables are global by default; always use 'local' to scope them properly
- local name = "Developer" -- String
- local age = 26 -- Number (all numbers are doubles/integers)
- local isLearning = true -- Boolean
- local emptyValue = nil -- Represents the absence of data
- -----------------------------------------
- -- 2. TABLES (Arrays and Dictionaries)
- -----------------------------------------
- -- Arrays are 1-indexed in Lua
- local shoppingList = {"Apples", "Bananas", "Oranges"}
- -- Tables also act as dictionaries/objects
- local userProfile = {
- username = "LuaCoder",
- level = 5,
- isPremium = false
- }
- -----------------------------------------
- -- 3. FUNCTIONS
- -----------------------------------------
- -- A standard function that takes parameters and returns a value
- local function calculateBonus(score, multiplier)
- if not score then return 0 end -- Early exit if nil
- return score * multiplier
- end
- -----------------------------------------
- -- 4. CONTROL FLOW & LOOPS
- -----------------------------------------
- -- Conditional block
- if userProfile.level >= 5 then
- print("Welcome high-level user: " .. userProfile.username) -- '..' concatenates strings
- elseif userProfile.level > 1 then
- print("Keep playing!")
- else
- print("Welcome beginner!")
- end
- -- Numeric For Loop: (start, stop, step)
- print("--- Counting up ---")
- for i = 1, 3, 1 do
- print("Count: " .. i)
- end
- -- Iterating through an Array (using ipairs)
- print("--- Shopping List ---")
- for index, item in ipairs(shoppingList) do
- print(index .. ": " .. item)
- end
- -- Iterating through a Dictionary (using pairs)
- print("--- User Profile ---")
- for key, value in pairs(userProfile) do
- print(key .. " = " .. tostring(value))
- end
- -----------------------------------------
- -- 5. EXECUTING A FUNCTION
- -----------------------------------------
- local finalScore = calculateBonus(100, 1.5)
- print("Final calculated bonus score: " .. finalScore)
- <?xml version="1.0" encoding="UTF-8"?>
- <breakfast_menu>
- <food>
- <name>Belgian Waffles</name>
- <price>$5.95</price>
- <description>
- Two of our famous Belgian Waffles with plenty of real maple syrup
- </description>
- <calories>650</calories>
- </food>
- <food>
- <name>Strawberry Belgian Waffles</name>
- <price>$7.95</price>
- <description>
- Light Belgian waffles covered with strawberries and whipped cream by John's sister
- </description>
- <calories>900</calories>
- </food>
- <food>
- <name>Berry-Berry Belgian Waffles</name>
- <price>$8.95</price>
- <description>
- Belgian waffles covered with assorted fresh berries and whipped cream
- </description>
- <calories>900</calories>
- </food>
- <food>
- <name>French Toast</name>
- <price>$4.50</price>
- <description>
- Thick slices made from our homemade sourdough bread
- </description>
- <calories>600</calories>
- </food>
- <!-- This is a comment -->
- <food>
- <name>Homestyle Breakfast</name>
- <price>$6.95</price>
- <description>
- Two eggs, bacon or sausage, toast, and our ever-popular hash browns
- </description>
- <calories>950</calories>
- </food>
- </breakfast_menu>
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- p.error {
- color: red;
- }
- </style>
- </head>
- <body>
- <p>This is a paragraph.</p>
- <p>This is a paragraph.</p>
- <p class="error">I am different.</p>
- <p>This is a paragraph.</p>
- <!-- This is a comment -->
- <p class="a b c-f">I am <b>different</b> too. Let's check some letlers t b i strong</p>
- </body>
- </html>