내용변환(conv_content -> html_purifier)시 hook을 사용해서 prismjs를 적용
[참고] https://prismjs.com/index.html#examples
1. 그누보드 extend폴더 안에 아래 파일 생성
prism.extend.php
[code]
add_event('tail_sub', 'prism_tail_sub', G5_HOOK_DEFAULT_PRIORITY);
add_replace('html_purifier_result', 'prism_html_purifier_result', 10, 3);
function prism_script(){
add_stylesheet('<link rel="stylesheet" href="'.G5_PLUGIN_URL.'/prism/prism.css">', -2);
$sh = '<script src="'.G5_PLUGIN_URL.'/prism/prism.js"></script>'.PHP_EOL;
$sh .= '<script>var is_SyntaxHighlighter = true;</script>';
add_javascript($sh, 0);
}
function prism_tail_sub(){
global $wr_id;
if($_SERVER['SCRIPT_NAME'] != '/bbs/board.php' || !$wr_id) return;
prism_script();
}
function PrismJS($m) {
$str = isset($m[3]) ? $m[3] : '';
if(!$str)
return;
$str = stripslashes($str);
$str = preg_replace("/(<br>|<br \/>|<br\/>|<p>)/i", "\n", $str);
$str = preg_replace("/(<div>|<\/div>|<\/p>)/i", "", $str);
$str = str_replace(" ", " ", $str);
$str = str_replace("/</", "<", $str);
$str = str_replace("/[/", "[", $str);
$str = str_replace("/{/", "{", $str);
if(!$str)
return;
$brush = isset($m[2]) ? strtolower(trim($m[2])) : 'html';
//prism_script();
return '<div class="line-numbers"><pre><code class="language-'.$brush.'">'.$str.'</code></pre></div>'.PHP_EOL;
}
function prism_html_purifier_result($str){
$content = preg_replace_callback("/(\[code\]|\[code=(.*)\])(.*)\[\/code\]/iUs", "PrismJS", $str); // PrismJS
return $content;
}
[/code]
2. https://prismjs.com/download.html 접속해서 테마, 언어, 기능 다운로드(prism.js, prism.css)

3. 다운로드한 파일(prism.js, prism.css)을 플러그인 폴더에 업로드

4. Prism 의 Okaidia 테마적용

게시글 목록
| 번호 | 제목 |
|---|---|
| 23966 | |
| 23963 | |
| 23953 | |
| 23949 | |
| 23938 | |
| 23935 | |
| 23933 | |
| 23928 | |
| 23919 | |
| 23918 | |
| 23917 | |
| 23910 | |
| 23902 | |
| 23901 | |
| 23897 | |
| 23894 | |
| 23893 | |
| 23891 | |
| 23885 | |
| 23872 | |
| 23870 | |
| 23862 | |
| 23859 | |
| 23853 | |
| 23845 | |
| 23838 | |
| 23827 | |
| 23819 | |
| 23805 | |
| 23801 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기