Fixed some problems

pull/1026/head
HMLTFan 2022-01-30 12:53:25 +08:00
parent 3a8d5fa6dc
commit da442f6c4f
2 changed files with 105 additions and 98 deletions

View File

@ -20,6 +20,7 @@
let title = ''; let title = '';
let size = ''; let size = '';
let header = ''; let header = '';
args.forEach(element => { args.forEach(element => {
const key = element.split(':')[0].trim(); const key = element.split(':')[0].trim();
const value = element.split(':')[1].trim(); const value = element.split(':')[1].trim();
@ -45,8 +46,9 @@
<div class="message-header"> <div class="message-header">
${hexo.render.renderSync({text: icon + title, engine: 'markdown'})} ${hexo.render.renderSync({text: icon + title, engine: 'markdown'})}
</div> </div>
` `;
} }
return ` return `
<article class="message is-${color}${size}"> <article class="message is-${color}${size}">
${header} ${header}
@ -56,4 +58,4 @@
</article> </article>
`; `;
}, { ends: true }); }, { ends: true });
} };

View File

@ -17,12 +17,13 @@
* <!-- activeitem hello 'Hello' -->This is hello.<!-- enditem --> * <!-- activeitem hello 'Hello' -->This is hello.<!-- enditem -->
* {% endmessage %} * {% endmessage %}
*/ */
module.exports = function(hexo) {
hexo.extend.tag.register('tabs', function(args, content) { hexo.extend.tag.register('tabs', function(args, content) {
let id = ''; let id = '';
let behavior = ''; let behavior = '';
let size = ''; let size = '';
let style = ''; let style = '';
let contentEl = content;
args.forEach(element => { args.forEach(element => {
const key = element.split(':')[0].trim(); const key = element.split(':')[0].trim();
const value = element.split(':')[1].trim(); const value = element.split(':')[1].trim();
@ -58,17 +59,20 @@
let hidden = ' is-hidden'; let hidden = ' is-hidden';
let icon = ''; let icon = '';
var contentString = match[5].replace(/^\n?|[ \n\t]*$/g, ''); var contentString = match[5].replace(/^\n?|[ \n\t]*$/g, '');
if (match[1] === 'active') { if (match[1] === 'active') {
active = ' class="is-active"'; active = ' class="is-active"';
hidden = ''; hidden = '';
} }
if (match[3] === 'active' && match[3].substring(1) !== '') icon = `<span class="icon is-small"><i class="fas fa-${match[3].substring(1)}" aria-hidden="true"></i></span>`; if (match[3] === 'active' && match[3].substring(1) !== '') icon = `<span class="icon is-small"><i class="fas fa-${match[3].substring(1)}" aria-hidden="true"></i></span>`;
if (contentString.match(/^ {4}|^\t{1}/gm) !== null && contentString.match(/^ {4}|^\t{1}/gm).length === contentString.split('\n').length) contentString = contentString.replace(/^ {4}|^\t{1}/g, '').replace(/\n {4}|\n\t{1}/g, '\n'); if (contentString.match(/^ {4}|^\t{1}/gm) !== null && contentString.match(/^ {4}|^\t{1}/gm).length === contentString.split('\n').length) contentString = contentString.replace(/^ {4}|^\t{1}/g, '').replace(/\n {4}|\n\t{1}/g, '\n');
tabsEl += ` tabsEl += `
<li id="${match[2].substring(1)}"${active}"> <li id="${match[2].substring(1)}"${active}">
<a onclick="switchTab(this)">${hexo.render.renderSync({text: icon + match[4].substring(2, match[4].length - 1), engine: 'markdown'})}</a> <a onclick="switchTab(this)">${hexo.render.renderSync({text: icon + match[4].substring(2, match[4].length - 1), engine: 'markdown'})}</a>
</li> </li>
`; `;
contentEl += ` contentEl += `
<div id="${match[2].substring(1)}" class="tab-content${hidden}"> <div id="${match[2].substring(1)}" class="tab-content${hidden}">
${hexo.render.renderSync({text: contentString, engine: 'markdown'})} ${hexo.render.renderSync({text: contentString, engine: 'markdown'})}
@ -116,3 +120,4 @@ hexo.extend.injector.register(
</script> </script>
` `
); );
};