You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

  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. for (let child of this.children) {
  32. const renderer = require(`../${_.kebabCase(child.key)}/renderer.js`)
  33. renderer.init(mkdown, child.config)
  34. }
  35. return mkdown.render(this.input)
  36. }
  37. }