2
0

renderer.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const md = require('markdown-it')
  2. const mdAnchor = require('markdown-it-anchor')
  3. const _ = require('lodash')
  4. const uslug = require('uslug')
  5. const quoteStyles = {
  6. Chinese: '””‘’',
  7. English: '“”‘’',
  8. French: ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'],
  9. German: '„“‚‘',
  10. Greek: '«»‘’',
  11. Japanese: '「」「」',
  12. Hungarian: '„”’’',
  13. Polish: '„”‚‘',
  14. Portuguese: '«»‘’',
  15. Russian: '«»„“',
  16. Spanish: '«»‘’',
  17. Swedish: '””’’'
  18. }
  19. module.exports = {
  20. async render() {
  21. const mkdown = md({
  22. html: this.config.allowHTML,
  23. breaks: this.config.linebreaks,
  24. linkify: this.config.linkify,
  25. typographer: this.config.typographer,
  26. quotes: _.get(quoteStyles, this.config.quotes, quoteStyles.English),
  27. highlight(str, lang) {
  28. return `<pre><code class="language-${lang}">${_.escape(str)}</code></pre>`
  29. }
  30. })
  31. mkdown.use(mdAnchor, {
  32. slugify: s => uslug(s),
  33. permalink: true,
  34. permalinkClass: 'toc-anchor',
  35. permalinkSymbol: '¶',
  36. permalinkBefore: true
  37. })
  38. for (let child of this.children) {
  39. const renderer = require(`../${_.kebabCase(child.key)}/renderer.js`)
  40. renderer.init(mkdown, child.config)
  41. }
  42. return mkdown.render(this.input)
  43. }
  44. }