renderer.js 945 B

123456789101112131415161718192021222324252627
  1. const _ = require('lodash')
  2. module.exports = {
  3. async init($, config) {
  4. for (let i = 1; i < 6; i++) {
  5. $(`h${i}.tabset`).each((idx, elm) => {
  6. let content = `<tabset>`
  7. let tabs = []
  8. let tabContents = []
  9. $(elm).nextUntil(_.times(i, t => `h${t + 1}`).join(', '), `h${i + 1}`).each((hidx, hd) => {
  10. tabs.push(`<li>${$(hd).html()}</li>`)
  11. let tabContent = ''
  12. $(hd).nextUntil(_.times(i + 1, t => `h${t + 1}`).join(', ')).each((cidx, celm) => {
  13. tabContent += $.html(celm)
  14. $(celm).remove()
  15. })
  16. tabContents.push(`<div class="tabset-panel">${tabContent}</div>`)
  17. $(hd).remove()
  18. })
  19. content += `<template v-slot:tabs>${tabs.join('')}</template>`
  20. content += `<template v-slot:content>${tabContents.join('')}</template>`
  21. content += `</tabset>`
  22. $(elm).replaceWith($(content))
  23. })
  24. }
  25. }
  26. }