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.

52 lines
1.4 KiB

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