There's markitup which has an example of it being used as a Markdown editor. I have used for a couple of internal projects and it is not bad. Plus the code is simple really and you can easily modify it to suit your needs.
I would use Markdown (reddit uses a customized version of this). It has a safe mode that will strip raw HTML tags. If you need a WSIWYG editor for your Markdown, try MarkItUp!.
If you really want to accept HTML from your untrusted users, run it through the HTMLSanitizer in html5lib.