renderer.js 1.2 KB

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