hexo-theme-volantis
Version:
Elegant and powerful theme for Hexo.
64 lines (62 loc) • 1.69 kB
JavaScript
;
function postCheckbox(args) {
if (/::/g.test(args)) {
args = args.join(' ').split('::');
}
else {
args = args.join(' ').split(',');
}
var cls = '';
var text = '';
var checked = false;
if (args.length > 1) {
cls = (args[0] || '').trim();
if (cls.length > 0) {
cls = ' ' + cls;
}
if (cls.indexOf('checked') > -1) {
checked = true;
}
text = (args[1] || '').trim();
} else if (args.length > 0) {
text = (args[0] || '').trim();
}
if (text.length > 0) {
return `<div class='checkbox${cls}'><input type="checkbox" ${checked ? 'checked="checked"' : ''}/>
${hexo.render.renderSync({ text: text, engine: 'markdown' }).split('\n').join('')}
</div>`;
}
}
function postRadio(args) {
if (/::/g.test(args)) {
args = args.join(' ').split('::');
}
else {
args = args.join(' ').split(',');
}
var cls = '';
var text = '';
var checked = false;
if (args.length > 1) {
cls = (args[0] || '').trim();
if (cls.length > 0) {
cls = ' ' + cls;
}
if (cls.indexOf('checked') > -1) {
checked = true;
}
text = (args[1] || '').trim();
} else if (args.length > 0) {
text = (args[0] || '').trim();
}
if (text.length > 0) {
return `<div class='checkbox${cls}'><input type="radio" ${checked ? 'checked="checked"' : ''}/>
${hexo.render.renderSync({ text: text, engine: 'markdown' }).split('\n').join('')}
</div>`;
}
}
// {% checkbox text %}
// {% checkbox checked, text %}
// {% checkbox color checked, text %}
hexo.extend.tag.register('checkbox', postCheckbox);
hexo.extend.tag.register('radio', postRadio);