-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from bustlelabs/skip-style-nodes
ensure style tags are skipped when parsing HTML/dom
- Loading branch information
Showing
4 changed files
with
50 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import HTMLParser from 'mobiledoc-kit/parsers/html'; | ||
import PostNodeBuilder from 'mobiledoc-kit/models/post-node-builder'; | ||
import Helpers from '../../test-helpers'; | ||
|
||
const {module, test} = Helpers; | ||
|
||
function parseHTML(html, options={}) { | ||
let builder = new PostNodeBuilder(); | ||
return new HTMLParser(builder, options).parse(html); | ||
} | ||
|
||
module('Unit: Parser: HTMLParser'); | ||
|
||
test('style tags are ignored', (assert) => { | ||
// This is the html you get when copying a message from Slack's desktop app | ||
let html = `<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Style-Type" content="text/css"> <title></title> <meta name="Generator" content="Cocoa HTML Writer"> <meta name="CocoaVersion" content="1348.17"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Times; color: #2c2d30; -webkit-text-stroke: #2c2d30; background-color: #f9f9f9} span.s1 {font-kerning: none} </style> </head> <body> <p class="p1"><span class="s1">cool</span></p> </body> </html>`; | ||
let post = parseHTML(html); | ||
|
||
let expected = Helpers.postAbstract.build( | ||
({post, markupSection, marker}) => { | ||
return post([markupSection('p', [marker('cool')])]); | ||
}); | ||
|
||
assert.postIsSimilar(post, expected); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters