21

I'm using TextWrangler on Mac OS X to do some web development. Is there a way to auto format code?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
dev.e.loper
  • 35,446
  • 76
  • 161
  • 247
  • 4
    I got tired of scripts/filters for every language in TextWrangler - TextMate does this out of the box so I switched to that. – josh-cain Jul 12 '13 at 13:15

2 Answers2

8

Yes, there is a possibility but not a simple one. Using Text Filters, if you can find a filter your choice you put it into Library/Application Support/TextWrangler/Text Filters and reach it from Text/Apply Text Filter menu.

This is how you do it for XML: http://magp.ie/2010/02/15/format-xml-with-textwrangler/

and for PHP: http://wizguild.com/textwrangler_phptidy_filter/

Sam
  • 166
  • 2
  • 3
  • 2
    can't find the folder Library/Application Support/TextWrangler on my mac os x 10.8 – AmineG Jul 21 '13 at 17:28
  • Hey @someone0 - you can create the folder yourself and then just restart the app. OSX is so much harder than Windows...'it just works' is a pile of sh**! It just works if you know bash scripting and UNIX commands. :( – BrantApps Aug 24 '13 at 14:27
  • 1
    @someone0 In the case you can't see the Library folder: The Library folder is really there but hidden. Open your home folder in the Finder, from Go menu choose "Go to Folder..." and enter Library. I add it to the favourites on my systems. – Sam Sep 13 '13 at 13:43
  • 3
    to the gods of notepad++ hear the cry of mac users. We need you – Will Sep 19 '14 at 17:15
  • 1
    @someone0 In the view options for your home directory there is a checkbox to show the Library folder. – unclerojelio Oct 20 '15 at 15:07
  • @sam - Do you know of a Tidy script for Java? – tekNorah Oct 21 '15 at 18:17
2

Create a new file -> Tidy XML.sh

Copy and Paste this lines below:

#!/bin/sh XMLLINT_INDENT=$'\t' xmllint --format --encode utf-8 -

Save on Desktop

Open Finder and GO to folder -> ~/Library/Application Support/TextWrangler/Text Filters

Move your Tidy XML.sh from desktop to Text Filters.

Open TextWrangler and beautifier your xml file.

Gojira
  • 23
  • 4
  • I'm having trouble with this one. It keeps saying there are incomplete tags even though I copied the code straight from the pristine HTML source code produced from the browser's Developer Tools. – Spencer Williams Sep 22 '16 at 15:56
  • Okay, a little more success adding the --html flag, but all it does is wrap the code in an HTML and BODY tag and it is not indenting or aligning anything. It did warn me about duplicate id tags, which I appreciated, but I was hoping it would, you know, format the text... – Spencer Williams Sep 22 '16 at 16:46