2007年07月27日

使用dp.SyntaxHighlighter v1.5

php code
css code
html code
javascript code
vb script code
java code
sql code

php code
css code
html code
javascript code
vb script code
java code
sql code

Demo

//php code
<?php
var $test_var=true;
for(var $i=0;$i<10;$i++){
echo $i."\n";
}
?>
/*css code*/
.some_class{
color:#3366FF;
}
<!--html code-->
<b>this is html</b>
</pre>
//javascript code
function fn1(){
alert('this is javascript fn1');
}
'javascript code
Function Fn1
message "this is vb Fn1"
End Function
//java code
public static HuffmanEncoded Encode
(
Object obj
)
throws IOException
{
// serialize object
if ((obj instanceof Serializable) || (obj instanceof Externalizable))
{
// create an output byte array
ByteArrayOutputStream raw = new ByteArrayOutputStream();

// create an object Output stream
ObjectOutputStream out = new ObjectOutputStream(raw);

// write object to output stream
out.writeObject(obj);
out.flush();

// encode bytes
return Compress(raw.toByteArray());
}
else
throw new HuffmanException("can't encode non-serializable object");
}
SELECT  user.name FORM users WHERE user.boss='gan068' ORDER BY user.id DESC;
使用方式

http://code.google.com/p/syntaxhighlighter/downloads/list 下載檔案
在要程式碼化的地方用pre標籤包住,並加上name=code,class=html屬性
name就是要被程式碼彩色化的元素名稱
class就是要以哪種程式碼色彩套用到程式碼上,詳細設定請看這
http://code.google.com/p/syntaxhighlighter/wiki/Languages
例如
<pre name="code" class="html">
<!--some code-->
</pre>
最後在目標元素之後</body>之前放上
<!--
style sheet should be linked at the
top of the page
-->
<link type="text/css" rel="stylesheet" href="dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css"></link>
<!-- the following code should be place at the bottom of the
page -->
<script language="javascript" src="dp.SyntaxHighlighter/Scripts/shCore.js"></script>
<script language="javascript" src="dp.SyntaxHighlighter/Scripts/shBrushPhp.js"></script>
<script language="javascript" src="dp.SyntaxHighlighter/Scripts/shBrushCss.js"></script>
<script language="javascript" src="dp.SyntaxHighlighter/Scripts/shBrushXml.js"></script>
<script language="javascript" src="dp.SyntaxHighlighter/Scripts/shBrushCss.js"></script>
<script language="javascript" src="dp.SyntaxHighlighter/Scripts/shBrushJScript.js"></script>
<script language="javascript" src="dp.SyntaxHighlighter/Scripts/shBrushVb.js"></script>
<script language="javascript" src="dp.SyntaxHighlighter/Scripts/shBrushJava.js"></script>
<script language="javascript" src="dp.SyntaxHighlighter/Scripts/shBrushSql.js"></script>
<script>
dp.SyntaxHighlighter.ClipboardSwf = 'dp.SyntaxHighlighter/Scripts/clipboard.swf';
//目標元素名稱,範例為"code"
dp.SyntaxHighlighter.HighlightAll('code');
</script>
大功告成

Posted by gan068 at 樂多Roodo! │15:45 │回應(0)引用(0)IT
樂多分類:網路/3C 共同主題:Programing 工具:編輯本文
Ads by Roodo! 

引用URL

http://cgi.blog.roodo.com/trackback/3725193