p4ulypops / jquery-clean

Automatically exported from code.google.com/p/jquery-clean
0 stars 0 forks source link

Specifying allowEmpty is Inconvenient for Multiple Tags #41

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Take some arbitrary HTML
2. Use HTML Clean to format it with the option "allowEmpty: true"

What is the expected output? What do you see instead?

Expected: I would expect to see my HTML formatted, with none of it removed

Actual: All of the empty tags will be removed

Now, this could be solved by using "allowEmpty: arrayWithEveryHtmlTag" ... but 
that's an awfully hacky solution.

What version of the product are you using? On what operating system?
1.4.0, Chrome, Linux

Please provide any additional information below.

In general when people want to format their HTML, I think they want to ... 
well, format it, NOT delete arbitrary chunks of it.  This might just be me, but 
I suspect it's actually a very common, if not the most common use, case.  
Therefore, I think:

A) every allowed* option (allowedTags, allowedAttributes, allowedClasses, etc.) 
should take a "true" option (which would indicate "don't delete anything")
B) all of those options should default to true

Just one user's opinion ...

Original issue reported on code.google.com by machineg...@gmail.com on 16 Jan 2014 at 6:40

GoogleCodeExporter commented 9 years ago
The "allowEmpty: true" part of my request could be implemented with the 
following two changes:

Line 35 change to:
options.allowEmpty = options.allowEmpty === true ? true : 
tagAllowEmpty.concat(options.allowEmpty);

Line 429 change to:
this.allowEmpty = options && ((options.allowEmpty === true && this.name != 
'xxx') || $.inArray(this.name, options.allowEmpty) > -1);

Original comment by machineg...@gmail.com on 16 Jan 2014 at 6:52

GoogleCodeExporter commented 9 years ago
One more thought: while I (and I imagine others) use this tool as a formatter, 
the original intent of the library seems to be more about converting large 
chunks of hard-to-read HTML in to smaller chunks of easy to read HTML.

Given that, my suggestion "all of those options should default to true" might 
make more sense for a (new) secondary command.  In other words, what if there 
was .htmlClean, which works exactly as it does now (ie. it very greedily tries 
to remove irrelevant HTML), and then a new .htmlFormat, which doesn't remove 
anything, and just formats the HTML?

Just a thought.

Original comment by machineg...@gmail.com on 16 Jan 2014 at 8:55