[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/mambots/content/geshi/ -> geshi.php (sommaire)

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 <nigel@geshi.org>
Copyright: Copyright © 2004, 2005, Nigel McNie
License: http://gnu.org/copyleft/gpl.html GNU GPL
Version: $Id: geshi.php 2970 2006-03-30 07:51:33Z stingrey $
Poids: 2698 lignes (91 kb)
Inclus ou requis:0 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 1 class

GeSHi:: (75 méthodes):
  GeSHi()
  error()
  get_language_name()
  set_source()
  set_language()
  set_language_path()
  set_header_type()
  set_overall_style()
  set_overall_class()
  set_overall_id()
  enable_classes()
  set_code_style()
  set_line_style()
  enable_line_numbers()
  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_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()
  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()
  set_header_content()
  set_footer_content()
  set_header_content_style()
  set_footer_content_style()
  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()
  start_line_numbers_at()
  set_encoding()
  parse_code()
  indent()
  change_case()
  add_url_to_keyword()
  parse_non_string_part()
  set_time()
  get_time()
  load_language()
  finalise()
  header()
  format_header_content()
  footer()
  format_footer_content()
  replace_keywords()
  get_attributes()
  get_stylesheet()
  geshi_highlight()


Classe: 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.

GeSHi($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

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)   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

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:

<ul>
<li><b>GESHI_NO_LINE_NUMBERS</b>: Line numbers will not be displayed</li>
<li><b>GESHI_NORMAL_LINE_NUMBERS</b>: Line numbers will be displayed</li>
<li><b>GESHI_FANCY_LINE_NUMBERS</b>: Fancy line numbers will be displayed</li>
</ul>

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

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)   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)   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

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)   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

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

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

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

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:

<ul>
<li><b>GESHI_CAPS_NO_CHANGE</b>: leave keywords as-is</li>
<li><b>GESHI_CAPS_UPPER</b>: convert all keywords to uppercase where found</li>
<li><b>GESHI_CAPS_LOWER</b>: convert all keywords to lowercase where found</li>
</ul>

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

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()   X-Ref
Enables 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

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>


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)   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

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

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

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


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)   X-Ref
Specifies which lines to highlight extra

param: mixed An array of line numbers to highlight, or just a line

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

param: string The style for extra-highlighted lines

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.

param: string The encoding to use for the source

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
return: string The source with HTML indenting applied

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

add_url_to_keyword($keyword, $group, $start_or_end)   X-Ref
Adds a url to a keyword where needed.

param: string The keyword to add the URL HTML to
param: int What group the keyword is from
param: boolean Whether to get the HTML for the start or end
return: The HTML for either the start or end of the HTML &lt;a&gt; tag

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

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


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
return: string The code nicely finalised

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

return: string The header for the code block

format_header_content()   X-Ref
Returns the header content, formatted for output

return: string The header content, formatted for output

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

return: string The footer for the code block

format_footer_content()   X-Ref
Returns the footer content, formatted for output

return: string The footer content, formatted for output

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

get_attributes()   X-Ref
Gets the CSS attributes for this code

return: The CSS attributes for this code

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

geshi_highlight($string, $language, $path, $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)



Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics