I’ve allowed users to use <pre></pre> tags to display code in comments and articles, but I’ve come across a problem that I’m struggling to solve. When a user fails to close an HTML tag, for example:
<pre>
<html>
<head>
</head>
</pre>
the comment appears to be blank. What I’m looking for is some sort of function that will automatically close any HTML tags that the user missed.
Thanks in advance.
Well it’s going to get nasty if you dont use a framework but your courage is admired. Hopefully this will be a nudge in the right direction.
The simplest, non-framework solution I can think of is using a stack to push and pop tags while parsing the string from the user.
pseudo code
This is by no means comprehensive and a framework is really recommended here, but hopefully it can help out a bit.