I’m using Asp.net., Assuming I’m allowing user to post messages in my site with HTML tags. How do I ensure he has properly closed all the tags? Is there any HTML-tag-checker available that tries to parse tags and report errors if any? May be just like the BLOGGER has.
Share
You could easily parse the text yourself. Define a list of tags that are allowed that require closing (strong, em, etc.). Parse the code and take each HTML tag as a token and push it on to a stack. When a closing tag is found, peek at the top item and if it is not the complement to the found closing tag, the HTML is improperly nested.
Assuming paired tags/closing tags are removed from the stack, the residual elements are the tags which are started but not completed. This is only a rudimentary approach, but it may only be a few lines of code to identify improperly nested tags or unclosed tags.