GeSHi
public class GeSHi
Field Summary | |
---|---|
boolean | Whether CSS IDs should be added to the code |
boolean | Flag to decide if multi line spans are allowed. |
string | The style for the actual code |
boolean | Whether important blocks should be recognised or not |
string | The encoding to use for entity encoding NOTE: Used with Escape Char Sequences to fix UTF-8 handling (cf. |
string | The error message associated with an error |
array | Possible error messages |
string | The content of the footer block |
string | The style of the footer block |
boolean | Tells if a block around the highlighted source should be forced if not using line numbering |
string | The content of the header block |
string | The style of the header block |
int | The type of header to use. |
array | Lines that should be highlighted extra |
string | Styles of extra-highlighted lines |
array | Styles of lines that should be highlighted extra |
string | Styles for important parts of the code |
boolean | Should keywords be linked? |
string | The language to use when highlighting |
array | The data for the language used |
string | The path to the language files |
array | Array of permissions for which lexics should be highlighted |
string | The line ending If null, nl2br() will be used on the result string. |
int | The "nth" value for fancy line highlighting |
boolean | Flag for how line numbers are displayed |
int | Number at which line numbers should start at |
string | Line number styles |
string | Line number styles for fancy lines |
array | The styles for hyperlinks in the code |
string | Default target for keyword links |
string | Currently loaded language file |
string | The overall class for this code block |
string | The overall ID for this code block |
string | The overall style for this code block |
bool | Wether the caches needed for parsing are built or not |
boolean | Whether highlighting is strict or not |
int | The size of tab stops |
string | Style for line numbers when GESHI_HEADER_PRE_TABLE is chosen |
double | The time it took to parse the code |
boolean | Whether to use CSS classes in output |
int | Should we use language-defined tab stop widths? |
Constructor Summary | |
---|---|
GeSHi(mixed source, mixed language, mixed path, string The) Creates a new GeSHi object, with source and language |
Method Summary | |
---|---|
void | add_keyword(mixed key, mixed word, string The) Adds a keyword to a keyword group for highlighting |
void | add_keyword_group(mixed key, mixed styles, mixed case_sensitive, mixed words, array The, boolean Whether) Creates a new keyword group |
void | Disables all highlighting |
void | enable_classes(mixed flag, boolean Whether) Sets whether CSS classes should be used to highlight the source. |
void | enable_highlighting(mixed flag, boolean A) Enables all highlightingThe optional flag parameter was added in version 1.0.7.21 and can be used to enable (true) or disable (false) all highlighting. |
void | enable_ids(mixed flag, boolean If) Whether CSS IDs should be added to each line |
void | enable_important_blocks(mixed flag, boolean Tells) Sets whether context-important blocks are highlighted |
void | enable_inner_code_block(mixed flag, boolean Tells) Sets whether to force a surrounding block around the highlighted code or not |
void | enable_keyword_links(mixed enable, boolean If) Turns linking of keywords on or off. |
void | enable_line_numbers(mixed flag, mixed nth_row, int How, int Defines) Sets whether line numbers should be displayed. |
void | enable_multiline_span(mixed flag, boolean Wether) Sets wether spans and other HTML markup generated by GeSHi can span over multiple lines or not. |
void | enable_strict_mode(mixed mode, boolean Whether) Enables/disables strict highlighting. |
string|false | error() Returns an error message associated with the last GeSHi operation, or false if no error has occured |
string | Gets a human-readable language name (thanks to Simon Patterson for the idea :)) |
void | get_language_name_from_extension(mixed extension, mixed lookup, string The, array A) Given a file extension, this method returns either a valid geshi language name, or the empty string if it couldn't be found |
bool | Get current setting for multiline spans, see GeSHi->enable_multiline_span(). |
int | Returns the tab width to use, based on the current language and user preference |
static string | get_stylesheet(mixed economy_mode, boolean Whether) Returns a stylesheet for the highlighted code. |
double | get_time() Gets the time taken to parse the code |
void | highlight_lines_extra(mixed lines, mixed style, mixed An, string A) Specifies which lines to highlight extraThe extra style parameter was added in 1.0.7.21. |
void | load_from_file(mixed file_name, mixed lookup, string The, array A) Given a file name, this method loads its contents in, and attempts to set the language automatically. |
void | optimize_keyword_group(mixed key, int The) compile optimized regexp list for keyword group |
static void | Returns the code in $this->source, highlighted and surrounded by the nessecary HTML. |
void | remove_keyword(mixed key, mixed word, mixed recompile, string The, bool Wether) Removes a keyword from a keyword group |
void | remove_keyword_group(mixed key, int The) Removes a keyword group |
void | set_brackets_highlighting(mixed flag, boolean Whether) Turns highlighting on/off for bracketsThis method is DEPRECATED: use set_symbols_highlighting instead. |
void | set_brackets_style(mixed style, mixed preserve_defaults, string The, boolean Whether) Sets the styles for brackets. |
void | set_case_keywords(mixed case, int A) Sets the case that keywords should use when found. |
void | set_case_sensitivity(mixed key, mixed case, int The, boolean Whether) Sets whether a set of keywords are checked for in a case sensitive manner |
void | set_code_style(mixed style, mixed preserve_defaults, string The, boolean Whether) Sets the style for the actual code. |
void | set_comments_highlighting(mixed key, mixed flag, int The, boolean Whether) Turns highlighting on/off for comment groups |
void | set_comments_style(mixed key, mixed style, mixed preserve_defaults, string The, boolean Whether) Sets the styles for comment groups. |
void | set_encoding(mixed encoding, string The) Sets the encoding used for htmlspecialchars(), for international support. |
void | set_escape_characters_highlighting(mixed flag, boolean Whether) Turns highlighting on/off for escaped characters |
void | set_escape_characters_style(mixed style, mixed preserve_defaults, mixed group, string The, boolean Whether) Sets the styles for escaped characters. |
void | set_footer_content(mixed content, string The) Sets the content of the footer block |
void | set_footer_content_style(mixed style, string The) Sets the style for the footer content |
void | set_header_content(mixed content, string The) Sets the content of the header block |
void | set_header_content_style(mixed style, string The) Sets the style for the header content |
void | set_header_type(mixed type, int The) Sets the type of header to be used. |
void | set_highlight_lines_extra_style(mixed styles, string The) Sets the style for extra-highlighted lines |
void | set_important_styles(mixed styles, string The) Sets styles for important parts of the code |
void | set_keyword_group_highlighting(mixed key, mixed flag, int The, boolean Whether) Turns highlighting on/off for a keyword group |
void | set_keyword_group_style(mixed key, mixed style, mixed preserve_defaults, string The, boolean Whether) Sets the style for a keyword group. |
void | set_language(mixed language, mixed force_reset, string The) Sets the language for this object |
void | set_language_path(mixed path, string The) Sets the path to the directory containing the language files. |
void | set_line_ending(mixed line_ending, string The) Sets the line-ending |
void | set_line_style(mixed style1, mixed style2, mixed preserve_defaults, string The, boolean If) Sets the styles for the line numbers. |
void | set_link_styles(mixed type, mixed styles, int A, string The) Sets styles for links in code |
void | set_link_target(mixed target, string The) Sets the target for links in code |
void | set_methods_highlighting(mixed flag, boolean Whether) Turns highlighting on/off for methods |
void | set_methods_style(mixed key, mixed style, mixed preserve_defaults, string The, boolean Whether) Sets the styles for methods. |
void | set_numbers_highlighting(mixed flag, boolean Whether) Turns highlighting on/off for numbers |
void | set_numbers_style(mixed style, mixed preserve_defaults, string The, boolean Whether) Sets the styles for numbers. |
void | set_overall_class(mixed class, string The) Sets the overall classname for this block of code. |
void | set_overall_id(mixed id, string The) Sets the overall id for this block of code. |
void | set_overall_style(mixed style, mixed preserve_defaults, string The, boolean Whether) Sets the styles for the code that will be outputted when this object is parsed. |
void | set_regexps_highlighting(mixed key, mixed flag, int The, boolean Whether) Turns highlighting on/off for regexps |
void | set_regexps_style(mixed key, mixed style, mixed preserve_defaults, string The, boolean Whether) Sets the styles for regexps. |
void | set_source(mixed source, string The) Sets the source code for this object |
void | set_strings_highlighting(mixed flag, boolean Whether) Turns highlighting on/off for strings |
void | set_strings_style(mixed style, mixed preserve_defaults, string The, boolean Whether) Sets the styles for strings. |
void | set_symbols_highlighting(mixed flag, boolean Whether) Turns highlighting on/off for symbols |
void | set_symbols_style(mixed style, mixed preserve_defaults, mixed group, string The, boolean Whether, int Tells) Sets the styles for symbols. |
void | set_tab_width(mixed width, int The) Sets how many spaces a tab is substituted forWidths below zero are ignored |
void | set_url_for_keyword_group(mixed group, mixed url, string The) Sets the base URL to be used for keywords |
void | set_use_language_tab_width(mixed use, boolean Whether) Sets whether or not to use tab-stop width specifed by language |
void | start_line_numbers_at(mixed number, int The) Sets what number line numbers should start at. |
public boolean $add_ids = false
Whether CSS IDs should be added to the code
public boolean $allow_multiline_span = true
Flag to decide if multi line spans are allowed. Set it to false to make sure each tag is closed before and reopened after each linefeed.
public string $code_style = 'font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;'
The style for the actual code
public boolean $enable_important_blocks = false
Whether important blocks should be recognised or not
public string $encoding = 'utf-8'
The encoding to use for entity encoding NOTE: Used with Escape Char Sequences to fix UTF-8 handling (cf. SF#2037598)
public string $error = false
The error message associated with an error
public array $error_messages = array(...)
Possible error messages
public string $footer_content = ''
The content of the footer block
public string $footer_content_style = ''
The style of the footer block
public boolean $force_code_block = false
Tells if a block around the highlighted source should be forced if not using line numbering
public string $header_content = ''
The content of the header block
public string $header_content_style = ''
The style of the header block
public int $header_type = GESHI_HEADER_PRE
The type of header to use. Can be one of the following values:
- GESHI_HEADER_PRE: Source is outputted in a "pre" HTML element. - GESHI_HEADER_DIV: Source is outputted in a "div" HTML element. - GESHI_HEADER_NONE: No header is outputted.
public array $highlight_extra_lines = array()
Lines that should be highlighted extra
public string $highlight_extra_lines_style = 'background-color: #ffc;'
Styles of extra-highlighted lines
public array $highlight_extra_lines_styles = array()
Styles of lines that should be highlighted extra
public string $important_styles = 'font-weight: bold; color: red;'
Styles for important parts of the code
public boolean $keyword_links = true
Should keywords be linked?
public string $language = ''
The language to use when highlighting
public array $language_data = array()
The data for the language used
public string $language_path = GESHI_LANG_ROOT
The path to the language files
public array $lexic_permissions = array(...)
Array of permissions for which lexics should be highlighted
public string $line_ending = null
The line ending If null, nl2br() will be used on the result string. Otherwise, all instances of \n will be replaced with $line_ending
public int $line_nth_row
The "nth" value for fancy line highlighting
public boolean $line_numbers = GESHI_NO_LINE_NUMBERS
Flag for how line numbers are displayed
public int $line_numbers_start = 1
Number at which line numbers should start at
public string $line_style1 = 'font-weight: normal; vertical-align:top;'
Line number styles
public string $line_style2 = 'font-weight: bold; vertical-align:top;'
Line number styles for fancy lines
public array $link_styles = array()
The styles for hyperlinks in the code
public string $link_target = ''
Default target for keyword links
public string $loaded_language = ''
Currently loaded language file
public string $overall_class = ''
The overall class for this code block
public string $overall_id = ''
The overall ID for this code block
public string $overall_style = 'font-family:monospace;'
The overall style for this code block
public bool $parse_cache_built = false
Wether the caches needed for parsing are built or not
public boolean $strict_mode = false
Whether highlighting is strict or not
public int $tab_width = 8
The size of tab stops
public string $table_linenumber_style = 'width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;'
Style for line numbers when GESHI_HEADER_PRE_TABLE is chosen
public double $time
The time it took to parse the code
public boolean $use_classes = false
Whether to use CSS classes in output
public int $use_language_tab_width = false
Should we use language-defined tab stop widths?
public GeSHi(mixed source, mixed language, mixed path, string The)
Creates a new GeSHi object, with source and language
public void add_keyword(mixed key, mixed word, string The)
Adds a keyword to a keyword group for highlighting
public void add_keyword_group(mixed key, mixed styles, mixed case_sensitive, mixed words, array The, boolean Whether)
Creates a new keyword group
public void disable_highlighting()
Disables all highlighting
public void enable_classes(mixed flag, boolean Whether)
Sets whether CSS classes should be used to highlight the source. Default is off, calling this method with no arguments will turn it on
public void enable_highlighting(mixed flag, boolean A)
Enables all highlighting
The optional flag parameter was added in version 1.0.7.21 and can be used to enable (true) or disable (false) all highlighting.
public void enable_ids(mixed flag, boolean If)
Whether CSS IDs should be added to each line
public void enable_important_blocks(mixed flag, boolean Tells)
Sets whether context-important blocks are highlighted
public void enable_inner_code_block(mixed flag, boolean Tells)
Sets whether to force a surrounding block around the highlighted code or not
public void enable_keyword_links(mixed enable, boolean If)
Turns linking of keywords on or off.
public void enable_line_numbers(mixed flag, mixed nth_row, int How, int Defines)
Sets whether line numbers should be displayed.
Valid values for the first parameter are:
- GESHI_NO_LINE_NUMBERS: Line numbers will not be displayed - GESHI_NORMAL_LINE_NUMBERS: Line numbers will be displayed - GESHI_FANCY_LINE_NUMBERS: Fancy line numbers will be displayed
For fancy line numbers, the second parameter is used to signal which lines are to be fancy. For example, if the value of this parameter is 5 then every 5th line will be fancy.
public void enable_multiline_span(mixed flag, boolean Wether)
Sets wether spans and other HTML markup generated by GeSHi can span over multiple lines or not. Defaults to true to reduce overhead. Set it to false if you want to manipulate the output or manually display the code in an ordered list.
public void enable_strict_mode(mixed mode, boolean Whether)
Enables/disables strict highlighting. Default is off, calling this method without parameters will turn it on. See documentation for more details on strict mode and where to use it.
public string|false error()
Returns an error message associated with the last GeSHi operation, or false if no error has occured
public string get_language_name()
Gets a human-readable language name (thanks to Simon Patterson for the idea :))
public void get_language_name_from_extension(mixed extension, mixed lookup, string The, array A)
Given a file extension, this method returns either a valid geshi language name, or the empty string if it couldn't be found
public bool get_multiline_span()
Get current setting for multiline spans, see GeSHi->enable_multiline_span().
public int get_real_tab_width()
Returns the tab width to use, based on the current language and user preference
public static string get_stylesheet(mixed economy_mode, boolean Whether)
Returns a stylesheet for the highlighted code. If $economy mode is true, we only return the stylesheet declarations that matter for this code block instead of the whole thing
public double get_time()
Gets the time taken to parse the code
public void highlight_lines_extra(mixed lines, mixed style, mixed An, string A)
Specifies which lines to highlight extra
The extra style parameter was added in 1.0.7.21.
public void load_from_file(mixed file_name, mixed lookup, string The, array A)
Given a file name, this method loads its contents in, and attempts to set the language automatically. An optional lookup table can be passed for looking up the language name. If not specified a default table is used
The language table is in the form
array( 'lang_name' => array('extension', 'extension', ...), 'lang_name' ... );
public void optimize_keyword_group(mixed key, int The)
compile optimized regexp list for keyword group
public static void parse_code()
Returns the code in $this->source, highlighted and surrounded by the nessecary HTML.
This should only be called ONCE, cos it's SLOW! If you want to highlight the same source multiple times, you're better off doing a whole lot of str_replaces to replace the <span>s
public void remove_keyword(mixed key, mixed word, mixed recompile, string The, bool Wether)
Removes a keyword from a keyword group
public void remove_keyword_group(mixed key, int The)
Removes a keyword group
public void set_brackets_highlighting(mixed flag, boolean Whether)
Turns highlighting on/off for brackets
This method is DEPRECATED: use set_symbols_highlighting instead. This method will be remove in 1.2.X
public void set_brackets_style(mixed style, mixed preserve_defaults, string The, boolean Whether)
Sets the styles for brackets. If $preserve_defaults is true, then styles are merged with the default styles, with the user defined styles having priority
This method is DEPRECATED: use set_symbols_style instead. This method will be removed in 1.2.X
public void set_case_keywords(mixed case, int A)
Sets the case that keywords should use when found. Use the constants:
- GESHI_CAPS_NO_CHANGE: leave keywords as-is - GESHI_CAPS_UPPER: convert all keywords to uppercase where found - GESHI_CAPS_LOWER: convert all keywords to lowercase where found
public void set_case_sensitivity(mixed key, mixed case, int The, boolean Whether)
Sets whether a set of keywords are checked for in a case sensitive manner
public void set_code_style(mixed style, mixed preserve_defaults, string The, boolean Whether)
Sets the style for the actual code. This should be a string containing valid stylesheet declarations. If $preserve_defaults is true, then styles are merged with the default styles, with the user defined styles having priority
Note: Use this method to override any style changes you made to the line numbers if you are using line numbers, else the line of code will have the same style as the line number! Consult the GeSHi documentation for more information about this.
public void set_comments_highlighting(mixed key, mixed flag, int The, boolean Whether)
Turns highlighting on/off for comment groups
public void set_comments_style(mixed key, mixed style, mixed preserve_defaults, string The, boolean Whether)
Sets the styles for comment groups. If $preserve_defaults is true, then styles are merged with the default styles, with the user defined styles having priority
public void set_encoding(mixed encoding, string The)
Sets the encoding used for htmlspecialchars(), for international support.
NOTE: This is not needed for now because htmlspecialchars() is not being used (it has a security hole in PHP4 that has not been patched). Maybe in a future version it may make a return for speed reasons, but I doubt it.
public void set_escape_characters_highlighting(mixed flag, boolean Whether)
Turns highlighting on/off for escaped characters
public void set_escape_characters_style(mixed style, mixed preserve_defaults, mixed group, string The, boolean Whether)
Sets the styles for escaped characters. If $preserve_defaults is true, then styles are merged with the default styles, with the user defined styles having priority
public void set_footer_content(mixed content, string The)
Sets the content of the footer block
public void set_footer_content_style(mixed style, string The)
Sets the style for the footer content
public void set_header_content(mixed content, string The)
Sets the content of the header block
public void set_header_content_style(mixed style, string The)
Sets the style for the header content
public void set_header_type(mixed type, int The)
Sets the type of header to be used.
If GESHI_HEADER_DIV is used, the code is surrounded in a "div".This means more source code but more control over tab width and line-wrapping. GESHI_HEADER_PRE means that a "pre" is used - less source, but less control. Default is GESHI_HEADER_PRE.
From 1.0.7.2, you can use GESHI_HEADER_NONE to specify that no header code should be outputted.
public void set_highlight_lines_extra_style(mixed styles, string The)
Sets the style for extra-highlighted lines
public void set_important_styles(mixed styles, string The)
Sets styles for important parts of the code
public void set_keyword_group_highlighting(mixed key, mixed flag, int The, boolean Whether)
Turns highlighting on/off for a keyword group
public void set_keyword_group_style(mixed key, mixed style, mixed preserve_defaults, string The, boolean Whether)
Sets the style for a keyword group. If $preserve_defaults is true, then styles are merged with the default styles, with the user defined styles having priority
public void set_language(mixed language, mixed force_reset, string The)
Sets the language for this object
public void set_language_path(mixed path, string The)
Sets the path to the directory containing the language files. Note that this path is relative to the directory of the script that included geshi.php, NOT geshi.php itself.
public void set_line_ending(mixed line_ending, string The)
Sets the line-ending
public void set_line_style(mixed style1, mixed style2, mixed preserve_defaults, string The, boolean If)
Sets the styles for the line numbers.
public void set_link_styles(mixed type, mixed styles, int A, string The)
Sets styles for links in code
public void set_link_target(mixed target, string The)
Sets the target for links in code
public void set_methods_highlighting(mixed flag, boolean Whether)
Turns highlighting on/off for methods
public void set_methods_style(mixed key, mixed style, mixed preserve_defaults, string The, boolean Whether)
Sets the styles for methods. $key is a number that references the appropriate "object splitter" - see the language file for the language you are highlighting to get this number. If $preserve_defaults is true, then styles are merged with the default styles, with the user defined styles having priority
public void set_numbers_highlighting(mixed flag, boolean Whether)
Turns highlighting on/off for numbers
public void set_numbers_style(mixed style, mixed preserve_defaults, string The, boolean Whether)
Sets the styles for numbers. If $preserve_defaults is true, then styles are merged with the default styles, with the user defined styles having priority
public void set_overall_class(mixed class, string The)
Sets the overall classname for this block of code. This class can then be used in a stylesheet to style this object's output
public void set_overall_id(mixed id, string The)
Sets the overall id for this block of code. This id can then be used in a stylesheet to style this object's output
public void set_overall_style(mixed style, mixed preserve_defaults, string The, boolean Whether)
Sets the styles for the code that will be outputted when this object is parsed. The style should be a string of valid stylesheet declarations
public void set_regexps_highlighting(mixed key, mixed flag, int The, boolean Whether)
Turns highlighting on/off for regexps
public void set_regexps_style(mixed key, mixed style, mixed preserve_defaults, string The, boolean Whether)
Sets the styles for regexps. If $preserve_defaults is true, then styles are merged with the default styles, with the user defined styles having priority
public void set_source(mixed source, string The)
Sets the source code for this object
public void set_strings_highlighting(mixed flag, boolean Whether)
Turns highlighting on/off for strings
public void set_strings_style(mixed style, mixed preserve_defaults, string The, boolean Whether)
Sets the styles for strings. If $preserve_defaults is true, then styles are merged with the default styles, with the user defined styles having priority
public void set_symbols_highlighting(mixed flag, boolean Whether)
Turns highlighting on/off for symbols
public void set_symbols_style(mixed style, mixed preserve_defaults, mixed group, string The, boolean Whether, int Tells)
Sets the styles for symbols. If $preserve_defaults is true, then styles are merged with the default styles, with the user defined styles having priority
public void set_tab_width(mixed width, int The)
Sets how many spaces a tab is substituted for
Widths below zero are ignored
public void set_url_for_keyword_group(mixed group, mixed url, string The)
Sets the base URL to be used for keywords
public void set_use_language_tab_width(mixed use, boolean Whether)
Sets whether or not to use tab-stop width specifed by language
public void start_line_numbers_at(mixed number, int The)
Sets what number line numbers should start at. Should be a positive integer, and will be converted to one.
Warning: Using this method will add the "start" attribute to the <ol> that is used for line numbering. This is not valid XHTML strict, so if that's what you care about then don't use this method. Firefox is getting support for the CSS method of doing this in 1.1 and Opera has support for the CSS method, but (of course) IE doesn't so it's not worth doing it the CSS way yet.
The GeSHi Class.
Please refer to the documentation for GeSHi 1.0.X that is available at http://qbnz.com/highlighter/documentation.php for more information about how to use this class.