[fix] syntax errors

This commit is contained in:
xaoxuu 2022-12-11 16:38:36 +08:00
parent 851c23cedc
commit 7963ea7289
2 changed files with 33 additions and 33 deletions

View File

@ -1,5 +1,5 @@
<script type="text/javascript"> <script type="text/javascript">
stellar = { const stellar = {
// 懒加载 css https://github.com/filamentgroup/loadCSS // 懒加载 css https://github.com/filamentgroup/loadCSS
loadCSS: (href, before, media, attributes) => { loadCSS: (href, before, media, attributes) => {
var doc = window.document; var doc = window.document;

View File

@ -4,56 +4,56 @@
'use strict'; 'use strict';
var tab_index = 0; var tab_index = 0
module.exports = ctx => function(args, content = '') { module.exports = ctx => function(args, content = '') {
var el = '';
var arr = content.split(/<!--\s*tab (.*?)\s*-->/g).filter(item => item.trim().length > 0) var arr = content.split(/<!--\s*tab (.*?)\s*-->/g).filter(item => item.trim().length > 0)
if (arr.length < 1) { if (arr.length < 1) {
return el; return ''
} }
var tabs = []; var tabs = []
arr.forEach((item, i) => { arr.forEach((item, i) => {
if (i % 2 == 0) { if (i % 2 == 0) {
tabs.push({ tabs.push({
header: item header: item
}); })
} else if (tabs.length > 0) { } else if (tabs.length > 0) {
var tab = tabs[tabs.length-1]; var tab = tabs[tabs.length-1]
if (tab.body == undefined) { if (tab.body == undefined) {
tab.body = item; tab.body = item
} else { } else {
tab.body += '\n' + item; tab.body += '\n' + item
} }
} }
}); })
args = ctx.args.map(args, ['active', 'align']); args = ctx.args.map(args, ['active', 'align'])
const tabName = 'tab_' + ++tab_index; const tabName = 'tab_' + ++tab_index
const tabActive = Number(args.active) || 0; const tabActive = Number(args.active) || 0
let tabId = 0; let tabId = 0
let tabNav = ''; let tabNav = ''
let tabContent = ''; let tabContent = ''
tabs.forEach((tab, i) => { tabs.forEach((tab, i) => {
let content = ctx.render.renderSync({ text: (tab.body || ''), engine: 'markdown' }).trim(); let content = ctx.render.renderSync({ text: (tab.body || ''), engine: 'markdown' }).trim()
const abbr = tabName + ' ' + ++tabId; const abbr = tabName + ' ' + ++tabId
const href = abbr.toLowerCase().split(' ').join('-'); const href = abbr.toLowerCase().split(' ').join('-')
const isActive = (tabActive > 0 && tabActive === tabId) || (tabActive === 0 && tabId === 1) ? ' active' : ''; const isActive = (tabActive > 0 && tabActive === tabId) || (tabActive === 0 && tabId === 1) ? ' active' : ''
tabNav += `<li class="tab${isActive}"><a href="#${href}">${tab.header || abbr}</a></li>`; tabNav += `<li class="tab${isActive}"><a href="#${href}">${tab.header || abbr}</a></li>`
tabContent += `<div class="tab-pane${isActive}" id="${href}">${content}</div>`; tabContent += `<div class="tab-pane${isActive}" id="${href}">${content}</div>`
}); })
tabNav = `<ul class="nav-tabs">${tabNav}</ul>`; tabNav = `<ul class="nav-tabs">${tabNav}</ul>`
tabContent = `<div class="tab-content">${tabContent}</div>`; tabContent = `<div class="tab-content">${tabContent}</div>`
el += '<div class="tag-plugin tabs"'; var el = ''
el += '<div class="tag-plugin tabs"'
if (args.align != undefined) { if (args.align != undefined) {
el += ' align="' + args.align + '"'; el += ' align="' + args.align + '"'
} }
el += 'id="' + tabName.toLowerCase().split(' ').join('-') + '"'; el += 'id="' + tabName.toLowerCase().split(' ').join('-') + '"'
el += '">'; el += '>'
el += tabNav + tabContent; el += tabNav + tabContent
el += '</div>'; el += '</div>'
return el; return el
}; }