⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geshi.php

📁 一款基于PHP的网络日记程序。WikyBlog支持:多用户的 BLOG
💻 PHP
📖 第 1 页 / 共 5 页
字号:
	}	/**	 * 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 &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     * @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.     *      * @param string The encoding to use for the source     * @since 1.0.3	 */	function set_encoding ($encoding)	{        if ($encoding) {		  $this->encoding = $encoding;        }	}	/**	 * 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     *      * @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 = @htmlspecialchars($this->source, ENT_COMPAT, $this->encoding);			// 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;		$stuff_to_parse   = '';		$result           = '';		// "Important" selections are handled like multiline comments        // @todo GET RID OF THIS SHIZ		if ($this->enable_important_blocks) {			$this->language_data['COMMENT_MULTI'][GESHI_START_IMPORTANT] = GESHI_END_IMPORTANT;		}		if ($this->strict_mode) {			// Break the source into bits. Each bit will be a portion of the code			// within script delimiters - for example, HTML between < and >			$parts = array(0 => array(0 => ''));			$k = 0;			for ($i = 0; $i < $length; $i++) {				$char = substr($code, $i, 1);				if (!$HIGHLIGHTING_ON) {					foreach ($this->language_data['SCRIPT_DELIMITERS'] as $key => $delimiters) {						foreach ($delimiters as $open => $close) {							// Get the next little bit for this opening string							$check = substr($code, $i, strlen($open));							// If it matches...							if ($check == $open) {								// We start a new block with the highlightable								// code in it								$HIGHLIGHTING_ON = $open;								$i += strlen($open) - 1;								$char = $open;								$parts[++$k][0] = $char;								// No point going around again...								break(2);							}						}					}				} else {					foreach ($this->language_data['SCRIPT_DELIMITERS'] as $key => $delimiters) {						foreach ($delimiters as $open => $close) {							if ($open == $HIGHLIGHTING_ON) {								// Found the closing tag								break(2);							}						}					}					// We check code from our current position BACKWARDS. This is so					// the ending string for highlighting can be included in the block					$check = substr($code, $i - strlen($close) + 1, strlen($close));					if ($check == $close) {						$HIGHLIGHTING_ON = '';						// Add the string to the rest of the string for this part						$parts[$k][1] = ( isset($parts[$k][1]) ) ? $parts[$k][1] . $char : $char;						$parts[++$k][0] = '';						$char = '';					}				}				$parts[$k][1] = ( isset($parts[$k][1]) ) ? $parts[$k][1] . $char : $char;			}			$HIGHLIGHTING_ON = '';		} else {			// Not strict mode - simply dump the source into			// the array at index 1 (the first highlightable block)			$parts = array(				1 => array(					0 => '',					1 => $code				)			);		}		// Now we go through each part. We know that even-indexed parts are		// code that shouldn't be highlighted, and odd-indexed parts should		// be highlighted		foreach ($parts as $key => $data) {			$part = $data[1];			// If this block should be highlighted...			if ($key % 2) {				if ($this->strict_mode) {					// Find the class key for this block of code					foreach ($this->language_data['SCRIPT_DELIMITERS'] as $script_key => $script_data) {						foreach ($script_data as $open => $close) {							if ($data[0] == $open) {								break(2);							}						}					}					if ($this->language_data['STYLES']['SCRIPT'][$script_key] != '' &&                        $this->lexic_permissions['SCRIPT']) {						// Add a span element around the source to						// highlight the overall source block						if (!$this->use_classes &&                            $this->language_data['STYLES']['SCRIPT'][$script_key] != '') {							$attributes = ' style="' . $this->language_data['STYLES']['SCRIPT'][$script_key] . '"';						} else {							$attributes = ' class="sc' . $script_key . '"';						}						$result .= "<span$attributes>";					}				}				if (!$this->strict_mode || $this->language_data['HIGHLIGHT_STRICT_BLOCK'][$script_key]) {					// Now, highlight the code in this block. This code					// is really the engine of GeSHi (along with the method					// parse_non_string_part).					$length = strlen($part);					for ($i = 0; $i < $length; $i++) {						// Get the next char						$char = substr($part, $i, 1);				        $hq = isset($this->language_data['HARDQUOTE']) ? $this->language_data['HARDQUOTE'][0] : false;						// Is this char the newline and line numbers being used?						if (($this->line_numbers != GESHI_NO_LINE_NUMBERS                            || count($this->highlight_extra_lines) > 0)                            && $char == "\n") {							// If so, is there a string open? If there is, we should end it before							// the newline and begin it again (so when <li>s are put in the source							// remains XHTML compliant)							// note to self: This opens up possibility of config files specifying							// that languages can/cannot have multiline strings???							if ($STRING_OPEN) {								if (!$this->use_classes) {									$attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][0] . '"';								} else {									$attributes = ' class="st0"';								}								$char = '</span>' . $char . "<span$attributes>";							}						} elseif ($char == $STRING_OPEN) {                            // A match of a string delimiter							if (($this->lexic_permissions['ESCAPE_CHAR'] && $ESCAPE_CHAR_OPEN) ||                                ($this->lexic_permissions['STRINGS'] && !$ESCAPE_CHAR_OPEN)) {								$char = htmlspecialchars($char, ENT_COMPAT, $this->encoding) . '</span>';							}						    $escape_me = false;    						if ($HARDQUOTE_OPEN)	    					{	    						if ($ESCAPE_CHAR_OPEN)								$escape_me = true;		    					else {			    					foreach ($this->language_data['HARDESCAPE'] as $hardesc)				    				if (substr($part, $i, strlen($hardesc)) == $hardesc)					    			{						    			$escape_me = true;							    		break;							    	}							    }						    }							if (!$ESCAPE_CHAR_OPEN) {								$STRING_OPEN = '';								$CLOSE_STRING = true;							}						    if (!$escape_me) {						    	$HARDQUOTE_OPEN = false;						    }							$ESCAPE_CHAR_OPEN = false;						} elseif (in_array($char, $this->language_data['QUOTEMARKS']) &&                            ($STRING_OPEN == '') && $this->lexic_permissions['STRINGS']) {                            // The start of a new string							$STRING_OPEN = $char;							if (!$this->use_classes) {								$attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][0] . '"';							} else {								$attributes = ' class="st0"';							}							$char = "<span$attributes>" . htmlspecialchars($char, ENT_COMPAT, $this->encoding);							$result .= $this->parse_non_string_part( $stuff_to_parse );							$stuff_to_parse = '';    				    } elseif (    					$hq &&    					substr($part, $i, strlen($hq)) == $hq &&    					($STRING_OPEN == '') && $this->lexic_permissions['STRINGS']    				    )    				    {    					// The start of a hard quoted string    					$STRING_OPEN = $this->language_data['HARDQUOTE'][1];    					if (!$this->use_classes) {    					    $attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][0] . '"';    					} else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -