Created
July 23, 2012 06:40
-
-
Save yasyf/3162302 to your computer and use it in GitHub Desktop.
Javascript to display source
This file contains 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
document.documentElement.innerHTML = '<html><head><link rel="stylesheet" href="http://google-code-prettify.googlecode.com/svn/branches/release-1-Jun-2011/styles/sunburst.css" /></head><body><pre class="prettyprint"><!DOCTYPE html>\n<html>\n' + document.documentElement.innerHTML.replace(/[<>]/g, function(m) { return {'<':'<','>':'>'}[m]}).replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1">$1</a>') + '\n</html></pre></body></html>'; var head= document.getElementsByTagName('head')[0];var script= document.createElement('script');script.type= 'text/javascript';script.src= 'http://css-tricks.com/examples/ViewSourceButton/prettify/prettify.js';head.appendChild(script);script.onload = function(){prettyPrint();}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
works easily as a bookmarklet on iPhone (!!) or any other mobile device, which is handy.
javascript:document.documentElement.innerHTML = '<html><head><link rel="stylesheet" href="http://google-code-prettify.googlecode.com/svn/branches/release-1-Jun-2011/styles/sunburst.css" /></head><body><pre class="prettyprint"><!DOCTYPE html>\n<html>\n' + document.documentElement.innerHTML.replace(/[<>]/g, function(m) { return {'<':'<','>':'>'}[m]}).replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1">$1</a>') + '\n</html></pre></body></html>'; var head= document.getElementsByTagName('head')[0];var script= document.createElement('script');script.type= 'text/javascript';script.src= 'http://css-tricks.com/examples/ViewSourceButton/prettify/prettify.js';head.appendChild(script);script.onload = function(){prettyPrint();};