Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module for replacing empty nodes by containing tags #4

Merged

Conversation

Minstel
Copy link
Contributor

@Minstel Minstel commented Feb 9, 2017

No description provided.

@Minstel Minstel force-pushed the 1-Remove_tags_with_only_section_tags branch from dc337f6 to 6cb093b Compare February 9, 2017 16:17
@@ -0,0 +1,289 @@
var tidy = require('../');

describe('Replacing empty dom nodes with containing tags', function() {
Copy link
Member

Choose a reason for hiding this comment

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

Please also add tests for common cases

<p>{{#tag}}</p>
<p>Hello world</p>
<p>{{/tag}}</p>

should become {{#tag}}<p>Hello world</p>{{/tag}}

and

<p>{{#tag}}</p>
<p>Hello world</p>
<p>{{/tag}} {{^tag}}</p>
<p>Good night</p>
<p>{{/tag}}</p>

should become {{#tag}}<p>Hello world</p>{{/tag}} {{^tag}}<p>Good night</p>{{/tag}}

scripts/utils.js Outdated
ProcessExternalResources: false
};

var Node = require('../node_modules/jsdom/lib/jsdom/living/generated/Node.js');
Copy link
Member

Choose a reason for hiding this comment

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

Can't you use require('jsdom/lib/jsdom/living/generated/Node.js')?

@Minstel Minstel force-pushed the 1-Remove_tags_with_only_section_tags branch from eea6520 to 2dc790c Compare February 10, 2017 10:15
@Minstel
Copy link
Contributor Author

Minstel commented Feb 10, 2017

<p>{{#tag}}</p>
<p>Hello world</p>
<p>{{/tag}} {{^tag}}</p>
<p>Good night</p>
<p>{{/tag}}</p>

To correctly handle <p>{{/tag}} {{^tag}}</p>, second step (moving tags) is required, when closing tag is first moved out of node. Currently replacing nodes hanles the following cases:

  • <p>{{#tag}}</p>
  • <p>{{/tag}}</p>
  • <p>{{^tag}} {{/tag}}</p>

This is related to current algo - while handling current tags section, it does not look for sibling tags (for better performance), and just consideres them as some data.
I did corresponding change to readme.

@jasny
Copy link
Member

jasny commented Feb 10, 2017

@Minstel You should treat {{^tag}} exactly the same as {{#tag}}. A ^ just means 'not'.

If a <p> contains only start and/or end tags, than remove <p>. It doesn't order or number of start tags doesn't matter. Doing step 2 without removing this, means we'll end up with empty paragraphs.

@jasny jasny merged commit 68a3d16 into legalthings:master Feb 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants