index.js 707 B

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