網頁程式碼美化程式 Google Code Prettify

target="_blank">Idea Grapes看到Google牌的網頁程式碼美化程式: href="http://code.google.com/p/google-code-prettify/"
target="_blank">Google Code Prettify,在 href="http://google-code-prettify.googlecode.com/svn/trunk/README.html"
target="_blank">README裡就能看到完整的安裝步驟。
id="mytag" value="google-code-prettify" type="hidden">

以下是google_adsense.js的源碼範例:

/*
* $Id: google_adsense.js 13029 2007-05-12 06:21:22Z emisjerry $
*
* Copyleft (c) Jerry Chien (http://blog.xuite.net/emisjerry), 2007/04/16
* Inspired by http://blog.xuite.net/misgarlic/weblogic/10337345
*
* 使用方法:
*   在自由欄位裡加入
*   div id="divGoogleAdSenseLinkScript">和
*   div id="divGoogleAdSenseContentScript">
*   與script src="http://emisjerry.googlepages.com/google_adsense.js">
*
* 2007/04/16 V1.0: 在文章內頁自動加入Google AdSense的script.
* 2007/04/22 V1.1: Xuite首頁最底也能顯示AdSense for Content.
*/
var isHomePage = true;  // 是否在Blog首頁?
var isXuite = false, isRoodo = false;

if (document.URL.indexOf(".roodo.") > 0) {  // for Roodo
isRoodo = true;
}
if (!isRoodo || document.URL.indexOf(".xuite.") > 0) {  // for Xuite
isXuite = true;
}

if (/^http:.*/d+.html(#comments|#trackback|)/.test(document.URL)) {
isHomePage = false;  // 在文章內頁; Roodo
//} else if (/^http:.*/d+(#|)(d+)$/.test(document.URL)) {
} else if (/^http://blog.xuite.net/.*/d+(?p=d+)?(#message|#trackback|)/.test(document.URL)) {
// } else if (/^http://blog.xuite.net/.*(d+|d+#.*)$/.test(document.URL)) {
isHomePage = false;  // 在文章內頁; Xuite /url/12345#message
}

if (isXuite || isRoodo) {
if (window.attachEvent) {
window.attachEvent('onload', init);
} else {
window.addEventListener('load', init, false);
}
}

//--FUNCTIONS-----------------------------------------------------------
// findTag('span','titlename', 'text');
function findTag(sTag, sName, sType) {
var aTags = document.getElementsByTagName(sTag);
var reg = new RegExp(sName);
var oResult = "";
for (var i in aTags) {
//alert(aTags[i].className);
if (reg.test(aTags[i].className)) {
if (sType=='text') {
oResult = aTags[i].textContent;
} else {
oResult = aTags[i];
}
break;
}
}
return oResult;
}

//===============================================================
function init() {
if (isXuite) {  // 把AdSense連結加到表頭
var _oTag1 = document.getElementById("divAdSenseLinkScript");
if (_oTag1 != null) {
_oTag = findTag("div", "description");
_oTag.innerHTML += _oTag1.innerHTML;
}
var _oTag2 = document.getElementById("divAdSenseContent2Script");
if (_oTag2 != null) {
document.getElementById("mid").innerHTML += _oTag2.innerHTML;
} else if (_oTag1 != null) {  // 沒有content2, 但有content
//!!document.getElementById("mid").innerHTML += _oTag1.innerHTML;
}
}
if (!isHomePage) {  // 在文章內頁裡加入文章底部的AdSense
var _oDiv = document.getElementById("divAdSenseContentScript");
if (_oDiv != null) {
if (isXuite) { // 把AdSense for Content加到文章底部
var _oTag = findTag("div", "blogbody");
_oTag.innerHTML += _oDiv.innerHTML;
} else if (isRoodo) {
var _oTag = findTag("div", "posted");
_oTag.innerHTML = _oDiv.innerHTML + _oTag.innerHTML;
}
}
}
}

參考:

dp.SyntaxHighlighter:在網頁顯示美觀的程式碼

target="_blank">網頁顯示程式碼的美容師:CodePress

您可能也會有興趣的類似文章

填寫回應

 

 

 

您可使用這些HTML標籤

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

隨機文章

  1. Vimperator/Pentadactyl的標記功能(Marks) 
  2. [分享] 程序員的宿命 (2)
  3. 日劇《我家的歷史》觀後感 (3)
  4. 幫Xuite增加單篇文章的雙擊快速編輯功能 (1)
  5. 神似 Google search的x-friend 
  6. 補遺:[軟體] 超強 Windows 字型美化軟體 – GDI++ (8)
  7. 兼具功能性與方便性的螢幕擷取軟體:Screenpresso (3)
  8. 灌水的無名小站訪客統計? (16)
  9. 用PlurkEasyEmoticon選取噗浪表情圖示 (7)
  10. [OOo] 自動圖文集與自動校正 

歷史熱門文章

  1. 如何手動輸入Plurk的表情圖示? (353,086 點擊/2008-09-29)
  2. 簡單放大Plurk輸入區的方法[修訂] (86,929 點擊/2008-09-29)
  3. 啟用&關閉中華電信ZyXEL P874的無線網路連線功能的步驟[修訂] (84,016 點擊/2011-06-01)
  4. Plurk CSS樣式自訂修改全攻略 (83,122 點擊/2009-07-04)
  5. 網路升級光世代50M/3M與設定ZyXEL P874 (53,311 點擊/2011-05-28)
  6. 輕鬆學會彈指神功-揭露AutoHotkey絕技 (43,177 點擊/2008-04-10)
  7. iPad新手入門技巧 (40,425 點擊/2011-02-05)
  8. 分享世博台灣館主題曲『台灣的心跳聲』MV(附歌詞+下載連結+新歌詞) (38,151 點擊/2010-04-27)
  9. 把HTC Touch HD操作介面換成Spb Mobile Shell,美觀又便利! (37,956 點擊/2009-02-18)
  10. 另一套適用手機的影片轉檔工具:WinAVI 3GP/MP4/PSP/iPod Video Converter (35,922 點擊/2009-04-18)