Skip to content

Commit

Permalink
Fix logic after cheerio update
Browse files Browse the repository at this point in the history
Newer cheerio by default wraps the content in `<html><head>...<body>` tags
which we don't want. Fix the logic & test fixtures.
  • Loading branch information
mgol authored and Krinkle committed Nov 8, 2023
1 parent b786a2a commit 72a287e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
5 changes: 4 additions & 1 deletion lib/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ function outdent( string ) {
}

function syntaxHighlight( html ) {
var $ = cheerio.load( html );

// The third parameter is `false` to disable wrapping contents
// in `<html><head>...`, etc.
var $ = cheerio.load( html, null, false );

$( "pre > code" ).each( function() {
var $t = $( this ),
Expand Down
4 changes: 2 additions & 2 deletions test/expected/wordpress/posts/page/pages/Hello_World.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script>{"title":"Hello World","customFields":[{"key":"source_path","value":"fixture/pages/Hello_World.html"}]}</script>
<html><head></head><body><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pellentesque placerat arcu, vel viverra augue posuere commodo. Aenean hendrerit quam sed commodo pellentesque.</p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pellentesque placerat arcu, vel viverra augue posuere commodo. Aenean hendrerit quam sed commodo pellentesque.</p>
<p>Donec sed commodo velit, non molestie justo.</p>
<h3>Phasellus</h3>
<p>Cras vel justo molestie lorem auctor convallis. Donec ac lacus tincidunt, euismod lectus eu, pulvinar tortor.</p>
Expand Down Expand Up @@ -31,4 +32,3 @@ <h3>Phasellus</h3>
<h3>Sed sed molestie purus</h3>
<p>Aliquam venenatis sem elit, et aliquet libero ultrices vitae. Nullam rutrum convallis justo, sed suscipit leo facilisis et.
</p>
</body></html>
3 changes: 1 addition & 2 deletions test/expected/wordpress/posts/page/pages/Mark.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<script>{"title":"Markdown","customFields":[{"key":"source_path","value":"fixture/pages/Mark.md"}]}</script>
<html><head></head><body><p><strong>Conubia linguae</strong> hydrae novissima recepto certe, clarus quod amictus tum ignota fluctibus <em>et quod</em>, est verba capitum, variusque. Sui saevam gentes propiora Cycladas, Hecate stamina nurus ramum!</p>
<p><strong>Conubia linguae</strong> hydrae novissima recepto certe, clarus quod amictus tum ignota fluctibus <em>et quod</em>, est verba capitum, variusque. Sui saevam gentes propiora Cycladas, Hecate stamina nurus ramum!</p>
<h2 class="toc-linked" id="oculi-miserarum"><a href="#oculi-miserarum" class="icon-link toc-link"><span class="visuallyhidden">link</span></a> Oculi miserarum</h2><p>Lorem <a href="https://en.wikipedia.org/wiki/Markdown">markdownum</a> silentia umerique, colla. Per felix innoxia pariterque capillos accessit, nec ad tempore in nubes detrahitur.</p>
<p>Aures precantibus supplice Medusaeo, Lycormas est esse aestuat aut Pterelas.</p>
<h2 class="toc-linked" id="domitos-interea"><a href="#domitos-interea" class="icon-link toc-link"><span class="visuallyhidden">link</span></a> Domitos interea</h2><ol>
<li>Non torsi numine amor</li>
<li>Tamen vino hinc indignatus aquas iunguntur sacrifica</li>
<li>Solitum bacae tellure ille</li>
</ol>
</body></html>
5 changes: 2 additions & 3 deletions test/expected/wordpress/posts/post/addClass.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html><head><script>{
<script>{
"title":
".addClass()",
"excerpt":
Expand All @@ -8,7 +8,7 @@
"css","version/1.0","version/1.4"
]
}
}</script></head><body><article id="addClass1" class="entry method"><h2 class="section-title">
}</script><article id="addClass1" class="entry method"><h2 class="section-title">
<span class="name">.addClass( className )</span><span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a></span>
</h2>
<div class="entry-wrapper">
Expand Down Expand Up @@ -117,4 +117,3 @@ <h4>Demo:</h4>
<div class="demo code-demo"></div>
</div></section>
</div></article>
</body></html>

0 comments on commit 72a287e

Please sign in to comment.