With this blog post, it’s possible to format any xml you’ve selected.
It will take about 5 minutes to get this working, a couple of manual steps are necessary.
These are the tools being used:
- AutoHotKey_L
- Tidy for Windows (click here for more information about tidy)
Steps to get it working: (All steps are necessary!)
- First install AutoHotKey_L and start it, you’ll see the logo if it’s running:
- Create a folder on your Hard Drive called “C:\autohotkey”
- Create a file “tidycfg.ini” in the location “C:\autohotkey\tidycfg.ini” with the following contents:
-
[Clean Indent XML] input-xml: yes bare:no clean:no fix-bad-comments:no fix-backslash:no indent:yes indent-attributes:no indent-spaces:4 char-encoding:raw replace-color:no wrap:0 wrap-asp:no wrap-jste:no wrap-php:no write-back:yes
-
- Place tidy.exe in the location C:\autohotkey
- Create a file called “autohotkey.ahk” in C:\autohotkey with the following contents:
-
#x:: sleep 50 Send ^c ClipWait clipboard = %clipboard% FileDelete, C:\autohotkey\format_with_tidy.xml FileAppend, %clipboard%, C:\autohotkey\format_with_tidy.xml sleep 50 RunWait, %comspec% /c C:\autohotkey\tidy.exe -config C:\autohotkey\tidycfg.ini C:\autohotkey\format_with_tidy.xml clipboard = FileRead, clipboard, C:\autohotkey\format_with_tidy.xml Return
-
- Doubleclick the file “autohotkey.ahk” in C:\autohotkey
- Select unformatted xml and press [ WINKEY+X ]
- The formatted xml is now in your clipboard and can be pasted anywhere.
Extra information:
These are the steps what is happening in the autohotkey file:
- Configure the keyboard shortcut (# = winkey, x = x-key)
- Wait 50 milliseconds
- Send the ctrl-c with keyboard combination ^c ( ^ = ctrl, c = c-key)
- Wait until the clipboard is filled
- remove all formatting from the clipboard
- Delete the temporary file (if present)
- Paste the clipboard contents in the temporary file
- Wait 50 milliseconds
- Run tidy.exe on the temporary file with the configuration settings
- empty the clipboard
- Paste the contents of the temporary file in the clipboard
- End script
Thank you !!!
Thanks, this is the only post I found that describes how to use Tidy with AHK! I implemented it in this script (https://autohotkey.com/board/topic/4310-capshift-slow-down-and-extend-the-caps-lock-key) which has a lot of other string replacement options, and is easily extended.
Thanks Inge! I might change out my script with yours 🙂