📄 geshi.php
字号:
/** * 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 * to overwrite them * @since 1.0.1 */ function set_symbols_style ($style, $preserve_defaults = false) { if (!$preserve_defaults) { $this->language_data['STYLES']['SYMBOLS'][0] = $style; } else { $this->language_data['STYLES']['SYMBOLS'][0] .= $style; } // For backward compatibility $this->set_brackets_style ($style, $preserve_defaults); } /** * Turns highlighting on/off for symbols * * @param boolean Whether to turn highlighting for symbols on or off * @since 1.0.0 */ function set_symbols_highlighting ($flag) { $this->lexic_permissions['SYMBOLS'] = ($flag) ? true : false; // For backward compatibility $this->set_brackets_highlighting ($flag); } /** * 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 * to overwrite them * @since 1.0.0 */ function set_strings_style ($style, $preserve_defaults = false) { if (!$preserve_defaults) { $this->language_data['STYLES']['STRINGS'][0] = $style; } else { $this->language_data['STYLES']['STRINGS'][0] .= $style; } } /** * Turns highlighting on/off for strings * * @param boolean Whether to turn highlighting for strings on or off * @since 1.0.0 */ function set_strings_highlighting ($flag) { $this->lexic_permissions['STRINGS'] = ($flag) ? true : false; } /** * 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 * to overwrite them * @since 1.0.0 */ function set_numbers_style ($style, $preserve_defaults = false) { if (!$preserve_defaults) { $this->language_data['STYLES']['NUMBERS'][0] = $style; } else { $this->language_data['STYLES']['NUMBERS'][0] .= $style; } } /** * Turns highlighting on/off for numbers * * @param boolean Whether to turn highlighting for numbers on or off * @since 1.0.0 */ function set_numbers_highlighting ($flag) { $this->lexic_permissions['NUMBERS'] = ($flag) ? true : false; } /** * 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 * to overwrite them * @since 1.0.0 */ function set_methods_style ($key, $style, $preserve_defaults = false) { if (!$preserve_defaults) { $this->language_data['STYLES']['METHODS'][$key] = $style; } else { $this->language_data['STYLES']['METHODS'][$key] .= $style; } } /** * Turns highlighting on/off for methods * * @param boolean Whether to turn highlighting for methods on or off * @since 1.0.0 */ function set_methods_highlighting ($flag) { $this->lexic_permissions['METHODS'] = ($flag) ? true : false; } /** * 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 * to overwrite them * @since 1.0.0 */ function set_regexps_style ($key, $style, $preserve_defaults = false) { if (!$preserve_defaults) { $this->language_data['STYLES']['REGEXPS'][$key] = $style; } else { $this->language_data['STYLES']['REGEXPS'][$key] .= $style; } } /** * 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 * @since 1.0.0 */ function set_regexps_highlighting ($key, $flag) { $this->lexic_permissions['REGEXPS'][$key] = ($flag) ? true : false; } /** * 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 * @since 1.0.0 */ function set_case_sensitivity ($key, $case) { $this->language_data['CASE_SENSITIVE'][$key] = ($case) ? true : false; } /** * 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 * @since 1.0.1 * @todo Error check the passed value */ function set_case_keywords ($case) { $this->language_data['CASE_KEYWORDS'] = $case; } /** * Sets how many spaces a tab is substituted for * * Widths below zero are ignored * * @param int The tab width * @since 1.0.0 */ function set_tab_width ($width) { $this->tab_width = intval($width); } /** * 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 * @since 1.0.0 */ function enable_strict_mode ($mode = true) { if (GESHI_MAYBE == $this->language_data['STRICT_MODE_APPLIES']) { $this->strict_mode = ($mode) ? true : false; } } /** * Disables all highlighting * * @since 1.0.0 * @todo Rewrite with an array traversal */ function disable_highlighting () { foreach ($this->lexic_permissions as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $this->lexic_permissions[$key][$k] = false; } } else { $this->lexic_permissions[$key] = false; } } // Context blocks $this->enable_important_blocks = false; } /** * Enables all highlighting * * @since 1.0.0 * @todo Rewrite with array traversal */ function enable_highlighting () { foreach ($this->lexic_permissions as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $this->lexic_permissions[$key][$k] = true; } } else { $this->lexic_permissions[$key] = true; } } // Context blocks $this->enable_important_blocks = true; } /** * 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 * @since 1.0.5 * @todo Re-think about how this method works (maybe make it private and/or make it * a extension->lang lookup?) * @todo static? */ function get_language_name_from_extension ( $extension, $lookup = array() ) { if ( !$lookup ) { $lookup = array( 'actionscript' => array('as'), 'ada' => array('a', 'ada', 'adb', 'ads'), 'apache' => array('conf'), 'asm' => array('ash', 'asm'), 'asp' => array('asp'), 'bash' => array('sh'), 'c' => array('c', 'h'), 'c_mac' => array('c', 'h'), 'caddcl' => array(), 'cadlisp' => array(), 'cdfg' => array('cdfg'), 'cpp' => array('cpp', 'h', 'hpp'), 'csharp' => array(), 'css' => array('css'), 'delphi' => array('dpk', 'dpr'), 'html4strict' => array('html', 'htm'), 'java' => array('java'), 'javascript' => array('js'), 'lisp' => array('lisp'), 'lua' => array('lua'), 'mpasm' => array(), 'nsis' => array(), 'objc' => array(), 'oobas' => array(), 'oracle8' => array(), 'pascal' => array('pas'), 'perl' => array('pl', 'pm'), 'php' => array('php', 'php5', 'phtml', 'phps'), 'python' => array('py'), 'qbasic' => array('bi'), 'sas' => array('sas'), 'smarty' => array(), 'vb' => array('bas'), 'vbnet' => array(), 'visualfoxpro' => array(), 'xml' => array('xml') ); } foreach ($lookup as $lang => $extensions) { foreach ($extensions as $ext) { if ($ext == $extension) { return $lang; } } } return ''; } /** * 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> * * @todo Complete rethink of this and above method * @since 1.0.5 */ function load_from_file ($file_name, $lookup = array()) { if (is_readable($file_name)) { $this->set_source(implode('', file($file_name))); $this->set_language($this->get_language_name_from_extension(substr(strrchr($file_name, '.'), 1), $lookup)); } else { $this->error = GESHI_ERROR_FILE_NOT_READABLE; } } /** * 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 * @since 1.0.0 */ function add_keyword ($key, $word) { $this->language_data['KEYWORDS'][$key][] = $word; } /** * 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 * @since 1.0.0 */ function remove_keyword ($key, $word) { $this->language_data['KEYWORDS'][$key] = array_diff($this->language_data['KEYWORDS'][$key], array($word)); } /** * 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 * @since 1.0.0 */ function add_keyword_group ( $key, $styles, $case_sensitive = true, $words = array() ) { $words = (array) $words; $this->language_data['KEYWORDS'][$key] = $words; $this->lexic_permissions['KEYWORDS'][$key] = true; $this->language_data['CASE_SENSITIVE'][$key] = $case_sensitive; $this->language_data['STYLES']['KEYWORDS'][$key] = $styles; } /** * Removes a keyword group * * @param int The key of the keyword group to remove * @since 1.0.0 */ function remove_keyword_group ($key) { unset($this->language_data['KEYWORDS'][$key]); unset($this->lexic_permissions['KEYWORDS'][$key]); unset($this->language_data['CASE_SENSITIVE'][$key]); unset($this->language_data['STYLES']['KEYWORDS'][$key]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -