I am rendering a text file on webpage inside <pre> tags. Right now i have encoded the input file so that < is encoded as < and > as >. But the problem comes when text file has valid html tags like <a href=......>hello</a>. In this case even the html tags are displayed as plain text not html elements. Is there a reliable way to display html elements as it is while escaping the invalid tags?
Asked
Active
Viewed 86 times
0
Michael Benjamin
- 307,417
- 93
- 525
- 644
Saurav Prakash
- 1,751
- 1
- 10
- 21
-
could u please show what u tried so far – Shailendra Sharma Dec 03 '15 at 13:25
-
I just tried to render the text file contents of format ,say, Map <String,Int> blah blah <a href=.....>....now hen being rendered,the a tag is displayed as plain text and not html – Saurav Prakash Dec 03 '15 at 13:28
-
http://stackoverflow.com/questions/5499078/fastest-method-to-escape-html-tags-as-html-entities – Shailendra Sharma Dec 03 '15 at 13:32
-
If you have HTML with plain < characters in it, technically that's broken HTML. You should simply fix that at the source instead of trying to partially escape it after the fact. – deceze Dec 03 '15 at 14:47
-
Do you know what you want to display and what you don't want? Is this input that comes from another source (such as the user)? It sounds like you're either trying to allow a small subset of HTML (where, for example, `` is OK, but ` – Mr Lister Dec 08 '15 at 07:37