📄 geshi.php
字号:
'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]); } /** * Sets the content of the header block * * @param string The content of the header block * @since 1.0.2 */ function set_header_content($content) { $this->header_content = $content; } /** * Sets the content of the footer block * * @param string The content of the footer block * @since 1.0.2 */ function set_footer_content($content) { $this->footer_content = $content; } /** * Sets the style for the header content * * @param string The style for the header content * @since 1.0.2 */ function set_header_content_style($style) { $this->header_content_style = $style; } /** * Sets the style for the footer content * * @param string The style for the footer content * @since 1.0.2 */ function set_footer_content_style($style) { $this->footer_content_style = $style; } /** * 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 * the url somewhere, it is replaced by the keyword * that the URL is being made for * @since 1.0.2 */ function set_url_for_keyword_group($group, $url) { $this->language_data['URLS'][$group] = $url; } /** * Sets styles for links in code * * @param int A constant that specifies what state the style is being * set for - e.g. :hover or :visited * @param string The styles to use for that state * @since 1.0.2 */ function set_link_styles($type, $styles) { $this->link_styles[$type] = $styles; } /** * Sets the target for links in code * * @param string The target for links in the code, e.g. _blank * @since 1.0.3 */ function set_link_target($target) { if (!$target) { $this->link_target = ''; } else { $this->link_target = ' target="' . $target . '" '; } } /** * Sets styles for important parts of the code * * @param string The styles to use on important parts of the code * @since 1.0.2 */ function set_important_styles($styles) { $this->important_styles = $styles; } /** * Sets whether context-important blocks are highlighted * * @todo REMOVE THIS SHIZ FROM GESHI! * @deprecated */ function enable_important_blocks($flag) { $this->enable_important_blocks = ( $flag ) ? true : false; } /** * Whether CSS IDs should be added to each line * * @param boolean If true, IDs will be added to each line. * @since 1.0.2 */ function enable_ids($flag = true) { $this->add_ids = ($flag) ? true : false; } /** * Specifies which lines to highlight extra * * @param mixed An array of line numbers to highlight, or just a line * number on its own. * @since 1.0.2 * @todo Some data replication here that could be cut down on */ function highlight_lines_extra($lines) { if (is_array($lines)) { foreach ($lines as $line) { $this->highlight_extra_lines[intval($line)] = intval($line); } } else { $this->highlight_extra_lines[intval($lines)] = intval($lines); } } /** * Sets the style for extra-highlighted lines * * @param string The style for extra-highlighted lines * @since 1.0.2 */ function set_highlight_lines_extra_style($styles) { $this->highlight_extra_lines_style = $styles; } /** * 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 <ol> 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 * @since 1.0.2 */ function start_line_numbers_at($number) { $this->line_numbers_start = abs(intval($number)); } /** * 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 * @since 1.0.3 */ function set_encoding($encoding) { if ($encoding) { $this->encoding = $encoding; } } /** * Turns linking of keywords on or off. * * @param boolean If true, links will be added to keywords */ function enable_keyword_links($enable = true) { $this->keyword_links = ($enable) ? true : false; } /** * 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 * * @since 1.0.0 */ function parse_code () { // Start the timer $start_time = microtime(); // Firstly, if there is an error, we won't highlight if ($this->error) { $result = GeSHi::hsc($this->source); // Timing is irrelevant $this->set_time($start_time, $start_time); return $this->finalise($result); } // Replace all newlines to a common form. $code = str_replace("\r\n", "\n", $this->source); $code = str_replace("\r", "\n", $code); // Add spaces for regular expression matching and line numbers $code = "\n" . $code . "\n"; // Initialise various stuff $length = strlen($code); $STRING_OPEN = ''; $CLOSE_STRING = false; $ESCAPE_CHAR_OPEN = false; $COMMENT_MATCHED = false; // Turn highlighting on if strict mode doesn't apply to this language $HIGHLIGHTING_ON = ( !$this->strict_mode ) ? true : ''; // Whether to highlight inside a block of code $HIGHLIGHT_INSIDE_STRICT = false; $HARDQUOTE_OPEN = false; $STRICTATTRS = ''; $stuff_to_parse = ''; $result = ''; // "Important" selections are handled like multiline comments // @todo GET RID OF THIS SHIZ
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -