예제 #1
0
	/**
	 *
	 * 코드 하이라이팅
	 * 
	 * @param array $matches 패턴매칭 결과
	 * @param array $params {@link NarinParser} 에서 전달하는 파라미터
	 * @return string code 태그
	 */
	public function wiki_code($matches, $params) {
		// $matches[1] = language
		// $matches[2] = code
		//print_r2($matches);
		if(!trim($matches[1])) {
			array_push($this->blocks, $matches[2]);
			return "<code></code>";
		}
		include_once "geshi.php";
		$geshi = new GeSHi(wiki_html($matches[2]), trim($matches[1]));
		$highlighted_code = trim(preg_replace('!^<pre[^>]*>|</pre>$!','',$geshi->parse_code()),"\n\r");
		array_push($this->blocks, $highlighted_code);
		return "<code></code>";
	}
예제 #2
0
	/**
	 *
	 * 코드 복구 (실제루틴)
	 * 
	 * @param array $matches 패턴매칭 결과
	 * @return string HTML로 변환 된 코드
	 */
	protected function _restoreHtml($matches)
	{
		$m = $this->blocks[0];
		array_shift($this->blocks);

		// text -> html
		$html = wiki_html($m);

		// 나쁜 태그 방지
		$html = $this->bad_tag_convert($html);

		// script 태그 방지
		if($this->allow_script_level > $this->writer_level) $html = $this->prevent_script($html);

		// iframe 태그 방지
		if($this->allow_iframe_level > $this->writer_level) $html = $this->prevent_iframe($html);

		// 복구
		if($matches[1] == "HTML") return "<div class='wiki_box'>".$html."</div>";
		else return $html;
	}