You may have to try another text application if no apparent shortcuts or scripts to semi-automate seem workable in TextEdit; a different approach may be TextWrangler, or others that have seen transition to the current OS X version. Other great third-party applications did not survive to make the transition further into OS X.
There is this TextEdit tidbit, that ultimately suggests
using the system's Help viewer to learn more...
•Mac Basics: TextEdit
•Mac OS X: How to set up TextEdit as HTML or Plain Text Editor:
AppleScript editor is a way of making automated repeatable commands available with shortcuts. There also is Automator workflows, in the OS X. These can be used to perform a variety of tasks.
•Automator for Mac OS X: Tutorial and examples:
Sometimes you can find third-party tutorials online, where some apple user group or school has uploaded or put their concept on a web site. However an older TextEdit premise from several OS X systems ago, may not work the same in the recent OS X. With those dated concepts, one can only test them to see if they are still valid. And there is X Code... tons of learning among the choices built into the Mac OS X, too.
My trouble is that I've been too imaginative, took a scientist to explain algebra
and only then could I pass it with an A. But not for long, as it was a step down.
Good luck & happy computing!