Skip to content

Instantly share code, notes, and snippets.

@blrun
Created August 21, 2014 22:26
Show Gist options
  • Save blrun/df70f12764cd9666be23 to your computer and use it in GitHub Desktop.
Save blrun/df70f12764cd9666be23 to your computer and use it in GitHub Desktop.
신택스 하이라이트 처리 루틴...
<?
// 신택스하이라이트 처리 시작
$codePattern = "#(\[[a-z]+\_code\:[0-9]+\{[^}]*?\}\]|\[\/[a-z]+\_code\])#si";
$temp = preg_split($codePattern,$memo,-1,PREG_SPLIT_DELIM_CAPTURE);
for($i=0;$i<count($temp);$i++) {
for($j=0;$j<count($code);$j++) {
$pattern1 = "#\[".$code[$j]."\_code\:([0-9]+)\{([^}]*?)\}\]#i";
$pattern2 = "#\[\/".$code[$j]."\_code\]#i";
if(preg_match($pattern1,$temp[$i])) {
if($code[$j]=="php")
$temp[$i]=preg_replace($pattern1,"<pre class=\"brush: $code[$j]; html_script: true; first-line: \\1\" title=\"\\2\">",$temp[$i]);
else
$temp[$i]=preg_replace($pattern1,"<pre class=\"brush: $code[$j]; first-line: \\1\" title=\"\\2\">",$temp[$i]);
$temp[$i+1]=str_replace("&amp;","&amp;amp;",$temp[$i+1]);
$temp[$i+1]=str_replace("&#039;","&amp;#039;",$temp[$i+1]);
$temp[$i+1]=str_replace("&quot;","&amp;quot;",$temp[$i+1]);
$temp[$i+1]=str_replace("&nbsp;","&amp;nbsp;",$temp[$i+1]);
$temp[$i+1]=str_replace("<","&lt;",$temp[$i+1]);
$i+=1;
}
elseif(preg_match($pattern2,$temp[$i])) {
$temp[$i]="</pre>";
}
}
}
$memo="";
for($i=0;$i<count($temp);$i++) {
$memo = $memo.$temp[$i];
}
// 신택스하이라이트 처리 끝
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment