mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-20 19:02:33 +00:00
Optimize note tag
This commit is contained in:
parent
d19109a7b4
commit
48a9d1330c
@ -7,19 +7,19 @@
|
|||||||
module.exports = ctx => function(args, content) {
|
module.exports = ctx => function(args, content) {
|
||||||
const keywords = ['default', 'primary', 'info', 'success', 'warning', 'danger', 'no-icon'];
|
const keywords = ['default', 'primary', 'info', 'success', 'warning', 'danger', 'no-icon'];
|
||||||
const className = [];
|
const className = [];
|
||||||
const summary = [];
|
for (let i = 0; i < 2; i++) {
|
||||||
args.forEach((arg, index) => {
|
if (keywords.includes(args[0])) {
|
||||||
if (index > 2 || !keywords.includes(arg)) {
|
className.push(args.shift());
|
||||||
summary.push(arg);
|
|
||||||
} else {
|
} else {
|
||||||
className.push(arg);
|
break;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
content = ctx.render.renderSync({ text: content, engine: 'markdown' });
|
|
||||||
if (summary.length === 0) {
|
|
||||||
return `<div class="note ${args.join(' ')}">${content}</div>`;
|
|
||||||
}
|
}
|
||||||
return `<details class="note ${className.join(' ')}"><summary>${ctx.render.renderSync({ text: summary.join(' '), engine: 'markdown' })}</summary>
|
|
||||||
|
content = ctx.render.renderSync({ text: content, engine: 'markdown' });
|
||||||
|
if (args.length === 0) {
|
||||||
|
return `<div class="note ${className.join(' ')}">${content}</div>`;
|
||||||
|
}
|
||||||
|
return `<details class="note ${className.join(' ')}"><summary>${ctx.render.renderSync({ text: args.join(' '), engine: 'markdown' })}</summary>
|
||||||
${content}
|
${content}
|
||||||
</details>`;
|
</details>`;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -50,6 +50,14 @@ ${result}
|
|||||||
</summary>
|
</summary>
|
||||||
${result}
|
${result}
|
||||||
|
|
||||||
|
</details>`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keywords in summary', () => {
|
||||||
|
postNote(['It\'s', 'danger'], content).should.eql(`<details class="note "><summary><p>It’s danger</p>
|
||||||
|
</summary>
|
||||||
|
${result}
|
||||||
|
|
||||||
</details>`);
|
</details>`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user