리자

게시판에 syntax highlight 적용하기

http://alexgorbatchev.com/ 에서 프로그램을 받아 웹에 업로드 한 후

<script type="text/javascript" src="<?=$g4['path']?>/js/syntaxhighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="<?=$g4['path']?>/js/syntaxhighlighter/scripts/shBrushPhp.js"></script>
<link type="text/css" rel="stylesheet" href="<?=$g4['path']?>/js/syntaxhighlighter/styles/shCore.css"/>
<link type="text/css" rel="stylesheet" href="<?=$g4['path']?>/js/syntaxhighlighter/styles/shThemeDefault.css"/>
<script type="text/javascript">
    SyntaxHighlighter.config.clipboardSwf = '<?=$g4['path']?>/js/syntaxhighlighter/scripts/clipboard.swf';
    SyntaxHighlighter.all();
</script>

이런식으로 적용합니다.


skin/board/basic/view.skin.php 에

        <!-- 내용 출력 -->
        <span id="writeContents">
        <?
        function _preg_callback($m)
        {
            $str = str_replace(array("<br/>", "&nbsp;"), array("\n", " "), $m[1]);
            return "<pre class='brush:php;'>$str</pre>";
        }

        $str = $view[content];
        $str = preg_replace_callback("/\[code\](.*)\[\/code\]/iU", "_preg_callback", $str);
        echo $str;
        ?>
        </span>

와 같이 코드를 수정합니다.



예)

http://sir.co.kr/bbs/board.php?bo_table=g4_qa&wr_id=155236

|

댓글 14개

감사합니다. 배추스킨에 적용 ^^
감사합니다~
진짜 짱이예요 감사합니다.
감사합니다. 적용하였습니다.

편집기능과 html 체크 해제하고 ... 그래야 정상동작합니다.
첨 보고 흘려버렸다가, 찾는데 30분이나 걸렸네요 적용해봐야겠네요 ㅎㅎ
좋은정보 감사합니다.
아 된장 이걸 이제 보다니
쌩유
모든 br을 걸러내지 못하므로
[code]
$str = preg_replace(array("/<(\/?)(br)([\/]*)?>/i","/&nbsp;/"),array("\n"," "), $m[1]);
[/code]
이걸로 바꿨습니다
이것은 진정 필요기능~~ 고맙습니다
[code]
<style>
#test{background:none}
</style>
[/code]
댓글을 작성하시려면 로그인이 필요합니다. 로그인

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요. 나누면 즐거움이 커집니다.

+
제목 글쓴이 날짜 조회
15년 전 조회 4,509
15년 전 조회 4,058
15년 전 조회 3,899
15년 전 조회 2,965
15년 전 조회 3,740
15년 전 조회 4,686
15년 전 조회 3,933
15년 전 조회 5,398
15년 전 조회 4,207
15년 전 조회 9,696
15년 전 조회 3,051
15년 전 조회 2.6만
15년 전 조회 6,019
15년 전 조회 4,288
15년 전 조회 4,259
15년 전 조회 3,573
15년 전 조회 5,958
15년 전 조회 7,702
15년 전 조회 6,699
15년 전 조회 4,017
🐛 버그신고