For Markdown -> HTML, there is Showdown StackOverflow itself uses Markdown language for questions and answers ; did you try to take a look at how it works ? Well, it seems it is using PageDown which is available under the MIT License The question Is there any good Markdown Javascript library or control? and its answers might help, too :-) A full editor is, of course, not exactly what you asked for
![Javascript to convert Markdown/Textile to HTML (and, ideally, back to Markdown/Textile)](https://cdn-ak-scissors.b.st-hatena.com/image/square/98d6f053a97a87156775f60757c60865d0f2c47d/height=288;version=1;width=512/https%3A%2F%2Fcdn.sstatic.net%2FSites%2Fstackoverflow%2FImg%2Fapple-touch-icon%402.png%3Fv%3D73d79a89bded)