index.js 597 B

123456789101112131415161718192021222324252627
  1. var Prism = require('prismjs');
  2. var cheerio = require('cheerio');
  3. module.exports = {
  4. book: {
  5. assets: './node_modules/prismjs/themes',
  6. css: [
  7. 'prism.css'
  8. ]
  9. },
  10. hooks: {
  11. page: function (page) {
  12. page.sections.forEach(function (section) {
  13. var $ = cheerio.load(section.content);
  14. $('code').each(function() {
  15. var text = $(this).text();
  16. var highlighted = Prism.highlight(text, Prism.languages.javascript);
  17. $(this).html(highlighted);
  18. });
  19. section.content = $.html();
  20. });
  21. return page;
  22. }
  23. }
  24. };