mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-18 18:33:42 +00:00
Optimize note tag
This commit is contained in:
parent
d19109a7b4
commit
48a9d1330c
@ -7,19 +7,19 @@
|
||||
module.exports = ctx => function(args, content) {
|
||||
const keywords = ['default', 'primary', 'info', 'success', 'warning', 'danger', 'no-icon'];
|
||||
const className = [];
|
||||
const summary = [];
|
||||
args.forEach((arg, index) => {
|
||||
if (index > 2 || !keywords.includes(arg)) {
|
||||
summary.push(arg);
|
||||
for (let i = 0; i < 2; i++) {
|
||||
if (keywords.includes(args[0])) {
|
||||
className.push(args.shift());
|
||||
} 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}
|
||||
</details>`;
|
||||
};
|
||||
|
||||
@ -50,6 +50,14 @@ ${result}
|
||||
</summary>
|
||||
${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>`);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user