[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/easybook/geshi/ -> geshi.php (summary)

GeSHi - Generic Syntax Highlighter The GeSHi class for Generic Syntax Highlighting. Please refer to the documentation at http://qbnz.com/highlighter/documentation.php for more information about how to use this class.

Author: Nigel McNie , Benny Baumann
Copyright: (C) 2004 - 2007 Nigel McNie, (C) 2007 - 2008 Benny Baumann
License: http://gnu.org/copyleft/gpl.html GNU GPL
File Size: 4774 lines (205 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

GeSHi:: (94 methods):
  __construct()
  get_version()
  error()
  get_language_name()
  set_source()
  set_language()
  set_language_path()
  get_supported_languages()
  get_language_fullname()
  set_header_type()
  set_overall_style()
  set_overall_class()
  set_overall_id()
  enable_classes()
  set_code_style()
  set_line_style()
  enable_line_numbers()
  enable_multiline_span()
  get_multiline_span()
  set_keyword_group_style()
  set_keyword_group_highlighting()
  set_comments_style()
  set_comments_highlighting()
  set_escape_characters_style()
  set_escape_characters_highlighting()
  set_brackets_style()
  set_brackets_highlighting()
  set_symbols_style()
  set_symbols_highlighting()
  set_strings_style()
  set_strings_highlighting()
  set_script_style()
  set_numbers_style()
  set_numbers_highlighting()
  set_methods_style()
  set_methods_highlighting()
  set_regexps_style()
  set_regexps_highlighting()
  set_case_sensitivity()
  set_case_keywords()
  set_tab_width()
  set_use_language_tab_width()
  get_real_tab_width()
  enable_strict_mode()
  disable_highlighting()
  enable_highlighting()
  get_language_name_from_extension()
  load_from_file()
  add_keyword()
  remove_keyword()
  add_keyword_group()
  remove_keyword_group()
  optimize_keyword_group()
  set_header_content()
  set_footer_content()
  set_header_content_style()
  set_footer_content_style()
  enable_inner_code_block()
  set_url_for_keyword_group()
  set_link_styles()
  set_link_target()
  set_important_styles()
  enable_important_blocks()
  enable_ids()
  highlight_lines_extra()
  set_highlight_lines_extra_style()
  set_line_ending()
  start_line_numbers_at()
  set_encoding()
  enable_keyword_links()
  build_style_cache()
  build_parse_cache()
  parse_code()
  indent()
  change_case()
  handle_keyword_replace()
  handle_regexps_callback()
  handle_multiline_regexps()
  parse_non_string_part()
  set_time()
  get_time()
  merge_arrays()
  load_language()
  finalise()
  header()
  footer()
  replace_keywords()
  hsc()
  _genCSSName()
  get_stylesheet()
  get_line_style()
  optimize_regexp_list()
  _optimize_regexp_list_tokens_to_string()
  geshi_highlight()

Defines 94 functions

  stripos()
  stripos()

Class: GeSHi  - X-Ref

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.

__construct($source = '', $language = '', $path = '')   X-Ref
Creates a new GeSHi object, with source and language

param: string The source code to highlight
param: string The language to highlight the source with
param: string The path to the language file directory. <b>This

get_version()   X-Ref
Returns the version of GeSHi

return: string

error()   X-Ref
Returns an error message associated with the last GeSHi operation,
or false if no error has occured

return: string|false An error message if there has been an error, else false

get_language_name()   X-Ref
Gets a human-readable language name (thanks to Simon Patterson
for the idea :))

return: string The name for the current language

set_source($source)   X-Ref
Sets the source code for this object

param: string The source code to highlight

set_language($language, $force_reset = false)   X-Ref
Sets the language for this object

param: string The name of the language to use

set_language_path($path)   X-Ref
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.

param: string The path to the language directory

get_supported_languages($full_names=false)   X-Ref
Get supported langs or an associative array lang=>full_name.

param: boolean $longnames
return: array

get_language_fullname($language)   X-Ref
Get full_name for a lang or false.

param: string $language short langname (html4strict for example)
return: mixed

set_header_type($type)   X-Ref
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.

param: int The type of header to be used

set_overall_style($style, $preserve_defaults = false)   X-Ref
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

param: string  The overall style for the outputted code block
param: boolean Whether to merge the styles with the current styles or not

set_overall_class($class)   X-Ref
Sets the overall classname for this block of code. This
class can then be used in a stylesheet to style this object's
output

param: string The class name to use for this block of code

set_overall_id($id)   X-Ref
Sets the overall id for this block of code. This id can then
be used in a stylesheet to style this object's output

param: string The ID to use for this block of code

enable_classes($flag = true)   X-Ref
Sets whether CSS classes should be used to highlight the source. Default
is off, calling this method with no arguments will turn it on

param: boolean Whether to turn classes on or not

set_code_style($style, $preserve_defaults = false)   X-Ref
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.

param: string  The style to use for actual code
param: boolean Whether to merge the current styles with the new styles

set_line_style($style1, $style2 = '', $preserve_defaults = false)   X-Ref
Sets the styles for the line numbers.

param: string The style for the line numbers that are "normal"
param: string|boolean If a string, this is the style of the line
param: boolean If set, is the flag for whether to merge the "fancy"

enable_line_numbers($flag, $nth_row = 5)   X-Ref
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.

param: int How line numbers should be displayed
param: int Defines which lines are fancy

enable_multiline_span($flag)   X-Ref
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.

param: boolean Wether multiline spans are allowed or not

get_multiline_span()   X-Ref
Get current setting for multiline spans, see GeSHi->enable_multiline_span().

see: enable_multiline_span
return: bool

set_keyword_group_style($key, $style, $preserve_defaults = false)   X-Ref
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

param: int     The key of the keyword group to change the styles of
param: string  The style to make the keywords
param: boolean Whether to merge the new styles with the old or just

set_keyword_group_highlighting($key, $flag = true)   X-Ref
Turns highlighting on/off for a keyword group

param: int     The key of the keyword group to turn on or off
param: boolean Whether to turn highlighting for that group on or off

set_comments_style($key, $style, $preserve_defaults = false)   X-Ref
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

param: int     The key of the comment group to change the styles of
param: string  The style to make the comments
param: boolean Whether to merge the new styles with the old or just

set_comments_highlighting($key, $flag = true)   X-Ref
Turns highlighting on/off for comment groups

param: int     The key of the comment group to turn on or off
param: boolean Whether to turn highlighting for that group on or off

set_escape_characters_style($style, $preserve_defaults = false, $group = 0)   X-Ref
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

param: string  The style to make the escape characters
param: boolean Whether to merge the new styles with the old or just

set_escape_characters_highlighting($flag = true)   X-Ref
Turns highlighting on/off for escaped characters

param: boolean Whether to turn highlighting for escape characters on or off

set_brackets_style($style, $preserve_defaults = false)   X-Ref
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

param: string  The style to make the brackets
param: boolean Whether to merge the new styles with the old or just

set_brackets_highlighting($flag)   X-Ref
Turns highlighting on/off for brackets

This method is DEPRECATED: use set_symbols_highlighting instead.
This method will be remove in 1.2.X

param: boolean Whether to turn highlighting for brackets on or off

set_symbols_style($style, $preserve_defaults = false, $group = 0)   X-Ref
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

param: string  The style to make the symbols
param: boolean Whether to merge the new styles with the old or just
param: int     Tells the group of symbols for which style should be set.

set_symbols_highlighting($flag)   X-Ref
Turns highlighting on/off for symbols

param: boolean Whether to turn highlighting for symbols on or off

set_strings_style($style, $preserve_defaults = false, $group = 0)   X-Ref
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

param: string  The style to make the escape characters
param: boolean Whether to merge the new styles with the old or just
param: int     Tells the group of strings for which style should be set.

set_strings_highlighting($flag)   X-Ref
Turns highlighting on/off for strings

param: boolean Whether to turn highlighting for strings on or off

set_script_style($style, $preserve_defaults = false, $group = 0)   X-Ref
Sets the styles for strict code blocks. If $preserve_defaults is
true, then styles are merged with the default styles, with the
user defined styles having priority

param: string  The style to make the script blocks
param: boolean Whether to merge the new styles with the old or just
param: int     Tells the group of script blocks for which style should be set.

set_numbers_style($style, $preserve_defaults = false, $group = 0)   X-Ref
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

param: string  The style to make the numbers
param: boolean Whether to merge the new styles with the old or just
param: int     Tells the group of numbers for which style should be set.

set_numbers_highlighting($flag)   X-Ref
Turns highlighting on/off for numbers

param: boolean Whether to turn highlighting for numbers on or off

set_methods_style($key, $style, $preserve_defaults = false)   X-Ref
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

param: int     The key of the object splitter to change the styles of
param: string  The style to make the methods
param: boolean Whether to merge the new styles with the old or just

set_methods_highlighting($flag)   X-Ref
Turns highlighting on/off for methods

param: boolean Whether to turn highlighting for methods on or off

set_regexps_style($key, $style, $preserve_defaults = false)   X-Ref
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

param: string  The style to make the regular expression matches
param: boolean Whether to merge the new styles with the old or just

set_regexps_highlighting($key, $flag)   X-Ref
Turns highlighting on/off for regexps

param: int     The key of the regular expression group to turn on or off
param: boolean Whether to turn highlighting for the regular expression group on or off

set_case_sensitivity($key, $case)   X-Ref
Sets whether a set of keywords are checked for in a case sensitive manner

param: int The key of the keyword group to change the case sensitivity of
param: boolean Whether to check in a case sensitive manner or not

set_case_keywords($case)   X-Ref
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

param: int A constant specifying what to do with matched keywords

set_tab_width($width)   X-Ref
Sets how many spaces a tab is substituted for

Widths below zero are ignored

param: int The tab width

set_use_language_tab_width($use)   X-Ref
Sets whether or not to use tab-stop width specifed by language

param: boolean Whether to use language-specific tab-stop widths

get_real_tab_width()   X-Ref
Returns the tab width to use, based on the current language and user
preference

return: int Tab width

enable_strict_mode($mode = true)   X-Ref
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.

param: boolean Whether to enable strict mode or not

disable_highlighting()   X-Ref
Disables all highlighting


enable_highlighting($flag = true)   X-Ref
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.

param: boolean A flag specifying whether to enable or disable all highlighting

get_language_name_from_extension( $extension, $lookup = array()   X-Ref
Given a file extension, this method returns either a valid geshi language
name, or the empty string if it couldn't be found

param: string The extension to get a language name for
param: array  A lookup array to use instead of the default one

load_from_file($file_name, $lookup = array()   X-Ref
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
<pre>array(
'lang_name' => array('extension', 'extension', ...),
'lang_name' ...
);</pre>

param: string The filename to load the source from
param: array  A lookup array to use instead of the default one

add_keyword($key, $word)   X-Ref
Adds a keyword to a keyword group for highlighting

param: int    The key of the keyword group to add the keyword to
param: string The word to add to the keyword group

remove_keyword($key, $word, $recompile = true)   X-Ref
Removes a keyword from a keyword group

param: int    The key of the keyword group to remove the keyword from
param: string The word to remove from the keyword group
param: bool   Wether to automatically recompile the optimized regexp list or not.

add_keyword_group($key, $styles, $case_sensitive = true, $words = array()   X-Ref
Creates a new keyword group

param: int    The key of the keyword group to create
param: string The styles for the keyword group
param: boolean Whether the keyword group is case sensitive ornot
param: array  The words to use for the keyword group

remove_keyword_group($key)   X-Ref
Removes a keyword group

param: int    The key of the keyword group to remove

optimize_keyword_group($key)   X-Ref
compile optimized regexp list for keyword group

param: int   The key of the keyword group to compile & optimize

set_header_content($content)   X-Ref
Sets the content of the header block

param: string The content of the header block

set_footer_content($content)   X-Ref
Sets the content of the footer block

param: string The content of the footer block

set_header_content_style($style)   X-Ref
Sets the style for the header content

param: string The style for the header content

set_footer_content_style($style)   X-Ref
Sets the style for the footer content

param: string The style for the footer content

enable_inner_code_block($flag)   X-Ref
Sets whether to force a surrounding block around
the highlighted code or not

param: boolean Tells whether to enable or disable this feature

set_url_for_keyword_group($group, $url)   X-Ref
Sets the base URL to be used for keywords

param: int The key of the keyword group to set the URL for
param: string The URL to set for the group. If {FNAME} is in

set_link_styles($type, $styles)   X-Ref
Sets styles for links in code

param: int A constant that specifies what state the style is being
param: string The styles to use for that state

set_link_target($target)   X-Ref
Sets the target for links in code

param: string The target for links in the code, e.g. _blank

set_important_styles($styles)   X-Ref
Sets styles for important parts of the code

param: string The styles to use on important parts of the code

enable_important_blocks($flag)   X-Ref
Sets whether context-important blocks are highlighted

param: boolean Tells whether to enable or disable highlighting of important blocks

enable_ids($flag = true)   X-Ref
Whether CSS IDs should be added to each line

param: boolean If true, IDs will be added to each line.

highlight_lines_extra($lines, $style = null)   X-Ref
Specifies which lines to highlight extra

The extra style parameter was added in 1.0.7.21.

param: mixed An array of line numbers to highlight, or just a line
param: string A string specifying the style to use for this line.

set_highlight_lines_extra_style($styles)   X-Ref
Sets the style for extra-highlighted lines

param: string The style for extra-highlighted lines

set_line_ending($line_ending)   X-Ref
Sets the line-ending

param: string The new line-ending

start_line_numbers_at($number)   X-Ref
Sets what number line numbers should start at. Should
be a positive integer, and will be converted to one.

<b>Warning:</b> Using this method will add the "start"
attribute to the &lt;ol&gt; that is used for line numbering.
This is <b>not</b> 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.

param: int The number to start line numbers at

set_encoding($encoding)   X-Ref
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.

param: string The encoding to use for the source

enable_keyword_links($enable = true)   X-Ref
Turns linking of keywords on or off.

param: boolean If true, links will be added to keywords

build_style_cache()   X-Ref
Setup caches needed for styling. This is automatically called in
parse_code() and get_stylesheet() when appropriate. This function helps
stylesheet generators as they rely on some style information being
preprocessed


build_parse_cache()   X-Ref
Setup caches needed for parsing. This is automatically called in parse_code() when appropriate.
This function makes stylesheet generators much faster as they do not need these caches.


parse_code()   X-Ref
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 &lt;span&gt;s


indent(&$result)   X-Ref
Swaps out spaces and tabs for HTML indentation. Not needed if
the code is in a pre block...

param: string The source to indent (reference!)

change_case($instr)   X-Ref
Changes the case of a keyword for those languages where a change is asked for

param: string The keyword to change the case of
return: string The keyword with its case changed

handle_keyword_replace($match)   X-Ref
Handles replacements of keywords to include markup and links if requested

param: string The keyword to add the Markup to
return: The HTML for the match found

handle_regexps_callback($matches)   X-Ref
handles regular expressions highlighting-definitions with callback functions

param: array the matches array
return: The highlighted string

handle_multiline_regexps($matches)   X-Ref
handles newlines in REGEXPS matches. Set the _hmr_* vars before calling this

param: array the matches array
return: string

parse_non_string_part($stuff_to_parse)   X-Ref
Takes a string that has no strings or comments in it, and highlights
stuff like keywords, numbers and methods.

param: string The string to parse for keyword, numbers etc.

set_time($start_time, $end_time)   X-Ref
Sets the time taken to parse the code

param: microtime The time when parsing started
param: microtime The time when parsing ended

get_time()   X-Ref
Gets the time taken to parse the code

return: double The time taken to parse the code

merge_arrays()   X-Ref
Merges arrays recursively, overwriting values of the first array with values of later arrays


load_language($file_name)   X-Ref
Gets language information and stores it for later use

param: string The filename of the language file you want to load

finalise(&$parsed_code)   X-Ref
Takes the parsed code and various options, and creates the HTML
surrounding it to make it look nice.

param: string The code already parsed (reference!)

header()   X-Ref
Creates the header for the code block (with correct attributes)

return: string The header for the code block

footer()   X-Ref
Returns the footer for the code block.

return: string The footer for the code block

replace_keywords($instr)   X-Ref
Replaces certain keywords in the header and footer with
certain configuration values

param: string The header or footer content to do replacement on
return: string The header or footer with replaced keywords

hsc($string, $quote_style = ENT_COMPAT)   X-Ref
Secure replacement for PHP built-in function htmlspecialchars().

See ticket #427 (http://wush.net/trac/wikka/ticket/427) for the rationale
for this replacement function.

The INTERFACE for this function is almost the same as that for
htmlspecialchars(), with the same default for quote style; however, there
is no 'charset' parameter. The reason for this is as follows:

The PHP docs say:
"The third argument charset defines character set used in conversion."

I suspect PHP's htmlspecialchars() is working at the byte-value level and
thus _needs_ to know (or asssume) a character set because the special
characters to be replaced could exist at different code points in
different character sets. (If indeed htmlspecialchars() works at
byte-value level that goes some  way towards explaining why the
vulnerability would exist in this function, too, and not only in
htmlentities() which certainly is working at byte-value level.)

This replacement function however works at character level and should
therefore be "immune" to character set differences - so no charset
parameter is needed or provided. If a third parameter is passed, it will
be silently ignored.

In the OUTPUT there is a minor difference in that we use '&#39;' instead
of PHP's '&#039;' for a single quote: this provides compatibility with
get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)
(see comment by mikiwoz at yahoo dot co dot uk on
http://php.net/htmlspecialchars); it also matches the entity definition
for XML 1.0
(http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_Special_characters).
Like PHP we use a numeric character reference instead of '&apos;' for the
single quote. For the other special characters we use the named entity
references, as PHP is doing.

param: string  $string string to be converted
param: integer $quote_style
author: {@link http://wikkawiki.org/JavaWoman Marjolein Katsma}
return: string  converted string

_genCSSName($name)   X-Ref
No description

get_stylesheet($economy_mode = true)   X-Ref
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

param: boolean Whether to use economy mode or not
return: string A stylesheet built on the data for the current language

get_line_style($line)   X-Ref
Get's the style that is used for the specified line

param: int The line number information is requested for

optimize_regexp_list($list, $regexp_delimiter = '/')   X-Ref
this functions creates an optimized regular expression list
of an array of strings.

Example:
<code>$list = array('faa', 'foo', 'foobar');
=> string 'f(aa|oo(bar)?)'</code>

param: $list array of (unquoted) strings
param: $regexp_delimiter your regular expression delimiter, @see preg_quote()
author: Milian Wolff <mail@milianw.de>
return: string for regular expression

_optimize_regexp_list_tokens_to_string(&$tokens, $recursed = false)   X-Ref
this function creates the appropriate regexp string of an token array
you should not call this function directly, @see $this->optimize_regexp_list().

param: &$tokens array of tokens
param: $recursed bool to know wether we recursed or not
author: Milian Wolff <mail@milianw.de>
return: string

geshi_highlight($string, $language, $path = null, $return = false)   X-Ref
Easy way to highlight stuff. Behaves just like highlight_string

param: string The code to highlight
param: string The language to highlight the code in
param: string The path to the language files. You can leave this blank if you need
param: boolean Whether to return the result or to echo
return: string The code highlighted (if $return is true)

Functions
Functions that are not part of a class: