Skip to content

Instantly share code, notes, and snippets.

@yasyf
Created July 23, 2012 06:40
Show Gist options
  • Save yasyf/3162302 to your computer and use it in GitHub Desktop.
Save yasyf/3162302 to your computer and use it in GitHub Desktop.
Javascript to display source
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">&lt;!DOCTYPE html>\n&lt;html>\n' + document.documentElement.innerHTML.replace(/[<>]/g, function(m) { return {'<':'&lt;','>':'&gt;'}[m]}).replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1">$1</a>') + '\n&lt;/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();};
@yasyf
Copy link
Author

yasyf commented Jul 23, 2012

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">&lt;!DOCTYPE html>\n&lt;html>\n' + document.documentElement.innerHTML.replace(/[<>]/g, function(m) { return {'<':'&lt;','>':'&gt;'}[m]}).replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1">$1</a>') + '\n&lt;/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();};

@yasyf
Copy link
Author

yasyf commented Aug 4, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment