Ever copy and paste code into a text editor and then realize you need to indent every line by four spaces to get it all escaped properly? Drive you crazy? Yeah, me too. I wrote a bookmarklet to take the currently selected text in a textarea input box and indent everything by four spaces. So you paste your code, select it, then click on this bookmarklet. I’ve only tested it on Chrome, so it might need slight modifications for other browsers. Here’s the source.

Ironically, markdown won’t let me create a link that has javascript in the href field, so I can’t post a link that you can simply drag to your bookmarks bar to install. Instead, right-click on the bookmarks bar and select “Add Page…” and paste this into the url field. ¬†Or duplicate an existing bookmark and edit the url setting to be this:

javascript:(function(){var d=document.activeElement,c=document.getSelection().toString(),a="",b=c.split("\n");indent="    ",i=0,total=b.length;if(c==""){return}for(i=0;i < total;i++){a+=indent+b[i]+"\n"}d.value=d.value.split(c).join(a)}());

Affinitive Dev Blog

Ramblings from the dev team at Affinitive, a word of mouth and social media marketing and technology solutions pioneer and Facebook Preferred Marketing Developer (PMD). Also see @Affinitive, @RMarscher, and @BobTroia.