What's happening in your case is that the HTML is being escaped and is therefore rendered as text.
I don't know what language you are writing in but I suspect you used the built-in text escape function. This will render the HTML as text however, this will not make it safe.
I suspect that what you are looking for is a solution that will:
- Parse the HTML and sanitize it to remove any potentially malicious tags such as JavaScript, external references, iframes etc.
- Store this sanitized HTML.
- Render the input as part of the page.
StackExchange supports only a sctrict subset of HTML, you may want to emulate the approach taken.
This is not a simple problem to solve and you will most likely want to find some framework that will do this for you than rolling your own.
For example, some exploits that someone may want to attempt against your system:
- Additional
</div>
tags to escape the wrapping element.
- Some character combination that may not look like valid HTML but behaves as such anyway.
- Utilizing some Javascript that you already have on your page.
- Adding CSS to break the page layout.
Foo
` or do you want to include the HTML in the page (so that the abobe would be presented as a heading "Foo")? It's not clear – Adam Apr 18 '14 at 22:50