renderer.js 641 B

1234567891011121314151617181920212223242526
  1. const asciidoctor = require('asciidoctor')()
  2. const cheerio = require('cheerio')
  3. module.exports = {
  4. async render() {
  5. const html = asciidoctor.convert(this.input, {
  6. standalone: false,
  7. safe: this.config.safeMode,
  8. attributes: {
  9. showtitle: true,
  10. icons: 'font'
  11. }
  12. })
  13. const $ = cheerio.load(html, {
  14. decodeEntities: true
  15. })
  16. $('pre.highlight > code.language-diagram').each((i, elm) => {
  17. const diagramContent = Buffer.from($(elm).html(), 'base64').toString()
  18. $(elm).parent().replaceWith(`<pre class="diagram">${diagramContent}</div>`)
  19. })
  20. return $.html()
  21. }
  22. }