Skip to content

Commit

Permalink
Remove <style> elements
Browse files Browse the repository at this point in the history
  • Loading branch information
zarathustra323 committed Apr 9, 2019
1 parent 218924e commit 4a536e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rules/pennwell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ To access, send a `POST` request to `/pennwell/default`. This rule set performs
- Extracts the `deck` text from elements classed with `.paraStyle_headline_deck` and removes the element from the cleaned HTML.
- Extracts an `author` object from elements classed with `.paraStyle_byline` or `.paraStyle_body_bio` and removes the elements from the cleaned HTML.
- If an `<h1>` is detected anywhere in the body, all heading elements are increased by one (e.g. `<h1>` becomes `<h2>`, `<h2>` becomes `<h3>`, etc).
- Removes all `<form>` elements.
- Removes all `<form>` and `<style>` elements.
- Removes all `id`, `class`, `style` and `data-*` attributes from elements.
- Removes PennNet.com iframe embeds, e.g. where `iframe[src*="pennnet.com"]`.

Expand Down
2 changes: 1 addition & 1 deletion src/rules/pennwell/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = async (body) => {
adjustHeadings($);

// Remove form elements.
removeElements($, 'form');
removeElements($, 'form, style');

// Remove buyer's guide iframe search embeds.
removeElements($, 'iframe[src*="pennnet.com"]');
Expand Down
14 changes: 14 additions & 0 deletions test/rules/pennwell/default.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ describe('rules/pennwell/default', () => {
const result = await rule(body);
expect(result.html.cleaned).to.equal('<div></div><p>Foo</p>');
});
it('should remove <style> elements.', async () => {
const body = `
<div>
<style>
body {
color: red;
}
</style>
</div>
<p>Foo</p>
`;
const result = await rule(body);
expect(result.html.cleaned).to.equal('<div></div><p>Foo</p>');
});
it('should remove <iframe> elements with a src containing pennnet.com.', async () => {
const body = `
<div>
Expand Down

0 comments on commit 4a536e1

Please sign in to comment.