fix: convert page - handle tabsets

This commit is contained in:
NGPixel
2021-04-02 17:30:04 -04:00
parent 84b927915e
commit f55caab359
3 changed files with 306 additions and 141 deletions

View File

@@ -520,8 +520,35 @@ module.exports = class Page extends Model {
})
if ($.root().children().length > 0) {
// Remove header anchors
$('.toc-anchor').remove()
// Attempt to convert tabsets
$('tabset').each((tabI, tabElm) => {
const tabHeaders = []
// -> Extract templates
$(tabElm).children('template').each((tmplI, tmplElm) => {
if ($(tmplElm).attr('v-slot:tabs') === '') {
$(tabElm).before('<ul class="tabset-headers">' + $(tmplElm).html() + '</ul>')
} else {
$(tabElm).after('<div class="markdown-tabset">' + $(tmplElm).html() + '</div>')
}
})
// -> Parse tab headers
$(tabElm).prev('.tabset-headers').children((i, elm) => {
tabHeaders.push($(elm).html())
})
$(tabElm).prev('.tabset-headers').remove()
// -> Inject tab headers
$(tabElm).next('.markdown-tabset').children((i, elm) => {
if (tabHeaders.length > i) {
$(elm).prepend(`<h2>${tabHeaders[i]}</h2>`)
}
})
$(tabElm).next('.markdown-tabset').prepend('<h1>Tabset</h1>')
$(tabElm).remove()
})
convertedContent = $.html('body').replace('<body>', '').replace('</body>', '').replace(/&#x([0-9a-f]{1,6});/ig, (entity, code) => {
code = parseInt(code, 16)