jQuery と google-code-prettify が必要
Created
February 8, 2012 05:19
-
-
Save mohayonao/1765702 to your computer and use it in GitHub Desktop.
scriptタグの中身をprettyprintする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// #!prettyprint <- この行のあるスクリプトが対象 | |
$(function() { | |
var count = 0; | |
$("script").each(function(i, e) { | |
var source = e.text; | |
if (source.indexOf("#!"+"prettyprint") === -1) return; | |
source = source.replace(/\/\/\s*<!\[CDATA\[/, ""); | |
source = source.replace(/\/\/\s*\]\]>/, ""); | |
source = source.replace(/<!\-\-/, ""); | |
source = source.replace(/\/\/\s*-->/, ""); | |
source = source.replace(new RegExp("//\\s*#!"+"prettyprint.*$", "gm"), ""); | |
source = source.replace(/^\s*$/gm, ""); | |
source = source.replace(/^\n/, ""); | |
$(document.createElement("pre")) | |
.addClass("prettyprint") | |
.text(source) | |
.insertAfter(e); | |
count += 1; | |
}); | |
if (count > 0) prettyPrint(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment