breakdance-checklist
Version:
Plugin that adds checklist rendering support to breakdance, similar to task lists in github-flavored-markdown.
43 lines (35 loc) • 988 B
JavaScript
;
var get = require('get-value');
module.exports = function(options) {
return function(breakdance) {
// overrides the built-in `input` handler
breakdance.set('input', function(node) {
var type = get(node, 'attribs.type');
var prefix = '';
if (get(node.attribs, 'checked') === '') {
type = 'checkbox checked';
}
if (!this.isInside(node.parent, 'li')) {
prefix = '* ';
var cls = get(node, 'parent.attribs.class');
var m = /checkbox\s*(checked|active|enabled)?/.exec(cls);
if (m) {
type = m[1] ? 'checkbox checked' : 'checkbox';
}
}
switch (type) {
case 'checkbox checked':
case 'checkbox active':
this.emit(prefix + '[x] ', node);
break;
case 'checkbox':
this.emit(prefix + '[ ] ', node);
break;
default: {
this.emit('', node);
break;
}
}
});
};
};