I'm looking for a way to check a string containing html and decide if it contains any text that should be visible, not counting whitespaces.
Basically anything should count as visible if it shows up as visible text upon rendering it as the innerHTML
of a <div>
.
For example
<div>hello</div>
is visible, as "hello" is shown in the browser.<div><p> <br/></div>
is not visible.<script>alert('asdf')</script>
is not visible.plain text
is visible, although it does not contain any html tags.
There are a lot of cases where I'm not sure (any result would be acceptable):
<div style="display: none">this is tricky</div>
is not visible, but since css adds an other layer of complexity to the question, it might be a good idea not to bother with it.<script>document.write('What is this, I don't even-')</script>
should be outside the scope of this question.<input value="Read this">
is visible, but I don't care about form elements at the moment, so this might as well be not visible.
I want to decide this server-side and deal with the situation accordingly.
Is there a good way to decide this in C#? Writing my own solution seems tedious, and I was wondering if someone already did this (or something similar).
EDIT:
Is the question this incomprehensible? I already stated that I want to do it on the server, not in a browser environment. jQuery and jsfiddle have little relevance here.