The magic behind the formatting on StackExchange is a great perl script called Markdown. Download it, and double-click the resulting Markdown_1.0.1.zip file.
Then, in terminal, type
chmod a+x ~/Downloads/Markdown_1.0.1/Markdown.pl
sudo cp ~/Downloads/Markdown_1.0.1/Markdown.pl /usr/local/bin/
Once you have that done, you can create a Service in Automator.
The service you create receives rich text in any application.
Uncheck the box that says Output replaces selected text.
Your service will contain two actions:
The first action is Run Shell Script.
Here is the shell script:
/usr/local/bin/Markdown.pl | /usr/bin/textutil -stdin -stdout -format html -convert rtf | /usr/bin/pbcopy
Your section action is Run AppleScript.
Here is the AppleScript:
tell application "System Events"
keystroke "v" using {command down}
end tell
Save the service, and, if you wish, assign it a keyboard shortcut using System Preferences » Keyboard » Keyboard Shortcuts » Services
Then, you can type text using the formatting codes you use on this site, and run this service to generate formatted text. This will only work if your mail messages are set up as Rich Text -- if you have plain text mail messages, running this service will simply erase the contents of your message, as your rich text formatted by the service will not be able to be pasted.
Best Answer
Macs come with
libxml2
which inclues a tool calledxmllint
. You can use this to format your xml with ease. The tool does not have a graphical interface, so you'll need to fire up terminal.Example 1. Format a file
Example 2. Format xml from clipboard