Have a look at this post where a very simple parser is explained: http://silverstripe.org/general-questions/show/260299
Or here for a slightly more complex parser: http://doc.silverstripe.com/doku.php?id=recipes:syntax-highlighting
But mind you, this won't be a simple task if you want to be sure you always end up having valid html. Probably the best approach would be to build some finite state machine that runs through the content and makes sure, opened tags get closed again...
Update: You could also write a custom method for this in the blog controller (like you mentioned in your previous post). The TextParser is a more generic approach though. TextParsers can be used on any "Text" or "HTMLText" Datafield.