chore: Inline test fixtures (#683)
Not to be confused with extractor fixtures, which are snapshots of a webpage. This change removes the pattern of separate JS files that provide "fixtures" for tests, which are used as provided or expected strings in tests. They were inconsistent and disorganized, and generally just served to add indirection to test files. So now all those strings are defined where they are used in their respective tests.feat-netease-extractor
parent
0d2bad544c
commit
112846f74f
@ -1,15 +0,0 @@
|
|||||||
const HTML = {
|
|
||||||
docWithH1: '<div><h1>This Is the Real Title</h1></div>',
|
|
||||||
docWith2H1s: `
|
|
||||||
<div>
|
|
||||||
<h1>This Is the Real Title</h1>
|
|
||||||
<h1>This Is the Real Title</h1>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
docWithTagsInH1: {
|
|
||||||
before: '<div><h1>This Is the <em>Real</em> Title</h1></div>',
|
|
||||||
after: 'This Is the Real Title',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default HTML;
|
|
@ -1,32 +0,0 @@
|
|||||||
const HTML = {
|
|
||||||
authorMeta: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<meta name="dc.author" value="Adam" />
|
|
||||||
</html>
|
|
||||||
`,
|
|
||||||
result: 'Adam',
|
|
||||||
},
|
|
||||||
authorSelectors: {
|
|
||||||
test: `
|
|
||||||
<div>
|
|
||||||
<div class="byline">
|
|
||||||
<a href="/author/adam">Adam</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
result: 'Adam',
|
|
||||||
},
|
|
||||||
authorRegSelectors: {
|
|
||||||
test: `
|
|
||||||
<div>
|
|
||||||
<div class="byline">
|
|
||||||
<span>By Adam</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
result: 'Adam',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default HTML;
|
|
@ -1,664 +0,0 @@
|
|||||||
const HTML = {
|
|
||||||
// getWeight fixtures
|
|
||||||
positiveId: `
|
|
||||||
<div id="entry">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
negativeId: `
|
|
||||||
<div id="adbox">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positiveClass: `
|
|
||||||
<div class="entry">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
negativeClass: `
|
|
||||||
<div id="comment ad">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positiveIdAndClass: `
|
|
||||||
<div id="article" class="entry">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positiveIdNegClass: `
|
|
||||||
<div id="article" class="adbox">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positivePhotoClass: `
|
|
||||||
<div class="figure">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positiveIdAndPhoto: `
|
|
||||||
<div id="article" class="figure">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
entryContentAsset: `
|
|
||||||
<div id="foo" class="entry-content-asset">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
|
|
||||||
// stripUnlikelyCandidates
|
|
||||||
noMatches: `
|
|
||||||
<div id="foo">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
whitelistMatch: {
|
|
||||||
before: `
|
|
||||||
<div class="header">Stuff</div>
|
|
||||||
<div class="article">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
whiteAndBlack: {
|
|
||||||
before: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
whiteInsideBlack: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<div class="adbox">
|
|
||||||
<div class="article">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>Something unrelated</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<div>Something unrelated</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// brsToPs
|
|
||||||
singleBr: {
|
|
||||||
before: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<br>
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<br>
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
doubleBrs: {
|
|
||||||
before: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<p> </p><p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
severalBrs: {
|
|
||||||
before: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<p> </p><p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
brsInP: {
|
|
||||||
before: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
Here is more text
|
|
||||||
</p>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<p>
|
|
||||||
Here is more text
|
|
||||||
</p></p>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
paragraphize: {
|
|
||||||
before: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<br />
|
|
||||||
Here is more text
|
|
||||||
<span>And also this</span>
|
|
||||||
</p>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<p>
|
|
||||||
Here is more text
|
|
||||||
<span>And also this</span>
|
|
||||||
</p></p>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
paragraphizeBlock: {
|
|
||||||
before: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<br />
|
|
||||||
Here is more text
|
|
||||||
<div>And also this</div>
|
|
||||||
</p>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<p>
|
|
||||||
Here is more text
|
|
||||||
</p><div>And also this</div>
|
|
||||||
</p>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// convertToParagraphs
|
|
||||||
convertToParagraphs: {
|
|
||||||
before: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<span>This should remain in a p</span>
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
This should be wrapped in a p
|
|
||||||
<div>This should become a p</div>
|
|
||||||
</p>
|
|
||||||
<span>This should become a p</span>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<span>This should remain in a p</span>
|
|
||||||
<p>
|
|
||||||
This should be wrapped in a p
|
|
||||||
</p><p>This should become a p</p>
|
|
||||||
</p> <p>This should become a p</p>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// linkDensity
|
|
||||||
linkDensity5: `
|
|
||||||
<div><p>Some text!</p><p><a href="">Some text!</a></p> </div>
|
|
||||||
`,
|
|
||||||
linkDensity1: `
|
|
||||||
<div><p><a href="">Some text!</a></p></div>
|
|
||||||
`,
|
|
||||||
linkDensity0: `
|
|
||||||
<div><p><a href=""></a></p></div>
|
|
||||||
`,
|
|
||||||
|
|
||||||
// rewriteTopLevel
|
|
||||||
rewriteHTMLBody: {
|
|
||||||
before: `
|
|
||||||
<html><body><div><p><a href="">Wow how about that</a></p></div></body></html>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div><div><div><p><a href="">Wow how about that</a></p></div></div></div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// cleanImages
|
|
||||||
cleanSmallImages: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<img width="5" height="5" />
|
|
||||||
<img width="50" />
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<img width="50">
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
cleanHeight: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<img width="50" height="50" />
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<img width="50">
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
cleanSpacer: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<img src="/foo/bar/baz/spacer.png" />
|
|
||||||
<img src="/foo/bar/baz/normal.png" />
|
|
||||||
<p>Some text</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<img src="/foo/bar/baz/normal.png">
|
|
||||||
<p>Some text</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
// stripJunkTags
|
|
||||||
stripsJunk: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<style>.red { color: 'red'; }</style>
|
|
||||||
<title>WOW</title>
|
|
||||||
<link rel="asdflkjawef" />
|
|
||||||
<p>What an article</p>
|
|
||||||
<script type="text/javascript">alert('hi!');</script>
|
|
||||||
<noscript>Don't got it</noscript>
|
|
||||||
<hr />
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What an article</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// stripHOnes
|
|
||||||
removeTwoHOnes: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<h1>Look at this!</h1>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h1>Can you believe it?!</h1>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
convertThreeHOnes: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<h1>Look at this!</h1>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h1>Can you believe it?!</h1>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h1>Can you believe it?!</h1>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<h2>Look at this!</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Can you believe it?!</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Can you believe it?!</h2>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// cleanAttributes
|
|
||||||
removeStyle: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p style="color: red;">What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
removeAlign: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p style="color: red;" align="center">What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// removeEmpty
|
|
||||||
removeEmptyP: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p></p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
doNotRemoveBr: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p></p>
|
|
||||||
<div></div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<div></div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
doNotNested: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p><img src="foo/bar.jpg" /></p>
|
|
||||||
<p><iframe src="foo/bar.jpg" /></p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p><img src="foo/bar.jpg" /></p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// cleanConditionally
|
|
||||||
dropNegativeScore: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>
|
|
||||||
<ul score="-10">
|
|
||||||
<li>Foo</li>
|
|
||||||
<li>Bar</li>
|
|
||||||
</ul>
|
|
||||||
</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>
|
|
||||||
</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
removeTooManyInputs: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<div>
|
|
||||||
<p>What is your name?</p>
|
|
||||||
<input type="text"></input>
|
|
||||||
<p>What is your name?</p>
|
|
||||||
<input type="text"></input>
|
|
||||||
<p>What is your name?</p>
|
|
||||||
<input type="text"></input>
|
|
||||||
</div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
removeShortNoImg: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<div>
|
|
||||||
<p>Keep this one</p>
|
|
||||||
<img src="asdf" />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p>Lose this one</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<div>
|
|
||||||
<p>Keep this one</p>
|
|
||||||
<img src="asdf">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
linkDensityHigh: {
|
|
||||||
before: `
|
|
||||||
<div score="0">
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
</ul>
|
|
||||||
<ul score="20">
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
goodScoreTooDense: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
</ul>
|
|
||||||
<ul score="30">
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
previousEndsInColon: {
|
|
||||||
before: `
|
|
||||||
<div weight="40">
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<p>Now read these links: </p>
|
|
||||||
<ul score="30">
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
cleanEntryContentAsset: {
|
|
||||||
before: `
|
|
||||||
<div score="100">
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul score="20" class="entry-content-asset">
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// normalizeSpaces
|
|
||||||
normalizeSpaces: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: 'What do you think?',
|
|
||||||
},
|
|
||||||
|
|
||||||
// cleanHeaders
|
|
||||||
cleanFirstHeds: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<h2>Lose me</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Keep me</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Keep me</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
cleanTitleMatch: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Title Match</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
dropWithNegativeWeight: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2 class="advert">Bad Class, Bad Weight</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default HTML;
|
|
@ -1,87 +0,0 @@
|
|||||||
const HTML = {
|
|
||||||
score1: `
|
|
||||||
<p>Lorem ipsum dolor sit amet</p>
|
|
||||||
`,
|
|
||||||
score3: `
|
|
||||||
<p>Lorem ipsum, dolor sit, amet</p>
|
|
||||||
`,
|
|
||||||
score19: `
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
`,
|
|
||||||
divScore5: `
|
|
||||||
<div>Lorem ipsum, dolor sit, amet</div>
|
|
||||||
`,
|
|
||||||
blockquoteScore3: `
|
|
||||||
<blockquote>Lorem ipsum, dolor sit, amet</blockquote>
|
|
||||||
`,
|
|
||||||
formScoreNeg3: `
|
|
||||||
<form><label>Lorem ipsum, dolor sit, amet</label></form>
|
|
||||||
`,
|
|
||||||
thScoreNeg5: `
|
|
||||||
<th>Lorem ipsum, dolor sit, amet</th>
|
|
||||||
`,
|
|
||||||
score44: `
|
|
||||||
<p class="entry">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
`,
|
|
||||||
score44Parent: `
|
|
||||||
<div>
|
|
||||||
<p class="entry">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
hNews: {
|
|
||||||
before: `
|
|
||||||
<div class="hentry">
|
|
||||||
<p class="entry-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="hentry" score="99">
|
|
||||||
<p class="entry-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
nonHNews: {
|
|
||||||
before: `
|
|
||||||
<div class="">
|
|
||||||
<p class="entry-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<p class="entry-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="" score="38">
|
|
||||||
<p class="entry-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<p class="entry-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// findTopCandidate
|
|
||||||
findDom1: `
|
|
||||||
<div score="100">
|
|
||||||
<p score="1">Lorem ipsum etc</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
findDom2: `
|
|
||||||
<div score="10">
|
|
||||||
<article score="50">
|
|
||||||
<p score="1">Lorem ipsum etc</p>
|
|
||||||
</article>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
findDom3: `
|
|
||||||
<article score="50">
|
|
||||||
<p score="1">Lorem ipsum br</p>
|
|
||||||
<br score="1000" />
|
|
||||||
</article>
|
|
||||||
`,
|
|
||||||
topBody: `
|
|
||||||
<body>
|
|
||||||
<article>
|
|
||||||
<p>Lorem ipsum etc</p>
|
|
||||||
<br />
|
|
||||||
</article>
|
|
||||||
<body>
|
|
||||||
`,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default HTML;
|
|
@ -1,26 +0,0 @@
|
|||||||
const HTML = {
|
|
||||||
datePublishedMeta: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta name="displaydate" value="1/1/2020 8:30 (EST)" />
|
|
||||||
</head>
|
|
||||||
</html>
|
|
||||||
`,
|
|
||||||
result: new Date('1/1/2020 8:30 (EST)'),
|
|
||||||
},
|
|
||||||
datePublishedSelectors: {
|
|
||||||
test: `
|
|
||||||
<div>
|
|
||||||
<div class="hentry">
|
|
||||||
<div class="updated">
|
|
||||||
1/1/2020 <span class="time">8:30am</span>
|
|
||||||
</div>
|
|
||||||
</head>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
result: new Date('1/1/2020 8:30 am (EST)'),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default HTML;
|
|
@ -1,42 +0,0 @@
|
|||||||
const HTML = {
|
|
||||||
og: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta name="og:image" value="http://example.com/lead.jpg">
|
|
||||||
</head>
|
|
||||||
</html>
|
|
||||||
`,
|
|
||||||
result: 'http://example.com/lead.jpg',
|
|
||||||
},
|
|
||||||
twitter: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta name="twitter:image" value="http://example.com/lead.jpg">
|
|
||||||
</head>
|
|
||||||
</html>
|
|
||||||
`,
|
|
||||||
result: 'http://example.com/lead.jpg',
|
|
||||||
},
|
|
||||||
scoring: {
|
|
||||||
test: `
|
|
||||||
<div>
|
|
||||||
<img src="http://example.com/sprite/abadpic.jpg" />
|
|
||||||
<img src="http://example.com/upload/goodpic.jpg" />
|
|
||||||
<img src="http://example.com/upload/whateverpic.png" />
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
result: 'http://example.com/upload/goodpic.jpg',
|
|
||||||
},
|
|
||||||
selectors: {
|
|
||||||
test: `
|
|
||||||
<div>
|
|
||||||
<link rel="image_src" href="http://example.com/upload/goodpic.jpg">
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
result: 'http://example.com/upload/goodpic.jpg',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default HTML;
|
|
@ -1,49 +1,68 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import cheerio from 'cheerio';
|
import cheerio from 'cheerio';
|
||||||
|
|
||||||
import HTML from './fixtures/html';
|
|
||||||
import GenericTitleExtractor from './extractor';
|
import GenericTitleExtractor from './extractor';
|
||||||
|
|
||||||
describe('GenericTitleExtractor', () => {
|
describe('GenericTitleExtractor', () => {
|
||||||
describe('extract({ $, url, cachedMeta })', () => {
|
describe('extract({ $, url, cachedMeta })', () => {
|
||||||
it('extracts strong meta title tags', () => {
|
it('extracts strong meta title tags', () => {
|
||||||
const $ = cheerio.load(HTML.dcTitle.test);
|
const $ = cheerio.load(`
|
||||||
|
<html>
|
||||||
|
<meta name="dc.title" value="This Is the Title Okay" />
|
||||||
|
<html>
|
||||||
|
`);
|
||||||
const result = GenericTitleExtractor.extract({
|
const result = GenericTitleExtractor.extract({
|
||||||
$,
|
$,
|
||||||
url: '',
|
url: '',
|
||||||
metaCache: ['dc.title', 'something-else'],
|
metaCache: ['dc.title', 'something-else'],
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(result, HTML.dcTitle.result);
|
assert.equal(result, 'This Is the Title Okay');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('pulls title from selectors lacking string meta', () => {
|
it('pulls title from selectors lacking string meta', () => {
|
||||||
const $ = cheerio.load(HTML.strongTitleSelector.test);
|
const $ = cheerio.load(`
|
||||||
|
<html>
|
||||||
|
<article class="hentry">
|
||||||
|
<h1 class="entry-title">This Is the Title Okay</h1>
|
||||||
|
</article>
|
||||||
|
<html>
|
||||||
|
`);
|
||||||
const result = GenericTitleExtractor.extract({
|
const result = GenericTitleExtractor.extract({
|
||||||
$,
|
$,
|
||||||
url: '',
|
url: '',
|
||||||
metaCache: ['og:title', 'something-else'],
|
metaCache: ['og:title', 'something-else'],
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(result, HTML.ogTitle.result);
|
assert.equal(result, 'This Is the Title Okay');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('then falls back to weak meta title tags', () => {
|
it('then falls back to weak meta title tags', () => {
|
||||||
const $ = cheerio.load(HTML.ogTitle.test);
|
const $ = cheerio.load(`
|
||||||
|
<html>
|
||||||
|
<meta name="og:title" value="This Is the Title Okay" />
|
||||||
|
<html>
|
||||||
|
`);
|
||||||
const result = GenericTitleExtractor.extract({
|
const result = GenericTitleExtractor.extract({
|
||||||
$,
|
$,
|
||||||
url: '',
|
url: '',
|
||||||
metaCache: ['og:title', 'something-else'],
|
metaCache: ['og:title', 'something-else'],
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(result, HTML.ogTitle.result);
|
assert.equal(result, 'This Is the Title Okay');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('then falls back to weak selectors', () => {
|
it('then falls back to weak selectors', () => {
|
||||||
const $ = cheerio.load(HTML.weakTitleSelector.test);
|
const $ = cheerio.load(`
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>This Is the Weak Title Okay</title>
|
||||||
|
</head>
|
||||||
|
<html>
|
||||||
|
`);
|
||||||
const result = GenericTitleExtractor.extract({ $, url: '', metaCache: [] });
|
const result = GenericTitleExtractor.extract({ $, url: '', metaCache: [] });
|
||||||
|
|
||||||
assert.equal(result, HTML.weakTitleSelector.result);
|
assert.equal(result, 'This Is the Weak Title Okay');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
const HTML = {
|
|
||||||
dcTitle: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<meta name="dc.title" value="This Is the Title Okay" />
|
|
||||||
<html>
|
|
||||||
`,
|
|
||||||
result: 'This Is the Title Okay',
|
|
||||||
},
|
|
||||||
ogTitle: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<meta name="og:title" value="This Is the Title Okay" />
|
|
||||||
<html>
|
|
||||||
`,
|
|
||||||
result: 'This Is the Title Okay',
|
|
||||||
},
|
|
||||||
strongTitleSelector: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<article class="hentry">
|
|
||||||
<h1 class="entry-title">This Is the Title Okay</h1>
|
|
||||||
</article>
|
|
||||||
<html>
|
|
||||||
`,
|
|
||||||
result: 'This Is the Title Okay',
|
|
||||||
},
|
|
||||||
weakTitleSelector: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>This Is the Weak Title Okay</title>
|
|
||||||
</head>
|
|
||||||
<html>
|
|
||||||
`,
|
|
||||||
result: 'This Is the Weak Title Okay',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default HTML;
|
|
@ -1,28 +1,41 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import cheerio from 'cheerio';
|
import cheerio from 'cheerio';
|
||||||
|
|
||||||
import HTML from './fixtures/extract-from-selectors';
|
|
||||||
import { extractFromMeta } from './index';
|
import { extractFromMeta } from './index';
|
||||||
|
|
||||||
describe('extractFromMeta($, metaNames, cachedNames, cleanTags)', () => {
|
describe('extractFromMeta($, metaNames, cachedNames, cleanTags)', () => {
|
||||||
it('extracts an arbitrary meta tag by name', () => {
|
it('extracts an arbitrary meta tag by name', () => {
|
||||||
const $ = cheerio.load(HTML.metaFoo.test);
|
const $ = cheerio.load(`
|
||||||
|
<html>
|
||||||
|
<meta name="foo" value="bar" />
|
||||||
|
</html>
|
||||||
|
`);
|
||||||
const result = extractFromMeta($, ['foo', 'baz'], ['foo', 'bat']);
|
const result = extractFromMeta($, ['foo', 'baz'], ['foo', 'bat']);
|
||||||
|
|
||||||
assert.equal(result, HTML.metaFoo.result);
|
assert.equal(result, 'bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns nothing if a meta name is duplicated', () => {
|
it('returns nothing if a meta name is duplicated', () => {
|
||||||
const $ = cheerio.load(HTML.metaDupes.test);
|
const $ = cheerio.load(`
|
||||||
|
<html>
|
||||||
|
<meta name="foo" value="bar" />
|
||||||
|
<meta name="foo" value="baz" />
|
||||||
|
</html>
|
||||||
|
`);
|
||||||
const result = extractFromMeta($, ['foo', 'baz'], ['foo', 'bat']);
|
const result = extractFromMeta($, ['foo', 'baz'], ['foo', 'bat']);
|
||||||
|
|
||||||
assert.equal(result, HTML.metaDupes.result);
|
assert.equal(result, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ignores duplicate meta names with empty values', () => {
|
it('ignores duplicate meta names with empty values', () => {
|
||||||
const $ = cheerio.load(HTML.metaEmptyDupes.test);
|
const $ = cheerio.load(`
|
||||||
|
<html>
|
||||||
|
<meta name="foo" value="bar" />
|
||||||
|
<meta name="foo" value="" />
|
||||||
|
</html>
|
||||||
|
`);
|
||||||
const result = extractFromMeta($, ['foo', 'baz'], ['foo', 'bat']);
|
const result = extractFromMeta($, ['foo', 'baz'], ['foo', 'bat']);
|
||||||
|
|
||||||
assert.equal(result, HTML.metaEmptyDupes.result);
|
assert.equal(result, 'bar');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,35 +1,55 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import cheerio from 'cheerio';
|
import cheerio from 'cheerio';
|
||||||
|
|
||||||
import HTML from './fixtures/extract-from-selectors';
|
|
||||||
import extractFromSelectors from './extract-from-selectors';
|
import extractFromSelectors from './extract-from-selectors';
|
||||||
|
|
||||||
describe('extractFromSelectors($, selectors, maxChildren, textOnly)', () => {
|
describe('extractFromSelectors($, selectors, maxChildren, textOnly)', () => {
|
||||||
it('extracts an arbitrary node by selector', () => {
|
it('extracts an arbitrary node by selector', () => {
|
||||||
const $ = cheerio.load(HTML.simpleSelector.test);
|
const $ = cheerio.load(`
|
||||||
const result = extractFromSelectors($, ['.author']);
|
<html>
|
||||||
|
<div class="author">Adam</div>
|
||||||
|
</html>
|
||||||
|
`);
|
||||||
|
|
||||||
assert.equal(result, HTML.simpleSelector.result);
|
assert.equal(extractFromSelectors($, ['.author']), 'Adam');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ignores comments', () => {
|
it('ignores comments', () => {
|
||||||
const $ = cheerio.load(HTML.insideComment.test);
|
const $ = cheerio.load(`
|
||||||
const result = extractFromSelectors($, ['.author']);
|
<html>
|
||||||
|
<div class="comments-section">
|
||||||
assert.equal(result, HTML.insideComment.result);
|
<div class="author">Adam</div>
|
||||||
|
</div>
|
||||||
|
</html>`);
|
||||||
|
|
||||||
|
assert.equal(extractFromSelectors($, ['.author']), null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('skips a selector if it matches multiple nodes', () => {
|
it('skips a selector if it matches multiple nodes', () => {
|
||||||
const $ = cheerio.load(HTML.multiMatch.test);
|
const $ = cheerio.load(`
|
||||||
const result = extractFromSelectors($, ['.author']);
|
<html>
|
||||||
|
<div>
|
||||||
assert.equal(result, HTML.multiMatch.result);
|
<div class="author">Adam</div>
|
||||||
|
<div class="author">Adam</div>
|
||||||
|
</div>
|
||||||
|
</html>
|
||||||
|
`);
|
||||||
|
|
||||||
|
assert.equal(extractFromSelectors($, ['.author']), null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('skips a node with too many children', () => {
|
it('skips a node with too many children', () => {
|
||||||
const $ = cheerio.load(HTML.manyChildren.test);
|
const $ = cheerio.load(`
|
||||||
const result = extractFromSelectors($, ['.author']);
|
<html>
|
||||||
|
<div>
|
||||||
assert.equal(result, HTML.manyChildren.result);
|
<div class="author">
|
||||||
|
<span>Adam</span>
|
||||||
|
<span>Pash</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</html>
|
||||||
|
`);
|
||||||
|
|
||||||
|
assert.equal(extractFromSelectors($, ['.author']), null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,75 +0,0 @@
|
|||||||
const HTML = {
|
|
||||||
// extractFromMeta
|
|
||||||
metaFoo: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<meta name="foo" value="bar" />
|
|
||||||
</html>`,
|
|
||||||
result: 'bar',
|
|
||||||
},
|
|
||||||
metaDupes: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<meta name="foo" value="bar" />
|
|
||||||
<meta name="foo" value="baz" />
|
|
||||||
</html>`,
|
|
||||||
result: null,
|
|
||||||
},
|
|
||||||
metaEmptyDupes: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<meta name="foo" value="bar" />
|
|
||||||
<meta name="foo" value="" />
|
|
||||||
</html>`,
|
|
||||||
result: 'bar',
|
|
||||||
},
|
|
||||||
custom: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<meta property="foo" content="bar" />
|
|
||||||
</html>`,
|
|
||||||
result: 'bar',
|
|
||||||
},
|
|
||||||
|
|
||||||
// extractFromSelectors
|
|
||||||
simpleSelector: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<div class="author">Adam</div>
|
|
||||||
</html>`,
|
|
||||||
result: 'Adam',
|
|
||||||
},
|
|
||||||
insideComment: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<div class="comments-section">
|
|
||||||
<div class="author">Adam</div>
|
|
||||||
</div>
|
|
||||||
</html>`,
|
|
||||||
result: null,
|
|
||||||
},
|
|
||||||
multiMatch: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<div>
|
|
||||||
<div class="author">Adam</div>
|
|
||||||
<div class="author">Adam</div>
|
|
||||||
</div>
|
|
||||||
</html>`,
|
|
||||||
result: null,
|
|
||||||
},
|
|
||||||
manyChildren: {
|
|
||||||
test: `
|
|
||||||
<html>
|
|
||||||
<div>
|
|
||||||
<div class="author">
|
|
||||||
<span>Adam</span>
|
|
||||||
<span>Pash</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</html>`,
|
|
||||||
result: null,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default HTML;
|
|
@ -1,714 +0,0 @@
|
|||||||
const HTML = {
|
|
||||||
// getWeight fixtures
|
|
||||||
positiveId: `
|
|
||||||
<div id="entry">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
negativeId: `
|
|
||||||
<div id="adbox">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positiveClass: `
|
|
||||||
<div class="entry">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
negativeClass: `
|
|
||||||
<div id="comment ad">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positiveIdAndClass: `
|
|
||||||
<div id="article" class="entry">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positiveIdNegClass: `
|
|
||||||
<div id="article" class="adbox">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positivePhotoClass: `
|
|
||||||
<div class="figure">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positiveIdAndPhoto: `
|
|
||||||
<div id="article" class="figure">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
entryContentAsset: `
|
|
||||||
<div id="foo" class="entry-content-asset">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
|
|
||||||
// stripUnlikelyCandidates
|
|
||||||
noMatches: `
|
|
||||||
<div id="foo">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
whitelistMatch: {
|
|
||||||
before: `
|
|
||||||
<div class="header">Stuff</div>
|
|
||||||
<div class="article">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
whiteAndBlack: {
|
|
||||||
before: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
whiteInsideBlack: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<div class="adbox">
|
|
||||||
<div class="article">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>Something unrelated</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<div>Something unrelated</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// brsToPs
|
|
||||||
singleBr: {
|
|
||||||
before: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<br>
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<br>
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
doubleBrs: {
|
|
||||||
before: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<p> </p><p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
severalBrs: {
|
|
||||||
before: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<p> </p><p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
brsInP: {
|
|
||||||
before: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
Here is more text
|
|
||||||
</p>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<p>
|
|
||||||
Here is more text
|
|
||||||
</p></p>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
paragraphize: {
|
|
||||||
before: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<br />
|
|
||||||
Here is more text
|
|
||||||
<span>And also this</span>
|
|
||||||
</p>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<p>
|
|
||||||
Here is more text
|
|
||||||
<span>And also this</span>
|
|
||||||
</p></p>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
paragraphizeBlock: {
|
|
||||||
before: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<br />
|
|
||||||
Here is more text
|
|
||||||
<div>And also this</div>
|
|
||||||
</p>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<p>
|
|
||||||
Here is more text
|
|
||||||
</p><div>And also this</div>
|
|
||||||
</p>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// convertToParagraphs
|
|
||||||
convertToParagraphs: {
|
|
||||||
before: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<span>This should remain in a p</span>
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
This should be wrapped in a p
|
|
||||||
<div>This should become a p</div>
|
|
||||||
</p>
|
|
||||||
<span>This should become a p</span>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<span>This should remain in a p</span>
|
|
||||||
<p>
|
|
||||||
This should be wrapped in a p
|
|
||||||
</p><p>This should become a p</p>
|
|
||||||
</p> <p>This should become a p</p>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// linkDensity
|
|
||||||
linkDensity5: `
|
|
||||||
<div><p>Some text!</p><p><a href="">Some text!</a></p> </div>
|
|
||||||
`,
|
|
||||||
linkDensity1: `
|
|
||||||
<div><p><a href="">Some text!</a></p></div>
|
|
||||||
`,
|
|
||||||
linkDensity0: `
|
|
||||||
<div><p><a href=""></a></p></div>
|
|
||||||
`,
|
|
||||||
|
|
||||||
// rewriteTopLevel
|
|
||||||
rewriteHTMLBody: {
|
|
||||||
before: `
|
|
||||||
<html><body><div><p><a href="">Wow how about that</a></p></div></body></html>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div><div><div><p><a href="">Wow how about that</a></p></div></div></div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// cleanImages
|
|
||||||
cleanSmallImages: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<img width="5" height="5" />
|
|
||||||
<img width="50" />
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<img width="50">
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
cleanHeight: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<img width="50" height="50" />
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<img width="50">
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
cleanSpacer: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<img src="/foo/bar/baz/spacer.png" />
|
|
||||||
<img src="/foo/bar/baz/normal.png" />
|
|
||||||
<p>Some text</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<img src="/foo/bar/baz/normal.png">
|
|
||||||
<p>Some text</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
// stripJunkTags
|
|
||||||
stripsJunk: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<style>.red { color: 'red'; }</style>
|
|
||||||
<title>WOW</title>
|
|
||||||
<link rel="asdflkjawef" />
|
|
||||||
<p>What an article</p>
|
|
||||||
<script type="text/javascript">alert('hi!');</script>
|
|
||||||
<noscript>Don't got it</noscript>
|
|
||||||
<hr />
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What an article</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
ignoresKeepable: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<style>.red { color: 'red'; }</style>
|
|
||||||
<title>WOW</title>
|
|
||||||
<link rel="asdflkjawef" />
|
|
||||||
<p>What an article</p>
|
|
||||||
<iframe class="mercury-parser-keep" src="https://www.youtube.com/embed/_2AqQV8wDvY" frameborder="0" allowfullscreen></iframe>
|
|
||||||
<hr />
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What an article</p>
|
|
||||||
<iframe class="" src="https://www.youtube.com/embed/_2AqQV8wDvY" frameborder="0" allowfullscreen></iframe>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// markToKeep
|
|
||||||
marksYouTube: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What an article</p>
|
|
||||||
<iframe src="https://www.youtube.com/embed/_2AqQV8wDvY" frameborder="0" allowfullscreen></iframe>
|
|
||||||
<iframe src="foo" frameborder="0" allowfullscreen></iframe>
|
|
||||||
<iframe src="https://player.vimeo.com/video/57712615"></iframe>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What an article</p>
|
|
||||||
<iframe src="https://www.youtube.com/embed/_2AqQV8wDvY" frameborder="0" allowfullscreen class="mercury-parser-keep"></iframe>
|
|
||||||
<iframe src="foo" frameborder="0" allowfullscreen></iframe>
|
|
||||||
<iframe src="https://player.vimeo.com/video/57712615" class="mercury-parser-keep"></iframe>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// stripHOnes
|
|
||||||
removeTwoHOnes: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<h1>Look at this!</h1>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h1>Can you believe it?!</h1>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
convertThreeHOnes: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<h1>Look at this!</h1>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h1>Can you believe it?!</h1>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h1>Can you believe it?!</h1>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<h2>Look at this!</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Can you believe it?!</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Can you believe it?!</h2>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// cleanAttributes
|
|
||||||
removeStyle: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p style="color: red;">What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
removeAlign: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p style="color: red;" align="center">What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// removeEmpty
|
|
||||||
removeEmptyP: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p></p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
doNotRemoveBr: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p></p>
|
|
||||||
<div></div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<div></div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
doNotNested: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p><img src="foo/bar.jpg" /></p>
|
|
||||||
<p><iframe src="foo/bar.jpg" /></p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p><img src="foo/bar.jpg" /></p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// cleanConditionally
|
|
||||||
dropNegativeScore: {
|
|
||||||
before: `
|
|
||||||
<div score="5">
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>
|
|
||||||
<ul score="-10">
|
|
||||||
<li>Foo</li>
|
|
||||||
<li>Bar</li>
|
|
||||||
</ul>
|
|
||||||
</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div score="5">
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>
|
|
||||||
</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
afterBrowser: `
|
|
||||||
<div score="5">
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>
|
|
||||||
</p>
|
|
||||||
<p></p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
removeTooManyInputs: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<div>
|
|
||||||
<p>What is your name?</p>
|
|
||||||
<input type="text"></input>
|
|
||||||
<p>What is your name?</p>
|
|
||||||
<input type="text"></input>
|
|
||||||
<p>What is your name?</p>
|
|
||||||
<input type="text"></input>
|
|
||||||
</div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
removeShortNoImg: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<div>
|
|
||||||
<p>Keep this one</p>
|
|
||||||
<img src="asdf" />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p>Lose this one</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<div>
|
|
||||||
<p>Keep this one</p>
|
|
||||||
<img src="asdf">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
linkDensityHigh: {
|
|
||||||
before: `
|
|
||||||
<div score="0">
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
</ul>
|
|
||||||
<ul score="20">
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
goodScoreTooDense: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
</ul>
|
|
||||||
<ul score="30">
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
previousEndsInColon: {
|
|
||||||
before: `
|
|
||||||
<div score="40">
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<p>Now read these links: </p>
|
|
||||||
<ul score="30">
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
cleanEntryContentAsset: {
|
|
||||||
before: `
|
|
||||||
<div score="100">
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul score="20" class="entry-content-asset">
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// normalizeSpaces
|
|
||||||
normalizeSpaces: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: 'What do you think?',
|
|
||||||
},
|
|
||||||
|
|
||||||
// cleanHeaders
|
|
||||||
cleanFirstHeds: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<h2>Lose me</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Keep me</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Keep me</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
cleanTitleMatch: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Title Match</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
dropWithNegativeWeight: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2 class="advert">Bad Class, Bad Weight</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default HTML;
|
|
@ -1,16 +0,0 @@
|
|||||||
const HTML = {
|
|
||||||
tooShort: `
|
|
||||||
<div class="foo bar">
|
|
||||||
<p>This is too short</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
longEnough: `
|
|
||||||
<div class="foo bar">
|
|
||||||
<p>
|
|
||||||
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean m
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default HTML;
|
|
@ -1,21 +1,30 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import cheerio from 'cheerio';
|
import cheerio from 'cheerio';
|
||||||
|
|
||||||
import HTML from './fixtures/node-is-sufficient';
|
|
||||||
import nodeIsSufficient from './node-is-sufficient';
|
import nodeIsSufficient from './node-is-sufficient';
|
||||||
|
|
||||||
describe('Utils', () => {
|
describe('Utils', () => {
|
||||||
describe('nodeIsSufficient(node)', () => {
|
describe('nodeIsSufficient(node)', () => {
|
||||||
it('returns false if node text length < 100 chars', () => {
|
it('returns false if node text length < 100 chars', () => {
|
||||||
const $ = cheerio.load(HTML.tooShort);
|
const $ = cheerio.load(`
|
||||||
const sufficient = nodeIsSufficient($.root());
|
<div class="foo bar">
|
||||||
assert.equal(sufficient, false);
|
<p>This is too short</p>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
|
||||||
|
assert.equal(nodeIsSufficient($.root()), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns true if node text length > 100 chars', () => {
|
it('returns true if node text length > 100 chars', () => {
|
||||||
const $ = cheerio.load(HTML.longEnough);
|
const $ = cheerio.load(`
|
||||||
const sufficient = nodeIsSufficient($.root());
|
<div class="foo bar">
|
||||||
assert.equal(sufficient, true);
|
<p>
|
||||||
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean m
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
|
||||||
|
assert.equal(nodeIsSufficient($.root()), true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,674 +0,0 @@
|
|||||||
const HTML = {
|
|
||||||
// getWeight fixtures
|
|
||||||
positiveId: `
|
|
||||||
<div id="entry">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
negativeId: `
|
|
||||||
<div id="adbox">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positiveClass: `
|
|
||||||
<div class="entry">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
negativeClass: `
|
|
||||||
<div id="comment ad">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positiveIdAndClass: `
|
|
||||||
<div id="article" class="entry">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positiveIdNegClass: `
|
|
||||||
<div id="article" class="adbox">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positivePhotoClass: `
|
|
||||||
<div class="figure">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
positiveIdAndPhoto: `
|
|
||||||
<div id="article" class="figure">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
entryContentAsset: `
|
|
||||||
<div id="foo" class="entry-content-asset">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
|
|
||||||
// stripUnlikelyCandidates
|
|
||||||
noMatches: `
|
|
||||||
<div id="foo">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
whitelistMatch: {
|
|
||||||
before: `
|
|
||||||
<div class="header">Stuff</div>
|
|
||||||
<div class="article">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
whiteAndBlack: {
|
|
||||||
before: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
whiteInsideBlack: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<div class="adbox">
|
|
||||||
<div class="article">
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>Something unrelated</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<div>Something unrelated</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// brsToPs
|
|
||||||
singleBr: {
|
|
||||||
before: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<br>
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<br>
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
doubleBrs: {
|
|
||||||
before: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<p> </p><p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
severalBrs: {
|
|
||||||
before: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div class="article adbox">
|
|
||||||
<p> </p><p>Ooo good one</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
brsInP: {
|
|
||||||
before: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
Here is more text
|
|
||||||
</p>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<p>
|
|
||||||
Here is more text
|
|
||||||
</p></p>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
paragraphize: {
|
|
||||||
before: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<br />
|
|
||||||
Here is more text
|
|
||||||
<span>And also this</span>
|
|
||||||
</p>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<p>
|
|
||||||
Here is more text
|
|
||||||
<span>And also this</span>
|
|
||||||
</p></p>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
paragraphizeBlock: {
|
|
||||||
before: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<br />
|
|
||||||
Here is more text
|
|
||||||
<div>And also this</div>
|
|
||||||
</p>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<p>
|
|
||||||
Here is more text
|
|
||||||
</p><div>And also this</div>
|
|
||||||
</p>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// convertToParagraphs
|
|
||||||
convertToParagraphs: {
|
|
||||||
before: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<span>This should remain in a p</span>
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
This should be wrapped in a p
|
|
||||||
<div>This should become a p</div>
|
|
||||||
</p>
|
|
||||||
<span>This should become a p</span>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<p>
|
|
||||||
Here is some text
|
|
||||||
<span>This should remain in a p</span>
|
|
||||||
<p>
|
|
||||||
This should be wrapped in a p
|
|
||||||
</p><p>This should become a p</p>
|
|
||||||
</p> <p>This should become a p</p>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// linkDensity
|
|
||||||
linkDensity5: `
|
|
||||||
<div><p>Some text!</p><p><a href="">Some text!</a></p> </div>
|
|
||||||
`,
|
|
||||||
linkDensity1: `
|
|
||||||
<div><p><a href="">Some text!</a></p></div>
|
|
||||||
`,
|
|
||||||
linkDensity0: `
|
|
||||||
<div><p><a href=""></a></p></div>
|
|
||||||
`,
|
|
||||||
|
|
||||||
// rewriteTopLevel
|
|
||||||
rewriteHTMLBody: {
|
|
||||||
before: `
|
|
||||||
<html><body><div><p><a href="">Wow how about that</a></p></div></body></html>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div><div><div><p><a href="">Wow how about that</a></p></div></div></div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// cleanImages
|
|
||||||
cleanSmallImages: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<img width="5" height="5" />
|
|
||||||
<img width="50" />
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<img width="50">
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
cleanHeight: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<img width="50" height="50" />
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<img width="50">
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
cleanSpacer: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<img src="/foo/bar/baz/spacer.png" />
|
|
||||||
<img src="/foo/bar/baz/normal.png" />
|
|
||||||
<p>Some text</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<img src="/foo/bar/baz/normal.png">
|
|
||||||
<p>Some text</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
// stripJunkTags
|
|
||||||
stripsJunk: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<style>.red { color: 'red'; }</style>
|
|
||||||
<title>WOW</title>
|
|
||||||
<link rel="asdflkjawef" />
|
|
||||||
<p>What an article</p>
|
|
||||||
<script type="text/javascript">alert('hi!');</script>
|
|
||||||
<noscript>Don't got it</noscript>
|
|
||||||
<hr />
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What an article</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// stripHOnes
|
|
||||||
removeTwoHOnes: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<h1>Look at this!</h1>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h1>Can you believe it?!</h1>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
convertThreeHOnes: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<h1>Look at this!</h1>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h1>Can you believe it?!</h1>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h1>Can you believe it?!</h1>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<h2>Look at this!</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Can you believe it?!</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Can you believe it?!</h2>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// cleanAttributes
|
|
||||||
removeStyle: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p style="color: red;">What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
removeAlign: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p style="color: red;" align="center">What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// removeEmpty
|
|
||||||
removeEmptyP: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p></p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
doNotRemoveBr: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p></p>
|
|
||||||
<div></div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<div></div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
doNotNested: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p><img src="foo/bar.jpg" /></p>
|
|
||||||
<p><iframe src="foo/bar.jpg" /></p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p><img src="foo/bar.jpg" /></p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// cleanConditionally
|
|
||||||
dropNegativeScore: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>
|
|
||||||
<ul score="-10">
|
|
||||||
<li>Foo</li>
|
|
||||||
<li>Bar</li>
|
|
||||||
</ul>
|
|
||||||
</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>
|
|
||||||
</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
removeTooManyInputs: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<div>
|
|
||||||
<p>What is your name?</p>
|
|
||||||
<input type="text"></input>
|
|
||||||
<p>What is your name?</p>
|
|
||||||
<input type="text"></input>
|
|
||||||
<p>What is your name?</p>
|
|
||||||
<input type="text"></input>
|
|
||||||
</div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
removeShortNoImg: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<div>
|
|
||||||
<p>Keep this one</p>
|
|
||||||
<img src="asdf" />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p>Lose this one</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<div>
|
|
||||||
<p>Keep this one</p>
|
|
||||||
<img src="asdf">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
linkDensityHigh: {
|
|
||||||
before: `
|
|
||||||
<div score="0">
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
</ul>
|
|
||||||
<ul score="20">
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
goodScoreTooDense: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
</ul>
|
|
||||||
<ul score="30">
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
<li>Keep this one</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
previousEndsInColon: {
|
|
||||||
before: `
|
|
||||||
<div weight="40">
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<p>Now read these links: </p>
|
|
||||||
<ul score="30">
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
cleanEntryContentAsset: {
|
|
||||||
before: `
|
|
||||||
<div score="100">
|
|
||||||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu.</p>
|
|
||||||
<ul score="20" class="entry-content-asset">
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
<li><a href="#">Lose this one</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// normalizeSpaces
|
|
||||||
normalizeSpaces: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: 'What do you think?',
|
|
||||||
},
|
|
||||||
normalizeSpacesPreserve: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<pre> What happens to spaces? </pre>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after:
|
|
||||||
'<div> <p>What do you think?</p> <pre> What happens to spaces? </pre> </div>',
|
|
||||||
},
|
|
||||||
|
|
||||||
// cleanHeaders
|
|
||||||
cleanFirstHeds: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<h2>Lose me</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Keep me</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Keep me</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
cleanTitleMatch: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2>Title Match</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
dropWithNegativeWeight: {
|
|
||||||
before: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<h2 class="advert">Bad Class, Bad Weight</h2>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
after: `
|
|
||||||
<div>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
<p>What do you think?</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default HTML;
|
|
@ -1,26 +1,36 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import cheerio from 'cheerio';
|
import cheerio from 'cheerio';
|
||||||
|
|
||||||
import HTML from './fixtures/html';
|
|
||||||
|
|
||||||
import { normalizeSpaces } from './index';
|
import { normalizeSpaces } from './index';
|
||||||
|
|
||||||
describe('normalizeSpaces(text)', () => {
|
describe('normalizeSpaces(text)', () => {
|
||||||
it('normalizes spaces from text', () => {
|
it('normalizes spaces from text', () => {
|
||||||
const $ = cheerio.load(HTML.normalizeSpaces.before);
|
const $ = cheerio.load(`
|
||||||
|
<div>
|
||||||
|
<p>What do you think?</p>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
|
||||||
const result = normalizeSpaces(
|
const result = normalizeSpaces(
|
||||||
$('*')
|
$('*')
|
||||||
.first()
|
.first()
|
||||||
.text()
|
.text()
|
||||||
);
|
);
|
||||||
assert.equal(result, HTML.normalizeSpaces.after);
|
assert.equal(result, 'What do you think?');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('preserves spaces in preformatted text blocks', () => {
|
it('preserves spaces in preformatted text blocks', () => {
|
||||||
const $ = cheerio.load(HTML.normalizeSpacesPreserve.before);
|
const $ = cheerio.load(`
|
||||||
|
<div>
|
||||||
|
<p>What do you think?</p>
|
||||||
|
<pre> What happens to spaces? </pre>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
|
||||||
const result = normalizeSpaces($.html());
|
const result = normalizeSpaces($.html());
|
||||||
assert.equal(result, HTML.normalizeSpacesPreserve.after);
|
assert.equal(
|
||||||
|
result,
|
||||||
|
'<div> <p>What do you think?</p> <pre> What happens to spaces? </pre> </div>'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue