Use String.prototype.matchAll

This commit is contained in:
Mimi 2021-03-25 15:20:55 +08:00
parent 17bd19d268
commit eefc25de1a

View File

@ -4,21 +4,21 @@
'use strict';
module.exports = ctx => function(args, content) {
module.exports = ctx => function(args, content = '') {
const tabBlock = /<!--\s*tab (.*?)\s*-->\n([\w\W\s\S]*?)<!--\s*endtab\s*-->/g;
args = args.join(' ').split(',');
const tabName = args[0];
const tabActive = Number(args[1]) || 0;
let match;
let tabId = 0;
let tabNav = '';
let tabContent = '';
if (!tabName) ctx.log.warn('Tabs block must have unique name!');
const matches = content.matchAll(tabBlock);
while ((match = tabBlock.exec(content)) !== null) {
for (const match of matches) {
let [caption = '', icon = ''] = match[1].split('@');
let postContent = match[2];