├── .gitignore ├── lib ├── .jshintrc └── cssprettifier-bookmarklet.js ├── .jshintrc ├── package.json ├── LICENSE-MIT ├── Gruntfile.js ├── dist ├── bookmarklet.md ├── cssprettifier-bookmarklet.min.js └── cssprettifier-bookmarklet.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | -------------------------------------------------------------------------------- /lib/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "curly": true, 3 | "eqeqeq": true, 4 | "immed": true, 5 | "latedef": true, 6 | "newcap": true, 7 | "noarg": true, 8 | "sub": true, 9 | "undef": true, 10 | "boss": true, 11 | "eqnull": true, 12 | "predef": ["exports"] 13 | } 14 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "curly": true, 3 | "eqeqeq": true, 4 | "immed": true, 5 | "latedef": true, 6 | "newcap": true, 7 | "noarg": true, 8 | "sub": true, 9 | "undef": true, 10 | "unused": true, 11 | "boss": true, 12 | "eqnull": true, 13 | "node": true, 14 | "es5": true 15 | } 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cssprettifier-bookmarklet", 3 | "description": "A bookmarklet for unminifying and prettifying CSS", 4 | "version": "0.1.0", 5 | "homepage": "", 6 | "author": { 7 | "name": "Addy Osmani", 8 | "email": "addyosmani@gmail.com", 9 | "url": "http://addyosmani.com" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git://github.com/addyosmani/cssprettifier-bookmarklet.git" 14 | }, 15 | "bugs": { 16 | "url": "http://github.com/addyosmani/cssprettifier-bookmarklet" 17 | }, 18 | "licenses": [ 19 | { 20 | "type": "MIT", 21 | "url": "/blob/master/LICENSE-MIT" 22 | } 23 | ], 24 | "main": "lib/cssprettifier-bookmarklet", 25 | "engines": { 26 | "node": ">= 0.6.0" 27 | }, 28 | "scripts": { 29 | }, 30 | "devDependencies": { 31 | "grunt-contrib-concat": "~0.1.2", 32 | "grunt-contrib-uglify": "~0.1.1", 33 | "grunt-contrib-jshint": "~0.1.1", 34 | "grunt-contrib-nodeunit": "~0.1.2", 35 | "grunt-contrib-watch": "~0.2.0", 36 | "grunt": "~0.4.1" 37 | }, 38 | "keywords": [] 39 | } -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Addy Osmani, Sindre Sorhus 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(grunt) { 4 | 5 | // Project configuration. 6 | grunt.initConfig({ 7 | // Metadata. 8 | pkg: grunt.file.readJSON('package.json'), 9 | banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + 10 | '<%= grunt.template.today("yyyy-mm-dd") %>\n' + 11 | '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' + 12 | '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + 13 | ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n', 14 | // Task configuration. 15 | concat: { 16 | options: { 17 | banner: '<%= banner %>', 18 | stripBanners: true 19 | }, 20 | dist: { 21 | src: ['lib/<%= pkg.name %>.js'], 22 | dest: 'dist/<%= pkg.name %>.js' 23 | }, 24 | }, 25 | uglify: { 26 | options: { 27 | banner: '<%= banner %>' 28 | }, 29 | dist: { 30 | src: '<%= concat.dist.dest %>', 31 | dest: 'dist/<%= pkg.name %>.min.js' 32 | }, 33 | }, 34 | jshint: { 35 | options: { 36 | jshintrc: '.jshintrc', 37 | curly: true, 38 | eqeqeq: true, 39 | immed: true, 40 | latedef: true, 41 | newcap: true, 42 | noarg: true, 43 | sub: true, 44 | undef: true, 45 | unused: true, 46 | boss: true, 47 | eqnull: true, 48 | node: true, 49 | es5: true 50 | }, 51 | gruntfile: { 52 | src: 'Gruntfile.js' 53 | }, 54 | lib: { 55 | options: { 56 | jshintrc: 'lib/.jshintrc' 57 | }, 58 | src: ['lib/**/*.js'] 59 | } 60 | }, 61 | watch: { 62 | gruntfile: { 63 | files: '<%= jshint.gruntfile.src %>', 64 | tasks: ['jshint:gruntfile'] 65 | }, 66 | lib: { 67 | files: '<%= jshint.lib.src %>', 68 | tasks: ['jshint:lib', 'nodeunit'] 69 | } 70 | } 71 | }); 72 | 73 | // These plugins provide necessary tasks. 74 | grunt.loadNpmTasks('grunt-contrib-concat'); 75 | grunt.loadNpmTasks('grunt-contrib-uglify'); 76 | grunt.loadNpmTasks('grunt-contrib-nodeunit'); 77 | grunt.loadNpmTasks('grunt-contrib-jshint'); 78 | grunt.loadNpmTasks('grunt-contrib-watch'); 79 | 80 | // Default task. 81 | grunt.registerTask('default', ['concat', 'uglify']); 82 | 83 | }; 84 | -------------------------------------------------------------------------------- /dist/bookmarklet.md: -------------------------------------------------------------------------------- 1 | javascript:(function(){"use strict";(function(){function e(e,t){function n(e){return" "===e||"\n"===e||" "===e||"\r"===e||"\f"===e}function r(e){return"'"===e||'"'===e}function o(e){return g>="a"&&"z">=g||g>="A"&&"Z">=g||g>="0"&&"9">=g||"-_*.:#".indexOf(e)>=0}function a(){var e;for(e=d;e>0;e-=1)w+=s.indent}function i(){w=k(w),A?w+=" {":(w+="\n",a(),w+="{"),"\n"!==u&&(w+="\n"),d+=1}function l(){var e;d-=1,w=k(w),S&&(e=w.charAt(w.length-1),";"!==e&&"{"!==e&&(w+=";")),w+="\n",a(),w+="}",c.push(w),w=""}var s,c,g,u,f,h,p,d,m,y,k,v=0,b=e.length,w="",A=!0,S=!1;for(s=arguments.length>1?t:{},void 0===s.indent&&(s.indent=" "),"string"==typeof s.openbrace&&(A="end-of-line"===s.openbrace),"boolean"==typeof s.autosemicolon&&(S=s.autosemicolon),k=String.prototype.trimRight?function(e){return e.trimRight()}:function(e){return e.replace(/\s+$/,"")},p={Start:0,AtRule:1,Block:2,Selector:3,Ruleset:4,Property:5,Separator:6,Expression:7,URL:8},d=0,h=p.Start,y=!1,c=[],e=e.replace(/\r\n/g,"\n");b>v;)if(g=e.charAt(v),u=e.charAt(v+1),v+=1,r(m))w+=g,g===m&&(m=null),"\\"===g&&u===m&&(w+=u,v+=1);else if(r(g))w+=g,m=g;else if(y)w+=g,"*"===g&&"/"===u&&(y=!1,w+=u,v+=1);else if("/"!==g||"*"!==u){if(h===p.Start){if(0===c.length&&n(g)&&0===w.length)continue;if(" ">=g||g.charCodeAt(0)>=128){h=p.Start,w+=g;continue}if(o(g)||"["===g||"@"===g){if(f=k(w),0===f.length)c.length>0&&(w="\n\n");else if("}"===f.charAt(f.length-1)||";"===f.charAt(f.length-1))w=f+"\n\n";else for(;u=w.charAt(w.length-1)," "===u||9===u.charCodeAt(0);)w=w.substr(0,w.length-1);w+=g,h="@"===g?p.AtRule:p.Selector;continue}}if(h!==p.AtRule)if(h!==p.Block)if(h!==p.Selector)if(h!==p.Ruleset)if(h!==p.Property)if(h!==p.Separator)if(h!==p.Expression)h===p.URL&&")"===g&&w.charAt("\\"!==w.length-1)?(w+=g,h=p.Expression):w+=g;else{if("}"===g){l(),h=p.Start,d>0&&(h=p.Block);continue}if(";"===g){w=k(w),w+=";\n",h=p.Ruleset;continue}if(w+=g,"("===g&&"l"===w.charAt(w.length-2)&&"r"===w.charAt(w.length-3)&&"u"===w.charAt(w.length-4)){h=p.URL;continue}}else{if(!n(g)){w+=g,h=p.Expression;continue}r(u)&&(h=p.Expression)}else{if(":"===g){w=k(w),w+=": ",h=p.Expression,n(u)&&(h=p.Separator);continue}if("}"===g){l(),h=p.Start,d>0&&(h=p.Block);continue}w+=g}else{if("}"===g){l(),h=p.Start,d>0&&(h=p.Block);continue}if("\n"===g){w=k(w),w+="\n";continue}if(!n(g)){w=k(w),w+="\n",a(),w+=g,h=p.Property;continue}w+=g}else{if("{"===g){i(),h=p.Ruleset;continue}if("}"===g){l(),h=p.Start;continue}w+=g}else{if(o(g)){if(f=k(w),0===f.length)c.length>0&&(w="\n\n");else if("}"===f.charAt(f.length-1))w=f+"\n\n";else for(;u=w.charAt(w.length-1)," "===u||9===u.charCodeAt(0);)w=w.substr(0,w.length-1);a(),w+=g,h=p.Selector;continue}if("}"===g){l(),h=p.Start;continue}w+=g}else{if(";"===g){w+=g,h=p.Start;continue}if("{"===g){f=k(w),i(),h="@font-face"===f?p.Ruleset:p.Block;continue}w+=g}}else y=!0,w+=g,w+=u,v+=1;return w=c.join("")+w}"undefined"!=typeof exports?module.exports=exports=e:"object"==typeof window&&(window.cssbeautify=e)})(),function(){var e=/\blang(?:uage)?-(?!\*)(\w+)\b/i,t=self.Prism={util:{type:function(e){return Object.prototype.toString.call(e).match(/\[object (\w+)\]/)[1]},clone:function(e){var n=t.util.type(e);switch(n){case"Object":var r={};for(var o in e)e.hasOwnProperty(o)&&(r[o]=t.util.clone(e[o]));return r;case"Array":return e.slice()}return e}},languages:{extend:function(e,n){var r=t.util.clone(t.languages[e]);for(var o in n)r[o]=n[o];return r},insertBefore:function(e,n,r,o){o=o||t.languages;var a=o[e],i={};for(var l in a)if(a.hasOwnProperty(l)){if(l==n)for(var s in r)r.hasOwnProperty(s)&&(i[s]=r[s]);i[l]=a[l]}return o[e]=i},DFS:function(e,n){for(var r in e)n.call(e,r,e[r]),"Object"===t.util.type(e)&&t.languages.DFS(e[r],n)}},highlightAll:function(e,n){for(var r,o=document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'),a=0;r=o[a++];)t.highlightElement(r,e===!0,n)},highlightElement:function(r,o,a){for(var i,l,s=r;s&&!e.test(s.className);)s=s.parentNode;if(s&&(i=(s.className.match(e)||[,""])[1],l=t.languages[i]),l){r.className=r.className.replace(e,"").replace(/\s+/g," ")+" language-"+i,s=r.parentNode,/pre/i.test(s.nodeName)&&(s.className=s.className.replace(e,"").replace(/\s+/g," ")+" language-"+i);var c=r.textContent;if(c){c=c.replace(/&/g,"&").replace(//g,">").replace(/\u00a0/g," ");var g={element:r,language:i,grammar:l,code:c};if(t.hooks.run("before-highlight",g),o&&self.Worker){var u=new Worker(t.filename);u.onmessage=function(e){g.highlightedCode=n.stringify(JSON.parse(e.data)),g.element.innerHTML=g.highlightedCode,a&&a.call(g.element),t.hooks.run("after-highlight",g)},u.postMessage(JSON.stringify({language:g.language,code:g.code}))}else g.highlightedCode=t.highlight(g.code,g.grammar),g.element.innerHTML=g.highlightedCode,a&&a.call(r),t.hooks.run("after-highlight",g)}}},highlight:function(e,r){return n.stringify(t.tokenize(e,r))},tokenize:function(e,n){var r=t.Token,o=[e],a=n.rest;if(a){for(var i in a)n[i]=a[i];delete n.rest}e:for(var i in n)if(n.hasOwnProperty(i)&&n[i]){var l=n[i],s=l.inside,c=!!l.lookbehind||0;l=l.pattern||l;for(var g=0;o.length>g;g++){var u=o[g];if(o.length>e.length)break e;if(!(u instanceof r)){l.lastIndex=0;var f=l.exec(u);if(f){c&&(c=f[1].length);var h=f.index-1+c,f=f[0].slice(c),p=f.length,d=h+p,m=u.slice(0,h+1),y=u.slice(d+1),k=[g,1];m&&k.push(m);var v=new r(i,s?t.tokenize(f,s):f);k.push(v),y&&k.push(y),Array.prototype.splice.apply(o,k)}}}}return o},hooks:{all:{},add:function(e,n){var r=t.hooks.all;r[e]=r[e]||[],r[e].push(n)},run:function(e,n){var r=t.hooks.all[e];if(r&&r.length)for(var o,a=0;o=r[a++];)o(n)}}},n=t.Token=function(e,t){this.type=e,this.content=t};if(n.stringify=function(e){if("string"==typeof e)return e;if("[object Array]"==Object.prototype.toString.call(e))return e.map(n.stringify).join("");var r={type:e.type,content:n.stringify(e.content),tag:"span",classes:["token",e.type],attributes:{}};"comment"==r.type&&(r.attributes.spellcheck="true"),t.hooks.run("wrap",r);var o="";for(var a in r.attributes)o+=a+'="'+(r.attributes[a]||"")+'"';return"<"+r.tag+' class="'+r.classes.join(" ")+'" '+o+">"+r.content+""},!self.document)return self.addEventListener("message",function(e){var n=JSON.parse(e.data),r=n.language,o=n.code;self.postMessage(JSON.stringify(t.tokenize(o,t.languages[r]))),self.close()},!1),void 0;var r=document.getElementsByTagName("script");r=r[r.length-1],r&&(t.filename=r.src,document.addEventListener&&!r.hasAttribute("data-manual")&&document.addEventListener("DOMContentLoaded",t.highlightAll))}(),Prism.languages.css={comment:/\/\*[\w\W]*?\*\//g,atrule:/@[\w-]+?(\s+[^;{]+)?(?=\s*{|\s*;)/gi,url:/url\((["']?).*?\1\)/gi,selector:/[^\{\}\s][^\{\}]*(?=\s*\{)/g,property:/(\b|\B)[a-z-]+(?=\s*:)/gi,string:/("|')(\\?.)*?\1/g,important:/\B!important\b/gi,ignore:/&(lt|gt|amp);/gi,punctuation:/[\{\};:]/g},Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{style:{pattern:/(<|<)style[\w\W]*?(>|>)[\w\W]*?(<|<)\/style(>|>)/gi,inside:{tag:{pattern:/(<|<)style[\w\W]*?(>|>)|(<|<)\/style(>|>)/gi,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.css}}});var e=document.createElement("style"),t=cssbeautify(document.body.textContent,{autosemicolon:!0}),n=Prism.highlight(t,Prism.languages.css);e.textContent='code[class*="language-"],pre[class*="language-"]{color:black;text-shadow:0 1px white;font-family:Consolas,Monaco,\'Andale Mono\',monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;}@media print{code[class*="language-"],pre[class*="language-"]{text-shadow:none;}}pre[class*="language-"]{padding:1em;margin:.5em 0;overflow:auto;}:not(pre) > code[class*="language-"],pre[class*="language-"]{background:#f5f2f0;}:not(pre) > code[class*="language-"]{padding:.1em;border-radius:.3em;}.token.comment,.token.prolog,.token.doctype,.token.cdata{color:slategray;}.token.punctuation{color:#999;}.namespace{opacity:.7;}.token.property,.token.tag,.token.boolean,.token.number{color:#905;}.token.selector,.token.attr-name,.token.string{color:#690;}.token.operator,.token.entity,.token.url,.language-css .token.string,.style .token.string{color:#a67f59;background:hsla(0,0%,100%,.5);}.token.atrule,.token.attr-value,.token.keyword{color:#07a;}.token.regex,.token.important{color:#e90;}.token.important{font-weight:bold;}.token.entity{cursor:help;}',document.head.innerHTML="",document.head.appendChild(e),document.body.innerHTML="
"+n+"
"})(); -------------------------------------------------------------------------------- /dist/cssprettifier-bookmarklet.min.js: -------------------------------------------------------------------------------- 1 | /*! cssprettifier-bookmarklet - v0.1.0 - 2013-03-17 2 | * Copyright (c) 2013 Addy Osmani; Licensed MIT */ 3 | (function(){"use strict";(function(){function e(e,t){function n(e){return" "===e||"\n"===e||" "===e||"\r"===e||"\f"===e}function r(e){return"'"===e||'"'===e}function o(e){return g>="a"&&"z">=g||g>="A"&&"Z">=g||g>="0"&&"9">=g||"-_*.:#".indexOf(e)>=0}function a(){var e;for(e=d;e>0;e-=1)w+=s.indent}function i(){w=k(w),A?w+=" {":(w+="\n",a(),w+="{"),"\n"!==u&&(w+="\n"),d+=1}function l(){var e;d-=1,w=k(w),S&&(e=w.charAt(w.length-1),";"!==e&&"{"!==e&&(w+=";")),w+="\n",a(),w+="}",c.push(w),w=""}var s,c,g,u,f,h,p,d,m,y,k,v=0,b=e.length,w="",A=!0,S=!1;for(s=arguments.length>1?t:{},void 0===s.indent&&(s.indent=" "),"string"==typeof s.openbrace&&(A="end-of-line"===s.openbrace),"boolean"==typeof s.autosemicolon&&(S=s.autosemicolon),k=String.prototype.trimRight?function(e){return e.trimRight()}:function(e){return e.replace(/\s+$/,"")},p={Start:0,AtRule:1,Block:2,Selector:3,Ruleset:4,Property:5,Separator:6,Expression:7,URL:8},d=0,h=p.Start,y=!1,c=[],e=e.replace(/\r\n/g,"\n");b>v;)if(g=e.charAt(v),u=e.charAt(v+1),v+=1,r(m))w+=g,g===m&&(m=null),"\\"===g&&u===m&&(w+=u,v+=1);else if(r(g))w+=g,m=g;else if(y)w+=g,"*"===g&&"/"===u&&(y=!1,w+=u,v+=1);else if("/"!==g||"*"!==u){if(h===p.Start){if(0===c.length&&n(g)&&0===w.length)continue;if(" ">=g||g.charCodeAt(0)>=128){h=p.Start,w+=g;continue}if(o(g)||"["===g||"@"===g){if(f=k(w),0===f.length)c.length>0&&(w="\n\n");else if("}"===f.charAt(f.length-1)||";"===f.charAt(f.length-1))w=f+"\n\n";else for(;u=w.charAt(w.length-1)," "===u||9===u.charCodeAt(0);)w=w.substr(0,w.length-1);w+=g,h="@"===g?p.AtRule:p.Selector;continue}}if(h!==p.AtRule)if(h!==p.Block)if(h!==p.Selector)if(h!==p.Ruleset)if(h!==p.Property)if(h!==p.Separator)if(h!==p.Expression)h===p.URL&&")"===g&&w.charAt("\\"!==w.length-1)?(w+=g,h=p.Expression):w+=g;else{if("}"===g){l(),h=p.Start,d>0&&(h=p.Block);continue}if(";"===g){w=k(w),w+=";\n",h=p.Ruleset;continue}if(w+=g,"("===g&&"l"===w.charAt(w.length-2)&&"r"===w.charAt(w.length-3)&&"u"===w.charAt(w.length-4)){h=p.URL;continue}}else{if(!n(g)){w+=g,h=p.Expression;continue}r(u)&&(h=p.Expression)}else{if(":"===g){w=k(w),w+=": ",h=p.Expression,n(u)&&(h=p.Separator);continue}if("}"===g){l(),h=p.Start,d>0&&(h=p.Block);continue}w+=g}else{if("}"===g){l(),h=p.Start,d>0&&(h=p.Block);continue}if("\n"===g){w=k(w),w+="\n";continue}if(!n(g)){w=k(w),w+="\n",a(),w+=g,h=p.Property;continue}w+=g}else{if("{"===g){i(),h=p.Ruleset;continue}if("}"===g){l(),h=p.Start;continue}w+=g}else{if(o(g)){if(f=k(w),0===f.length)c.length>0&&(w="\n\n");else if("}"===f.charAt(f.length-1))w=f+"\n\n";else for(;u=w.charAt(w.length-1)," "===u||9===u.charCodeAt(0);)w=w.substr(0,w.length-1);a(),w+=g,h=p.Selector;continue}if("}"===g){l(),h=p.Start;continue}w+=g}else{if(";"===g){w+=g,h=p.Start;continue}if("{"===g){f=k(w),i(),h="@font-face"===f?p.Ruleset:p.Block;continue}w+=g}}else y=!0,w+=g,w+=u,v+=1;return w=c.join("")+w}"undefined"!=typeof exports?module.exports=exports=e:"object"==typeof window&&(window.cssbeautify=e)})(),function(){var e=/\blang(?:uage)?-(?!\*)(\w+)\b/i,t=self.Prism={util:{type:function(e){return Object.prototype.toString.call(e).match(/\[object (\w+)\]/)[1]},clone:function(e){var n=t.util.type(e);switch(n){case"Object":var r={};for(var o in e)e.hasOwnProperty(o)&&(r[o]=t.util.clone(e[o]));return r;case"Array":return e.slice()}return e}},languages:{extend:function(e,n){var r=t.util.clone(t.languages[e]);for(var o in n)r[o]=n[o];return r},insertBefore:function(e,n,r,o){o=o||t.languages;var a=o[e],i={};for(var l in a)if(a.hasOwnProperty(l)){if(l==n)for(var s in r)r.hasOwnProperty(s)&&(i[s]=r[s]);i[l]=a[l]}return o[e]=i},DFS:function(e,n){for(var r in e)n.call(e,r,e[r]),"Object"===t.util.type(e)&&t.languages.DFS(e[r],n)}},highlightAll:function(e,n){for(var r,o=document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'),a=0;r=o[a++];)t.highlightElement(r,e===!0,n)},highlightElement:function(r,o,a){for(var i,l,s=r;s&&!e.test(s.className);)s=s.parentNode;if(s&&(i=(s.className.match(e)||[,""])[1],l=t.languages[i]),l){r.className=r.className.replace(e,"").replace(/\s+/g," ")+" language-"+i,s=r.parentNode,/pre/i.test(s.nodeName)&&(s.className=s.className.replace(e,"").replace(/\s+/g," ")+" language-"+i);var c=r.textContent;if(c){c=c.replace(/&/g,"&").replace(//g,">").replace(/\u00a0/g," ");var g={element:r,language:i,grammar:l,code:c};if(t.hooks.run("before-highlight",g),o&&self.Worker){var u=new Worker(t.filename);u.onmessage=function(e){g.highlightedCode=n.stringify(JSON.parse(e.data)),g.element.innerHTML=g.highlightedCode,a&&a.call(g.element),t.hooks.run("after-highlight",g)},u.postMessage(JSON.stringify({language:g.language,code:g.code}))}else g.highlightedCode=t.highlight(g.code,g.grammar),g.element.innerHTML=g.highlightedCode,a&&a.call(r),t.hooks.run("after-highlight",g)}}},highlight:function(e,r){return n.stringify(t.tokenize(e,r))},tokenize:function(e,n){var r=t.Token,o=[e],a=n.rest;if(a){for(var i in a)n[i]=a[i];delete n.rest}e:for(var i in n)if(n.hasOwnProperty(i)&&n[i]){var l=n[i],s=l.inside,c=!!l.lookbehind||0;l=l.pattern||l;for(var g=0;o.length>g;g++){var u=o[g];if(o.length>e.length)break e;if(!(u instanceof r)){l.lastIndex=0;var f=l.exec(u);if(f){c&&(c=f[1].length);var h=f.index-1+c,f=f[0].slice(c),p=f.length,d=h+p,m=u.slice(0,h+1),y=u.slice(d+1),k=[g,1];m&&k.push(m);var v=new r(i,s?t.tokenize(f,s):f);k.push(v),y&&k.push(y),Array.prototype.splice.apply(o,k)}}}}return o},hooks:{all:{},add:function(e,n){var r=t.hooks.all;r[e]=r[e]||[],r[e].push(n)},run:function(e,n){var r=t.hooks.all[e];if(r&&r.length)for(var o,a=0;o=r[a++];)o(n)}}},n=t.Token=function(e,t){this.type=e,this.content=t};if(n.stringify=function(e){if("string"==typeof e)return e;if("[object Array]"==Object.prototype.toString.call(e))return e.map(n.stringify).join("");var r={type:e.type,content:n.stringify(e.content),tag:"span",classes:["token",e.type],attributes:{}};"comment"==r.type&&(r.attributes.spellcheck="true"),t.hooks.run("wrap",r);var o="";for(var a in r.attributes)o+=a+'="'+(r.attributes[a]||"")+'"';return"<"+r.tag+' class="'+r.classes.join(" ")+'" '+o+">"+r.content+""},!self.document)return self.addEventListener("message",function(e){var n=JSON.parse(e.data),r=n.language,o=n.code;self.postMessage(JSON.stringify(t.tokenize(o,t.languages[r]))),self.close()},!1),void 0;var r=document.getElementsByTagName("script");r=r[r.length-1],r&&(t.filename=r.src,document.addEventListener&&!r.hasAttribute("data-manual")&&document.addEventListener("DOMContentLoaded",t.highlightAll))}(),Prism.languages.css={comment:/\/\*[\w\W]*?\*\//g,atrule:/@[\w-]+?(\s+[^;{]+)?(?=\s*{|\s*;)/gi,url:/url\((["']?).*?\1\)/gi,selector:/[^\{\}\s][^\{\}]*(?=\s*\{)/g,property:/(\b|\B)[a-z-]+(?=\s*:)/gi,string:/("|')(\\?.)*?\1/g,important:/\B!important\b/gi,ignore:/&(lt|gt|amp);/gi,punctuation:/[\{\};:]/g},Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{style:{pattern:/(<|<)style[\w\W]*?(>|>)[\w\W]*?(<|<)\/style(>|>)/gi,inside:{tag:{pattern:/(<|<)style[\w\W]*?(>|>)|(<|<)\/style(>|>)/gi,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.css}}});var e=document.createElement("style"),t=cssbeautify(document.body.textContent,{autosemicolon:!0}),n=Prism.highlight(t,Prism.languages.css);e.textContent='code[class*="language-"],pre[class*="language-"]{color:black;text-shadow:0 1px white;font-family:Consolas,Monaco,\'Andale Mono\',monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;}@media print{code[class*="language-"],pre[class*="language-"]{text-shadow:none;}}pre[class*="language-"]{padding:1em;margin:.5em 0;overflow:auto;}:not(pre) > code[class*="language-"],pre[class*="language-"]{background:#f5f2f0;}:not(pre) > code[class*="language-"]{padding:.1em;border-radius:.3em;}.token.comment,.token.prolog,.token.doctype,.token.cdata{color:slategray;}.token.punctuation{color:#999;}.namespace{opacity:.7;}.token.property,.token.tag,.token.boolean,.token.number{color:#905;}.token.selector,.token.attr-name,.token.string{color:#690;}.token.operator,.token.entity,.token.url,.language-css .token.string,.style .token.string{color:#a67f59;background:hsla(0,0%,100%,.5);}.token.atrule,.token.attr-value,.token.keyword{color:#07a;}.token.regex,.token.important{color:#e90;}.token.important{font-weight:bold;}.token.entity{cursor:help;}',document.head.innerHTML="",document.head.appendChild(e),document.body.innerHTML="
"+n+"
"})(); -------------------------------------------------------------------------------- /dist/cssprettifier-bookmarklet.js: -------------------------------------------------------------------------------- 1 | /*! cssprettifier-bookmarklet - v0.1.0 - 2013-03-17 2 | * Copyright (c) 2013 Addy Osmani; Licensed MIT */ 3 | /*globals document:true*/ 4 | (function () { 5 | 'use strict'; 6 | 7 | // cssbeautify 8 | (function(){"use strict";function a(a,b){function s(a){return" "===a||"\n"===a||" "===a||"\r"===a||"\f"===a}function t(a){return"'"===a||'"'===a}function u(a){return h>="a"&&"z">=h||h>="A"&&"Z">=h||h>="0"&&"9">=h||"-_*.:#".indexOf(a)>=0}function v(){var a;for(a=m;a>0;a-=1)g+=c.indent}function w(){g=r(g),p?g+=" {":(g+="\n",v(),g+="{"),"\n"!==i&&(g+="\n"),m+=1}function x(){var a;m-=1,g=r(g),q&&(a=g.charAt(g.length-1),";"!==a&&"{"!==a&&(g+=";")),g+="\n",v(),g+="}",f.push(g),g=""}var c,f,h,i,j,k,l,m,n,o,r,d=0,e=a.length,g="",p=!0,q=!1;for(c=arguments.length>1?b:{},c.indent===void 0&&(c.indent=" "),"string"==typeof c.openbrace&&(p="end-of-line"===c.openbrace),"boolean"==typeof c.autosemicolon&&(q=c.autosemicolon),r=String.prototype.trimRight?function(a){return a.trimRight()}:function(a){return a.replace(/\s+$/,"")},l={Start:0,AtRule:1,Block:2,Selector:3,Ruleset:4,Property:5,Separator:6,Expression:7,URL:8},m=0,k=l.Start,o=!1,f=[],a=a.replace(/\r\n/g,"\n");e>d;)if(h=a.charAt(d),i=a.charAt(d+1),d+=1,t(n))g+=h,h===n&&(n=null),"\\"===h&&i===n&&(g+=i,d+=1);else if(t(h))g+=h,n=h;else if(o)g+=h,"*"===h&&"/"===i&&(o=!1,g+=i,d+=1);else if("/"!==h||"*"!==i){if(k===l.Start){if(0===f.length&&s(h)&&0===g.length)continue;if(" ">=h||h.charCodeAt(0)>=128){k=l.Start,g+=h;continue}if(u(h)||"["===h||"@"===h){if(j=r(g),0===j.length)f.length>0&&(g="\n\n");else if("}"===j.charAt(j.length-1)||";"===j.charAt(j.length-1))g=j+"\n\n";else for(;;){if(i=g.charAt(g.length-1)," "!==i&&9!==i.charCodeAt(0))break;g=g.substr(0,g.length-1)}g+=h,k="@"===h?l.AtRule:l.Selector;continue}}if(k!==l.AtRule)if(k!==l.Block)if(k!==l.Selector)if(k!==l.Ruleset)if(k!==l.Property)if(k!==l.Separator)if(k!==l.Expression)k===l.URL&&")"===h&&g.charAt("\\"!==g.length-1)?(g+=h,k=l.Expression):g+=h;else{if("}"===h){x(),k=l.Start,m>0&&(k=l.Block);continue}if(";"===h){g=r(g),g+=";\n",k=l.Ruleset;continue}if(g+=h,"("===h&&"l"===g.charAt(g.length-2)&&"r"===g.charAt(g.length-3)&&"u"===g.charAt(g.length-4)){k=l.URL;continue}}else{if(!s(h)){g+=h,k=l.Expression;continue}t(i)&&(k=l.Expression)}else{if(":"===h){g=r(g),g+=": ",k=l.Expression,s(i)&&(k=l.Separator);continue}if("}"===h){x(),k=l.Start,m>0&&(k=l.Block);continue}g+=h}else{if("}"===h){x(),k=l.Start,m>0&&(k=l.Block);continue}if("\n"===h){g=r(g),g+="\n";continue}if(!s(h)){g=r(g),g+="\n",v(),g+=h,k=l.Property;continue}g+=h}else{if("{"===h){w(),k=l.Ruleset;continue}if("}"===h){x(),k=l.Start;continue}g+=h}else{if(u(h)){if(j=r(g),0===j.length)f.length>0&&(g="\n\n");else if("}"===j.charAt(j.length-1))g=j+"\n\n";else for(;;){if(i=g.charAt(g.length-1)," "!==i&&9!==i.charCodeAt(0))break;g=g.substr(0,g.length-1)}v(),g+=h,k=l.Selector;continue}if("}"===h){x(),k=l.Start;continue}g+=h}else{if(";"===h){g+=h,k=l.Start;continue}if("{"===h){j=r(g),w(),k="@font-face"===j?l.Ruleset:l.Block;continue}g+=h}}else o=!0,g+=h,g+=i,d+=1;return g=f.join("")+g}"undefined"!=typeof exports?module.exports=exports=a:"object"==typeof window&&(window.cssbeautify=a)})(); 9 | // prism 10 | (function(){var e=/\blang(?:uage)?-(?!\*)(\w+)\b/i,t=self.Prism={util:{type:function(e){return Object.prototype.toString.call(e).match(/\[object (\w+)\]/)[1]},clone:function(e){var n=t.util.type(e);switch(n){case"Object":var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=t.util.clone(e[i]));return r;case"Array":return e.slice()}return e}},languages:{extend:function(e,n){var r=t.util.clone(t.languages[e]);for(var i in n)r[i]=n[i];return r},insertBefore:function(e,n,r,i){i=i||t.languages;var s=i[e],o={};for(var u in s)if(s.hasOwnProperty(u)){if(u==n)for(var a in r)r.hasOwnProperty(a)&&(o[a]=r[a]);o[u]=s[u]}return i[e]=o},DFS:function(e,n){for(var r in e){n.call(e,r,e[r]);t.util.type(e)==="Object"&&t.languages.DFS(e[r],n)}}},highlightAll:function(e,n){var r=document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');for(var i=0,s;s=r[i++];)t.highlightElement(s,e===!0,n)},highlightElement:function(r,i,s){var o,u,a=r;while(a&&!e.test(a.className))a=a.parentNode;if(a){o=(a.className.match(e)||[,""])[1];u=t.languages[o]}if(!u)return;r.className=r.className.replace(e,"").replace(/\s+/g," ")+" language-"+o;a=r.parentNode;/pre/i.test(a.nodeName)&&(a.className=a.className.replace(e,"").replace(/\s+/g," ")+" language-"+o);var f=r.textContent;if(!f)return;f=f.replace(/&/g,"&").replace(//g,">").replace(/\u00a0/g," ");var l={element:r,language:o,grammar:u,code:f};t.hooks.run("before-highlight",l);if(i&&self.Worker){var c=new Worker(t.filename);c.onmessage=function(e){l.highlightedCode=n.stringify(JSON.parse(e.data));l.element.innerHTML=l.highlightedCode;s&&s.call(l.element);t.hooks.run("after-highlight",l)};c.postMessage(JSON.stringify({language:l.language,code:l.code}))}else{l.highlightedCode=t.highlight(l.code,l.grammar);l.element.innerHTML=l.highlightedCode;s&&s.call(r);t.hooks.run("after-highlight",l)}},highlight:function(e,r){return n.stringify(t.tokenize(e,r))},tokenize:function(e,n){var r=t.Token,i=[e],s=n.rest;if(s){for(var o in s)n[o]=s[o];delete n.rest}e:for(var o in n){if(!n.hasOwnProperty(o)||!n[o])continue;var u=n[o],a=u.inside,f=!!u.lookbehind||0;u=u.pattern||u;for(var l=0;le.length)break e;if(c instanceof r)continue;u.lastIndex=0;var h=u.exec(c);if(h){f&&(f=h[1].length);var p=h.index-1+f,h=h[0].slice(f),d=h.length,v=p+d,m=c.slice(0,p+1),g=c.slice(v+1),y=[l,1];m&&y.push(m);var b=new r(o,a?t.tokenize(h,a):h);y.push(b);g&&y.push(g);Array.prototype.splice.apply(i,y)}}}return i},hooks:{all:{},add:function(e,n){var r=t.hooks.all;r[e]=r[e]||[];r[e].push(n)},run:function(e,n){var r=t.hooks.all[e];if(!r||!r.length)return;for(var i=0,s;s=r[i++];)s(n)}}},n=t.Token=function(e,t){this.type=e;this.content=t};n.stringify=function(e){if(typeof e=="string")return e;if(Object.prototype.toString.call(e)=="[object Array]")return e.map(n.stringify).join("");var r={type:e.type,content:n.stringify(e.content),tag:"span",classes:["token",e.type],attributes:{}};r.type=="comment"&&(r.attributes.spellcheck="true");t.hooks.run("wrap",r);var i="";for(var s in r.attributes)i+=s+'="'+(r.attributes[s]||"")+'"';return"<"+r.tag+' class="'+r.classes.join(" ")+'" '+i+">"+r.content+""};if(!self.document){self.addEventListener("message",function(e){var n=JSON.parse(e.data),r=n.language,i=n.code;self.postMessage(JSON.stringify(t.tokenize(i,t.languages[r])));self.close()},!1);return}var r=document.getElementsByTagName("script");r=r[r.length-1];if(r){t.filename=r.src;document.addEventListener&&!r.hasAttribute("data-manual")&&document.addEventListener("DOMContentLoaded",t.highlightAll)}})();; 11 | Prism.languages.css={comment:/\/\*[\w\W]*?\*\//g,atrule:/@[\w-]+?(\s+[^;{]+)?(?=\s*{|\s*;)/gi,url:/url\((["']?).*?\1\)/gi,selector:/[^\{\}\s][^\{\}]*(?=\s*\{)/g,property:/(\b|\B)[a-z-]+(?=\s*:)/ig,string:/("|')(\\?.)*?\1/g,important:/\B!important\b/gi,ignore:/&(lt|gt|amp);/gi,punctuation:/[\{\};:]/g};Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{style:{pattern:/(<|<)style[\w\W]*?(>|>)[\w\W]*?(<|<)\/style(>|>)/ig,inside:{tag:{pattern:/(<|<)style[\w\W]*?(>|>)|(<|<)\/style(>|>)/ig,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.css}}}); 12 | 13 | var prismStyle = document.createElement('style'); 14 | var beautified = cssbeautify(document.body.textContent, {autosemicolon: true}); 15 | var highlighted = Prism.highlight(beautified, Prism.languages.css); 16 | 17 | prismStyle.textContent = 'code[class*="language-"],pre[class*="language-"]{color:black;text-shadow:0 1px white;font-family:Consolas,Monaco,\'Andale Mono\',monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;}@media print{code[class*="language-"],pre[class*="language-"]{text-shadow:none;}}pre[class*="language-"]{padding:1em;margin:.5em 0;overflow:auto;}:not(pre) > code[class*="language-"],pre[class*="language-"]{background:#f5f2f0;}:not(pre) > code[class*="language-"]{padding:.1em;border-radius:.3em;}.token.comment,.token.prolog,.token.doctype,.token.cdata{color:slategray;}.token.punctuation{color:#999;}.namespace{opacity:.7;}.token.property,.token.tag,.token.boolean,.token.number{color:#905;}.token.selector,.token.attr-name,.token.string{color:#690;}.token.operator,.token.entity,.token.url,.language-css .token.string,.style .token.string{color:#a67f59;background:hsla(0,0%,100%,.5);}.token.atrule,.token.attr-value,.token.keyword{color:#07a;}.token.regex,.token.important{color:#e90;}.token.important{font-weight:bold;}.token.entity{cursor:help;}'; 18 | 19 | document.head.innerHTML = ''; 20 | document.head.appendChild(prismStyle); 21 | document.body.innerHTML = '
' + highlighted + '
'; 22 | 23 | })(); -------------------------------------------------------------------------------- /lib/cssprettifier-bookmarklet.js: -------------------------------------------------------------------------------- 1 | /* 2 | * cssprettifier-bookmarklet 3 | * A bookmarklet for unminifying and prettifying CSS 4 | * in the browser 5 | * Copyright (c) 2013 Addy Osmani, Sindre Sorhus 6 | * CSSBeautify (c) Sencha, Ariya Hidayat 7 | * Prism (c) Lea Verou 8 | * Licensed under the MIT license. 9 | */ 10 | /*globals document:true*/ 11 | (function () { 12 | 'use strict'; 13 | 14 | // cssbeautify 15 | (function(){"use strict";function a(a,b){function s(a){return" "===a||"\n"===a||" "===a||"\r"===a||"\f"===a}function t(a){return"'"===a||'"'===a}function u(a){return h>="a"&&"z">=h||h>="A"&&"Z">=h||h>="0"&&"9">=h||"-_*.:#".indexOf(a)>=0}function v(){var a;for(a=m;a>0;a-=1)g+=c.indent}function w(){g=r(g),p?g+=" {":(g+="\n",v(),g+="{"),"\n"!==i&&(g+="\n"),m+=1}function x(){var a;m-=1,g=r(g),q&&(a=g.charAt(g.length-1),";"!==a&&"{"!==a&&(g+=";")),g+="\n",v(),g+="}",f.push(g),g=""}var c,f,h,i,j,k,l,m,n,o,r,d=0,e=a.length,g="",p=!0,q=!1;for(c=arguments.length>1?b:{},c.indent===void 0&&(c.indent=" "),"string"==typeof c.openbrace&&(p="end-of-line"===c.openbrace),"boolean"==typeof c.autosemicolon&&(q=c.autosemicolon),r=String.prototype.trimRight?function(a){return a.trimRight()}:function(a){return a.replace(/\s+$/,"")},l={Start:0,AtRule:1,Block:2,Selector:3,Ruleset:4,Property:5,Separator:6,Expression:7,URL:8},m=0,k=l.Start,o=!1,f=[],a=a.replace(/\r\n/g,"\n");e>d;)if(h=a.charAt(d),i=a.charAt(d+1),d+=1,t(n))g+=h,h===n&&(n=null),"\\"===h&&i===n&&(g+=i,d+=1);else if(t(h))g+=h,n=h;else if(o)g+=h,"*"===h&&"/"===i&&(o=!1,g+=i,d+=1);else if("/"!==h||"*"!==i){if(k===l.Start){if(0===f.length&&s(h)&&0===g.length)continue;if(" ">=h||h.charCodeAt(0)>=128){k=l.Start,g+=h;continue}if(u(h)||"["===h||"@"===h){if(j=r(g),0===j.length)f.length>0&&(g="\n\n");else if("}"===j.charAt(j.length-1)||";"===j.charAt(j.length-1))g=j+"\n\n";else for(;;){if(i=g.charAt(g.length-1)," "!==i&&9!==i.charCodeAt(0))break;g=g.substr(0,g.length-1)}g+=h,k="@"===h?l.AtRule:l.Selector;continue}}if(k!==l.AtRule)if(k!==l.Block)if(k!==l.Selector)if(k!==l.Ruleset)if(k!==l.Property)if(k!==l.Separator)if(k!==l.Expression)k===l.URL&&")"===h&&g.charAt("\\"!==g.length-1)?(g+=h,k=l.Expression):g+=h;else{if("}"===h){x(),k=l.Start,m>0&&(k=l.Block);continue}if(";"===h){g=r(g),g+=";\n",k=l.Ruleset;continue}if(g+=h,"("===h&&"l"===g.charAt(g.length-2)&&"r"===g.charAt(g.length-3)&&"u"===g.charAt(g.length-4)){k=l.URL;continue}}else{if(!s(h)){g+=h,k=l.Expression;continue}t(i)&&(k=l.Expression)}else{if(":"===h){g=r(g),g+=": ",k=l.Expression,s(i)&&(k=l.Separator);continue}if("}"===h){x(),k=l.Start,m>0&&(k=l.Block);continue}g+=h}else{if("}"===h){x(),k=l.Start,m>0&&(k=l.Block);continue}if("\n"===h){g=r(g),g+="\n";continue}if(!s(h)){g=r(g),g+="\n",v(),g+=h,k=l.Property;continue}g+=h}else{if("{"===h){w(),k=l.Ruleset;continue}if("}"===h){x(),k=l.Start;continue}g+=h}else{if(u(h)){if(j=r(g),0===j.length)f.length>0&&(g="\n\n");else if("}"===j.charAt(j.length-1))g=j+"\n\n";else for(;;){if(i=g.charAt(g.length-1)," "!==i&&9!==i.charCodeAt(0))break;g=g.substr(0,g.length-1)}v(),g+=h,k=l.Selector;continue}if("}"===h){x(),k=l.Start;continue}g+=h}else{if(";"===h){g+=h,k=l.Start;continue}if("{"===h){j=r(g),w(),k="@font-face"===j?l.Ruleset:l.Block;continue}g+=h}}else o=!0,g+=h,g+=i,d+=1;return g=f.join("")+g}"undefined"!=typeof exports?module.exports=exports=a:"object"==typeof window&&(window.cssbeautify=a)})(); 16 | // prism 17 | (function(){var e=/\blang(?:uage)?-(?!\*)(\w+)\b/i,t=self.Prism={util:{type:function(e){return Object.prototype.toString.call(e).match(/\[object (\w+)\]/)[1]},clone:function(e){var n=t.util.type(e);switch(n){case"Object":var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=t.util.clone(e[i]));return r;case"Array":return e.slice()}return e}},languages:{extend:function(e,n){var r=t.util.clone(t.languages[e]);for(var i in n)r[i]=n[i];return r},insertBefore:function(e,n,r,i){i=i||t.languages;var s=i[e],o={};for(var u in s)if(s.hasOwnProperty(u)){if(u==n)for(var a in r)r.hasOwnProperty(a)&&(o[a]=r[a]);o[u]=s[u]}return i[e]=o},DFS:function(e,n){for(var r in e){n.call(e,r,e[r]);t.util.type(e)==="Object"&&t.languages.DFS(e[r],n)}}},highlightAll:function(e,n){var r=document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');for(var i=0,s;s=r[i++];)t.highlightElement(s,e===!0,n)},highlightElement:function(r,i,s){var o,u,a=r;while(a&&!e.test(a.className))a=a.parentNode;if(a){o=(a.className.match(e)||[,""])[1];u=t.languages[o]}if(!u)return;r.className=r.className.replace(e,"").replace(/\s+/g," ")+" language-"+o;a=r.parentNode;/pre/i.test(a.nodeName)&&(a.className=a.className.replace(e,"").replace(/\s+/g," ")+" language-"+o);var f=r.textContent;if(!f)return;f=f.replace(/&/g,"&").replace(//g,">").replace(/\u00a0/g," ");var l={element:r,language:o,grammar:u,code:f};t.hooks.run("before-highlight",l);if(i&&self.Worker){var c=new Worker(t.filename);c.onmessage=function(e){l.highlightedCode=n.stringify(JSON.parse(e.data));l.element.innerHTML=l.highlightedCode;s&&s.call(l.element);t.hooks.run("after-highlight",l)};c.postMessage(JSON.stringify({language:l.language,code:l.code}))}else{l.highlightedCode=t.highlight(l.code,l.grammar);l.element.innerHTML=l.highlightedCode;s&&s.call(r);t.hooks.run("after-highlight",l)}},highlight:function(e,r){return n.stringify(t.tokenize(e,r))},tokenize:function(e,n){var r=t.Token,i=[e],s=n.rest;if(s){for(var o in s)n[o]=s[o];delete n.rest}e:for(var o in n){if(!n.hasOwnProperty(o)||!n[o])continue;var u=n[o],a=u.inside,f=!!u.lookbehind||0;u=u.pattern||u;for(var l=0;le.length)break e;if(c instanceof r)continue;u.lastIndex=0;var h=u.exec(c);if(h){f&&(f=h[1].length);var p=h.index-1+f,h=h[0].slice(f),d=h.length,v=p+d,m=c.slice(0,p+1),g=c.slice(v+1),y=[l,1];m&&y.push(m);var b=new r(o,a?t.tokenize(h,a):h);y.push(b);g&&y.push(g);Array.prototype.splice.apply(i,y)}}}return i},hooks:{all:{},add:function(e,n){var r=t.hooks.all;r[e]=r[e]||[];r[e].push(n)},run:function(e,n){var r=t.hooks.all[e];if(!r||!r.length)return;for(var i=0,s;s=r[i++];)s(n)}}},n=t.Token=function(e,t){this.type=e;this.content=t};n.stringify=function(e){if(typeof e=="string")return e;if(Object.prototype.toString.call(e)=="[object Array]")return e.map(n.stringify).join("");var r={type:e.type,content:n.stringify(e.content),tag:"span",classes:["token",e.type],attributes:{}};r.type=="comment"&&(r.attributes.spellcheck="true");t.hooks.run("wrap",r);var i="";for(var s in r.attributes)i+=s+'="'+(r.attributes[s]||"")+'"';return"<"+r.tag+' class="'+r.classes.join(" ")+'" '+i+">"+r.content+""};if(!self.document){self.addEventListener("message",function(e){var n=JSON.parse(e.data),r=n.language,i=n.code;self.postMessage(JSON.stringify(t.tokenize(i,t.languages[r])));self.close()},!1);return}var r=document.getElementsByTagName("script");r=r[r.length-1];if(r){t.filename=r.src;document.addEventListener&&!r.hasAttribute("data-manual")&&document.addEventListener("DOMContentLoaded",t.highlightAll)}})();; 18 | Prism.languages.css={comment:/\/\*[\w\W]*?\*\//g,atrule:/@[\w-]+?(\s+[^;{]+)?(?=\s*{|\s*;)/gi,url:/url\((["']?).*?\1\)/gi,selector:/[^\{\}\s][^\{\}]*(?=\s*\{)/g,property:/(\b|\B)[a-z-]+(?=\s*:)/ig,string:/("|')(\\?.)*?\1/g,important:/\B!important\b/gi,ignore:/&(lt|gt|amp);/gi,punctuation:/[\{\};:]/g};Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{style:{pattern:/(<|<)style[\w\W]*?(>|>)[\w\W]*?(<|<)\/style(>|>)/ig,inside:{tag:{pattern:/(<|<)style[\w\W]*?(>|>)|(<|<)\/style(>|>)/ig,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.css}}}); 19 | 20 | var prismStyle = document.createElement('style'); 21 | var beautified = cssbeautify(document.body.textContent, {autosemicolon: true}); 22 | var highlighted = Prism.highlight(beautified, Prism.languages.css); 23 | 24 | prismStyle.textContent = 'code[class*="language-"],pre[class*="language-"]{color:black;text-shadow:0 1px white;font-family:Consolas,Monaco,\'Andale Mono\',monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;}@media print{code[class*="language-"],pre[class*="language-"]{text-shadow:none;}}pre[class*="language-"]{padding:1em;margin:.5em 0;overflow:auto;}:not(pre) > code[class*="language-"],pre[class*="language-"]{background:#f5f2f0;}:not(pre) > code[class*="language-"]{padding:.1em;border-radius:.3em;}.token.comment,.token.prolog,.token.doctype,.token.cdata{color:slategray;}.token.punctuation{color:#999;}.namespace{opacity:.7;}.token.property,.token.tag,.token.boolean,.token.number{color:#905;}.token.selector,.token.attr-name,.token.string{color:#690;}.token.operator,.token.entity,.token.url,.language-css .token.string,.style .token.string{color:#a67f59;background:hsla(0,0%,100%,.5);}.token.atrule,.token.attr-value,.token.keyword{color:#07a;}.token.regex,.token.important{color:#e90;}.token.important{font-weight:bold;}.token.entity{cursor:help;}'; 25 | 26 | document.head.innerHTML = ''; 27 | document.head.appendChild(prismStyle); 28 | document.body.innerHTML = '
' + highlighted + '
'; 29 | 30 | })(); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cssprettifier-bookmarklet 2 | ========================= 3 | A convenient bookmarklet for unminifying and prettifying CSS in the browser. 4 | 5 | Also available as a [UserScript](https://github.com/sindresorhus/cssprettifier-userscript) by [Sindre Sorhus](http://sindresorhus.com) or an existing DevTools [extension](https://chrome.google.com/webstore/detail/prettyprint/nipdlgebaanapcphbcidpmmmkcecpkhg/details) 6 | by [Gildas Lormeau](https://github.com/gildas-lormeau/). 7 | 8 | 9 | 10 | Tested in Chrome stable, canary channels. 11 | 12 | # Uses 13 | 14 | * [cssbeautifier](http://senchalabs.github.com/cssbeautify/) 15 | * [Prism](http://prismjs.com/) 16 | 17 | # Usage 18 | 19 | View Source -> run the bookmarklet or alternatively use it as a [DevTools snippet](http://bgrins.github.io/devtools-snippets/#cssprettifier). 20 | 21 | # Installation 22 | 23 | Get it now. Copy/paste: 24 | 25 | ```javascript 26 | javascript:(function(){(function(){function a(a,b){function s(a){return" "===a||"\n"===a||" "===a||"\r"===a||"\f"===a}function t(a){return"'"===a||'"'===a}function u(a){return h>="a"&&"z">=h||h>="A"&&"Z">=h||h>="0"&&"9">=h||"-_*.:#".indexOf(a)>=0}function v(){var a;for(a=m;a>0;a-=1)g+=c.indent}function w(){g=r(g),p?g+=" {":(g+="\n",v(),g+="{"),"\n"!==i&&(g+="\n"),m+=1}function x(){var a;m-=1,g=r(g),q&&(a=g.charAt(g.length-1),";"!==a&&"{"!==a&&(g+=";")),g+="\n",v(),g+="}",f.push(g),g=""}var c,f,h,i,j,k,l,m,n,o,r,d=0,e=a.length,g="",p=!0,q=!1;for(c=arguments.length>1?b:{},c.indent===void 0&&(c.indent=" "),"string"==typeof c.openbrace&&(p="end-of-line"===c.openbrace),"boolean"==typeof c.autosemicolon&&(q=c.autosemicolon),r=String.prototype.trimRight?function(a){return a.trimRight()}:function(a){return a.replace(/\s+$/,"")},l={Start:0,AtRule:1,Block:2,Selector:3,Ruleset:4,Property:5,Separator:6,Expression:7,URL:8},m=0,k=l.Start,o=!1,f=[],a=a.replace(/\r\n/g,"\n");e>d;)if(h=a.charAt(d),i=a.charAt(d+1),d+=1,t(n))g+=h,h===n&&(n=null),"\\"===h&&i===n&&(g+=i,d+=1);else if(t(h))g+=h,n=h;else if(o)g+=h,"*"===h&&"/"===i&&(o=!1,g+=i,d+=1);else if("/"!==h||"*"!==i){if(k===l.Start){if(0===f.length&&s(h)&&0===g.length)continue;if(" ">=h||h.charCodeAt(0)>=128){k=l.Start,g+=h;continue}if(u(h)||"["===h||"@"===h){if(j=r(g),0===j.length)f.length>0&&(g="\n\n");else if("}"===j.charAt(j.length-1)||";"===j.charAt(j.length-1))g=j+"\n\n";else for(;;){if(i=g.charAt(g.length-1)," "!==i&&9!==i.charCodeAt(0))break;g=g.substr(0,g.length-1)}g+=h,k="@"===h?l.AtRule:l.Selector;continue}}if(k!==l.AtRule)if(k!==l.Block)if(k!==l.Selector)if(k!==l.Ruleset)if(k!==l.Property)if(k!==l.Separator)if(k!==l.Expression)k===l.URL&&")"===h&&g.charAt("\\"!==g.length-1)?(g+=h,k=l.Expression):g+=h;else{if("}"===h){x(),k=l.Start,m>0&&(k=l.Block);continue}if(";"===h){g=r(g),g+=";\n",k=l.Ruleset;continue}if(g+=h,"("===h&&"l"===g.charAt(g.length-2)&&"r"===g.charAt(g.length-3)&&"u"===g.charAt(g.length-4)){k=l.URL;continue}}else{if(!s(h)){g+=h,k=l.Expression;continue}t(i)&&(k=l.Expression)}else{if(":"===h){g=r(g),g+=": ",k=l.Expression,s(i)&&(k=l.Separator);continue}if("}"===h){x(),k=l.Start,m>0&&(k=l.Block);continue}g+=h}else{if("}"===h){x(),k=l.Start,m>0&&(k=l.Block);continue}if("\n"===h){g=r(g),g+="\n";continue}if(!s(h)){g=r(g),g+="\n",v(),g+=h,k=l.Property;continue}g+=h}else{if("{"===h){w(),k=l.Ruleset;continue}if("}"===h){x(),k=l.Start;continue}g+=h}else{if(u(h)){if(j=r(g),0===j.length)f.length>0&&(g="\n\n");else if("}"===j.charAt(j.length-1))g=j+"\n\n";else for(;;){if(i=g.charAt(g.length-1)," "!==i&&9!==i.charCodeAt(0))break;g=g.substr(0,g.length-1)}v(),g+=h,k=l.Selector;continue}if("}"===h){x(),k=l.Start;continue}g+=h}else{if(";"===h){g+=h,k=l.Start;continue}if("{"===h){j=r(g),w(),k="@font-face"===j?l.Ruleset:l.Block;continue}g+=h}}else o=!0,g+=h,g+=i,d+=1;return g=f.join("")+g}"undefined"!=typeof exports?module.exports=exports=a:"object"==typeof window&&(window.cssbeautify=a)})();(function(){var e=/\blang(?:uage)?-(?!\*)(\w+)\b/i,t=self.Prism={util:{type:function(e){return Object.prototype.toString.call(e).match(/\[object (\w+)\]/)[1]},clone:function(e){var n=t.util.type(e);switch(n){case "Object":var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=t.util.clone(e[i]));return r;case "Array":return e.slice()}return e}},languages:{extend:function(e,n){var r=t.util.clone(t.languages[e]);for(var i in n)r[i]=n[i];return r},insertBefore:function(e,n,r,i){i=i||t.languages;var s=i[e],o={};for(var u in s)if(s.hasOwnProperty(u)){if(u==n)for(var a in r)r.hasOwnProperty(a)&&(o[a]=r[a]);o[u]=s[u]}return i[e]=o},DFS:function(e,n){for(var r in e){n.call(e,r,e[r]);t.util.type(e)==="Object"&&t.languages.DFS(e[r],n)}}},highlightAll:function(e,n){var r=document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');for(var i=0,s;s=r[i++];)t.highlightElement(s,e===!0,n)},highlightElement:function(r,i,s){var o,u,a=r;while(a&&!e.test(a.className))a=a.parentNode;if(a){o=(a.className.match(e)||[,""])[1];u=t.languages[o]}if(!u)return;r.className=r.className.replace(e,"").replace(/\s+/g," ")+" language-"+o;a=r.parentNode;/pre/i.test(a.nodeName)&&(a.className=a.className.replace(e,"").replace(/\s+/g," ")+" language-"+o);var f=r.textContent;if(!f)return;f=f.replace(/&/g,"&").replace(//g,">").replace(/\u00a0/g," ");var l={element:r,language:o,grammar:u,code:f};t.hooks.run("before-highlight",l);if(i&&self.Worker){var c=new Worker(t.filename);c.onmessage=function(e){l.highlightedCode=n.stringify(JSON.parse(e.data));l.element.innerHTML=l.highlightedCode;s&&s.call(l.element);t.hooks.run("after-highlight",l)};c.postMessage(JSON.stringify({language:l.language,code:l.code}))}else{l.highlightedCode=t.highlight(l.code,l.grammar);l.element.innerHTML=l.highlightedCode;s&&s.call(r);t.hooks.run("after-highlight",l)}},highlight:function(e,r){return n.stringify(t.tokenize(e,r))},tokenize:function(e,n){var r=t.Token,i=[e],s=n.rest;if(s){for(var o in s)n[o]=s[o];delete n.rest}e:for(var o in n){if(!n.hasOwnProperty(o)||!n[o])continue;var u=n[o],a=u.inside,f=!!u.lookbehind||0;u=u.pattern||u;for(var l=0;le.length)break e;if(c instanceof r)continue;u.lastIndex=0;var h=u.exec(c);if(h){f&&(f=h[1].length);var p=h.index-1+f,h=h[0].slice(f),d=h.length,v=p+d,m=c.slice(0,p+1),g=c.slice(v+1),y=[l,1];m&&y.push(m);var b=new r(o,a?t.tokenize(h,a):h);y.push(b);g&&y.push(g);Array.prototype.splice.apply(i,y)}}}return i},hooks:{all:{},add:function(e,n){var r=t.hooks.all;r[e]=r[e]||[];r[e].push(n)},run:function(e,n){var r=t.hooks.all[e];if(!r||!r.length)return;for(var i=0,s;s=r[i++];)s(n)}}},n=t.Token=function(e,t){this.type=e;this.content=t};n.stringify=function(e){if(typeof e=="string")return e;if(Object.prototype.toString.call(e)=="[object Array]")return e.map(n.stringify).join("");var r={type:e.type,content:n.stringify(e.content),tag:"span",classes:["token",e.type],attributes:{}};r.type=="comment"&&(r.attributes.spellcheck="true");t.hooks.run("wrap",r);var i="";for(var s in r.attributes)i+=s+'="'+(r.attributes[s]||"")+'"';return"<"+r.tag+' class="'+r.classes.join(" ")+'" '+i+">"+r.content+""};if(!self.document){self.addEventListener("message",function(e){var n=JSON.parse(e.data),r=n.language,i=n.code;self.postMessage(JSON.stringify(t.tokenize(i,t.languages[r])));self.close()},!1);return}var r=document.getElementsByTagName("script");r=r[r.length-1];if(r){t.filename=r.src;document.addEventListener&&!r.hasAttribute("data-manual")&&document.addEventListener("DOMContentLoaded",t.highlightAll)}})();Prism.languages.css={comment:/\/\*[\w\W]*?\*\//g,atrule:/@[\w-]+?(\s+[^;{]+)?(?=\s*{|\s*;)/gi,url:/url\((["']?).*?\1\)/gi,selector:/[^\{\}\s][^\{\}]*(?=\s*\{)/g,property:/(\b|\B)[a-z-]+(?=\s*:)/ig,string:/("|')(\\?.)*?\1/g,important:/\B!important\b/gi,ignore:/&(lt|gt|amp);/gi,punctuation:/[\{\};:]/g};Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{style:{pattern:/(<|<)style[\w\W]*?(>|>)[\w\W]*?(<|<)\/style(>|>)/ig,inside:{tag:{pattern:/(<|<)style[\w\W]*?(>|>)|(<|<)\/style(>|>)/ig,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.css}}});var prismStyle=document.createElement("style");var beautified=cssbeautify(document.body.textContent,{autosemicolon:true});var highlighted=Prism.highlight(beautified,Prism.languages.css);prismStyle.textContent='code[class*="language-"],pre[class*="language-"]{color:black;text-shadow:0 1px white;font-family:Consolas,Monaco,\'Andale Mono\',monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;}@media print{code[class*="language-"],pre[class*="language-"]{text-shadow:none;}}pre[class*="language-"]{padding:1em;margin:.5em 0;overflow:auto;}:not(pre) > code[class*="language-"],pre[class*="language-"]{background:#f5f2f0;}:not(pre) > code[class*="language-"]{padding:.1em;border-radius:.3em;}.token.comment,.token.prolog,.token.doctype,.token.cdata{color:slategray;}.token.punctuation{color:#999;}.namespace{opacity:.7;}.token.property,.token.tag,.token.boolean,.token.number{color:#905;}.token.selector,.token.attr-name,.token.string{color:#690;}.token.operator,.token.entity,.token.url,.language-css .token.string,.style .token.string{color:#a67f59;background:hsla(0,0%,100%,.5);}.token.atrule,.token.attr-value,.token.keyword{color:#07a;}.token.regex,.token.important{color:#e90;}.token.important{font-weight:bold;}.token.entity{cursor:help;}';document.head.innerHTML="";document.head.appendChild(prismStyle);document.body.innerHTML="
"+highlighted+"
"})(); 27 | ``` 28 | 29 | or [use this](https://raw.github.com/addyosmani/cssprettifier-bookmarklet/master/dist/bookmarklet.md). 30 | 31 | 32 | ### Before 33 | 34 | ```css 35 | .callout{margin:15px 0;padding:10px;font-size:13px;color:#8d8d6d;background:#fffef1;border:1px solid #e5e2c8;border-radius:4px;}.callout strong{font-weight:bold;color:#000;}.callout h2{margin:0;font-size:16px;font-weight:300;}.callout p:last-child{margin-bottom:0;} 36 | ``` 37 | 38 | ### After 39 | 40 | ```css 41 | .callout { 42 | margin: 15px 0; 43 | padding: 10px; 44 | font-size: 13px; 45 | color: #8d8d6d; 46 | background: #fffef1; 47 | border: 1px solid #e5e2c8; 48 | border-radius: 4px; 49 | } 50 | 51 | .callout strong { 52 | font-weight: bold; 53 | color: #000; 54 | } 55 | 56 | .callout h2 { 57 | margin: 0; 58 | font-size: 16px; 59 | font-weight: 300; 60 | } 61 | 62 | .callout p:last-child { 63 | margin-bottom: 0; 64 | } 65 | ``` 66 | 67 | 68 | # License 69 | 70 | [MIT License](http://en.wikipedia.org/wiki/MIT_License) 71 | (c) [Addy Osmani](http://addyosmani.com) and [Sindre Sorhus](http://sindresorhus.com) 72 | --------------------------------------------------------------------------------