tistory syntaxhighlighter 설정

일반 2012. 7. 26. 12:51

참고 : 다른 분것 참조를 했는데 링크를 읽어버렸습니다. ㅡㅡ;


위에 링크를 참조해서 span 태그의 whitepace 문제 수정







<script type="text/javascript">
<!--
;jQuery.noConflict();  // 다른 라이브러리와 충돌을 방지한다.
;(function($) { $(document).ready(function() {
//////////////////////////////////////////////////////////////////////////////////////
    $("blockquote[class^=brush]").each( function() {  //blokquote를 사용한 태그
        var $this = $(this);

        // 복사 붙여넣기 했을때 탭처리
        $this.find("span[class*=Apple-tab-span]").replaceWith(function() {
            return $(this).text();
        });

        // 편집창에서 직접 수정했을때 탭 처리
        $this.find("p[style*=margin-left]").each(function() {
            var $elem = $(this);
            var style = $elem.attr("style");
            var result = /\s*?margin-left:\s(\w+?)em;\s*?/gi.exec(style);
            if ( result != null ) {
                result = result[1];
            }
            var spaceCount = parseInt(result) * 2;
            var spaceString = "";
            for (var i = 0; i < spaceCount; i++) {
                spaceString += "&nbsp;";
            }
            $elem.removeAttr("style");
            $elem.html(spaceString + $elem.html());
        });

        var temp = $this.html(); //  내용 복사
        temp = temp.replace(/\n/gi, "");
        temp = temp.replace(/<p><\/p>/gi, "");
        temp = temp.replace(/<p><br\s*\/?><\/p>/gi, "\n");    // 줄바꿈
        temp = temp.replace(/<P>(.*?)<\/P>/gi, "$1\n");       // 한줄끝
        temp = temp.replace(/<br\s*\/?>/gi, "\n");            // 줄바꿈

        temp = '<script type="syntaxhighlighter" class="' + $this.attr('class') + '"><![CDATA[' + temp + ']]><\/script>'
        $this.replaceWith(temp);
    });
  
    $("pre[class^=brush]").each( function() {  //pre를 사용한 태그
    var $this = $(this);
        var temp = $this.html(); //  내용 복사
        temp = temp.replace(/</g, "&lt;");
        $this.html = temp;
    });     

    /*  SyntaxHighlighter 사용부분  */
    SyntaxHighlighter.defaults['toolbar'] = false; // 툴바 안 보기
    SyntaxHighlighter.all();
//////////////////////////////////////////////////////////////////////////////////////
});})(jQuery);
//-->
</script>


posted by 뚱2