Skip to content

Instantly share code, notes, and snippets.

@mohayonao
Created February 8, 2012 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohayonao/1765702 to your computer and use it in GitHub Desktop.
Save mohayonao/1765702 to your computer and use it in GitHub Desktop.
scriptタグの中身をprettyprintする
// #!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