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'; '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; const tabBlock = /<!--\s*tab (.*?)\s*-->\n([\w\W\s\S]*?)<!--\s*endtab\s*-->/g;
args = args.join(' ').split(','); args = args.join(' ').split(',');
const tabName = args[0]; const tabName = args[0];
const tabActive = Number(args[1]) || 0; const tabActive = Number(args[1]) || 0;
let match;
let tabId = 0; let tabId = 0;
let tabNav = ''; let tabNav = '';
let tabContent = ''; let tabContent = '';
if (!tabName) ctx.log.warn('Tabs block must have unique name!'); 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 [caption = '', icon = ''] = match[1].split('@');
let postContent = match[2]; let postContent = match[2];