Browse Source

Fix implementation

Dan Abramov 9 years ago
parent
commit
120569d554
1 changed files with 10 additions and 7 deletions
  1. 10 7
      index.js

+ 10 - 7
index.js

@@ -1,4 +1,5 @@
 var Prism = require('prismjs');
+var cheerio = require('cheerio');
 
 module.exports = {
   book: {
@@ -9,15 +10,17 @@ module.exports = {
   },
   hooks: {
     page: function (page) {
-      var $ = cheerio.load(page.content);
+      page.sections.forEach(function (section) {
+        var $ = cheerio.load(section.content);
 
-      $('code').each(function() {
-        var text = $(this).text();
-        var highlighted = Prism.highlight(text, Prism.languages.javascript);
-        $(this).html(highlighted);
-      });
+        $('code').each(function() {
+          var text = $(this).text();
+          var highlighted = Prism.highlight(text, Prism.languages.javascript);
+          $(this).html(highlighted);
+        });
 
-      page.content = $.html();
+        section.content = $.html();
+      });
       return page;
     }
   }