renderer.js 1.0 KB

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