Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. const marked = require('marked');
  2. const renderer = new marked.Renderer();
  3. const cheerio = require('cheerio');
  4.  
  5. renderer.html = function(html) {
  6. // marked has to be the first attribute
  7. if (html.startsWith('<div marked')) {
  8. const $ = cheerio.load(html);
  9. const markedDivs = $('div[marked]');
  10. // loop through all div tags with marked attribute
  11. for (var i = markedDivs.length; i > 0; i--) {
  12. marked(markedDivs.eq(i).html(), function(err, html) {
  13. markedDivs.eq(i).html(html);
  14. });
  15. }
  16. html = $('body').html();
  17. }
  18. return html;
  19. };
  20. renderer.paragraph = function(text) {
  21. let isHtml = /<[a-z][\s\S]*>/i.test(text);
  22. if (isHtml) return text + '\n';
  23. else return '<p>' + text + '</p>\n';
  24. };
  25.  
  26. module.exports = renderer;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement