Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Strip out white space text nodes #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RacingTadpole
Copy link

Fixes #30 ("Should not insert spans into tables even if there is white space") by stripping out all white-space text nodes.

This changes non-table nodes too, e.g.:
<div> </div> into <div></div>
<div> <span>hi</span>bye</div> into <div><span>hi</span>bye</div>.

I'm not sure if that is desirable. If it's not, is there a better solution?

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.1%) to 98.876% when pulling a44d4ef on TerriaJS:tablespan into 3bf4bd4 on mikenikles:master.

@aknuds1
Copy link
Collaborator

aknuds1 commented Jun 27, 2016

Might this PR be unnecessary as #30 is already closed?

Copy link
Collaborator

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like input from others as to whether this whitespace removal is a good idea.

@@ -101,6 +101,47 @@ describe('Html2React', function() {

assert.equal(reactHtml, htmlExpected);
});

it('should not insert spans into tables even if there is white space', function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, this test doesn't add anything except verify that whitespace text nodes are stripped.

});

// Should it strip out contents of a div containing only white space?
it('should strip out contents of a div containing only white space', function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we actually remove text nodes that are whitespace only? The comment seems to indicate the PR author isn't sure either.

});

// Should it strip out white space that is a sibling to an element?
it('should strip out white space that is a sibling to an element', function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make any semantic difference compared to just stripping whitespace text nodes?

@aknuds1
Copy link
Collaborator

aknuds1 commented Sep 18, 2016

Could it be better to leave to some HTML tidying library to handle concerns such as unnecessary whitespace, which this PR addresses?

@RacingTadpole
Copy link
Author

Thanks @aknuds1 - I agree, this feels like too heavy a solution to the problem. I like your idea of leaving it to another library to deal with this.

Is it a worry that the test in #30 passes but still produces a warning that a span has been introduced? This may be a spurious comparison, but eg.

<div dangerouslySetInnerHTML={{__html: '<table><tbody> <tr><td>x</td><td>3</td></tr></tbody></table>'}} />

doesn't produce a warning.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants