config.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* eslint-disable @typescript-eslint/no-var-requires */
  2. /*markdown-it的配置文件*/
  3. const Config = require('markdown-it-chain'); //链式配置
  4. const anchorPlugin = require('markdown-it-anchor'); //给页眉添加锚点
  5. const slugify = require('transliteration').slugify;
  6. const hljs = require('highlight.js');
  7. const containers = require('./containers');
  8. const overWriteFenceRule = require('./fence');
  9. const config = new Config();
  10. const highlight = (str, lang) => {
  11. if (!lang || !hljs.getLanguage(lang)) {
  12. return '<pre><code class="hljs">' + str + '</code></pre>';
  13. }
  14. const html = hljs.highlight(lang, str, true, undefined).value;
  15. return `<pre><code class="hljs language-${lang}">${html}</code></pre>`;
  16. };
  17. config.options
  18. .html(true)
  19. .highlight(highlight)
  20. .end()
  21. // .plugin('anchor').use(anchorPlugin, [
  22. // {
  23. // level: 2,
  24. // slugify: slugify,
  25. // permalink: false,
  26. // permalinkBefore: false,
  27. // },
  28. // ]).end()
  29. .plugin('containers')
  30. .use(containers)
  31. .end();
  32. const md = config.toMd();
  33. overWriteFenceRule(md);
  34. module.exports = md;