1. download : http://code.google.com/p/syntaxhighlighter/
2. 설치
다운로드 받은 파일을 압축해제후 scripts, styles 폴더 안에 있는 파일들을 스킨-직접 올리기에서 모두 올린다.
그런 후에 아래 내용을 스킨-html/css 에서 html 태그중 </body> 위에 아래 내용을 추가한다.
-
- <link type="text/css" rel="stylesheet" href="./images/SyntaxHighlighter.css"></link>
- <script language="javascript" src="./images/shCore.js"></script>
- <script language="javascript" src="./images/shBrushCpp.js"></script>
- <script language="javascript" src="./images/shBrushCSharp.js"></script>
- <script language="javascript" src="./images/shBrushCss.js"></script>
- <script language="javascript" src="./images/shBrushDelphi.js"></script>
- <script language="javascript" src="./images/shBrushJava.js"></script>
- <script language="javascript" src="./images/shBrushJScript.js"></script>
- <script language="javascript" src="./images/shBrushPhp.js"></script>
- <script language="javascript" src="./images/shBrushPython.js"></script>
- <script language="javascript" src="./images/shBrushRuby.js"></script>
- <script language="javascript" src="./images/shBrushSql.js"></script>
- <script language="javascript" src="./images/shBrushVb.js"></script>
- <script language="javascript" src="./images/shBrushXml.js"></script>
- <script language="javascript">
- dp.SyntaxHighlighter.ClipboardSwf = 'http://your_address/images/clipboard.swf';
- dp.SyntaxHighlighter.HighlightAll('code');
- </script>
-
3. 사용법
- tag중 pre와 textarea에 대한 : http://code.google.com/p/syntaxhighlighter/wiki/PreAndTextarea
- 사용법에 대한 : http://code.google.com/p/syntaxhighlighter/wiki/Usage
- 사용 가능한 언어 : http://code.google.com/p/syntaxhighlighter/wiki/Languages
- 설정 : http://code.google.com/p/syntaxhighlighter/wiki/Configuration
출처 : http://srand.tistory.com/8
Usage
Placing the code
Place your code on the page and surround it with <pre> tag. Set name attribute to code and class attribute to one of the language aliases you wish to use.
<pre name="code" class="c-sharp">
... some code here ...
</pre>
NOTE: One important thing to watch out for is opening triangular bracket <. It must be replaced with an HTML equivalent of < in all cases. Failure to do won't break the page, but might break the source code displayed.
An alternative to <pre> is to use <textarea> tag. There are no problems with < character in that case. The main problem is that it doesn't look as good as <pre> tag if for some reason JavaScript didn't work (in RSS feed for example).
<textarea name="code" class="c#" cols="60" rows="10">
... some code here ...
</textarea>
Extended configuration
There's a way to pass a few configuration options to the code block. It's done via colon separated arguments.
<pre name="code" class="html:collapse">
... some code here ...
</pre>
Making it work
Finally, to get the whole thing to render properly on the page, you have to add JavaScript to the page.
<link type="text/css" rel="stylesheet" href="css/SyntaxHighlighter.css"></link>
<script language="javascript" src="js/shCore.js"></script>
<script language="javascript" src="js/shBrushCSharp.js"></script>
<script language="javascript" src="js/shBrushXml.js"></script>
<script language="javascript">
dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
</script>
For optimal result, place this code at the very end of your page. Check HighlightAll for more details about the function.