index.js 677 B

12345678910111213141516171819202122232425262728
  1. var Prism = require('prismjs');
  2. var cheerio = require('cheerio');
  3. var path = require('path');
  4. var prismCSS = require.resolve('prismjs/themes/prism.css');
  5. module.exports = {
  6. book: {
  7. assets: path.dirname(prismCSS),
  8. css: [path.basename(prismCSS)]
  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. };