Skip to content

Commit 8ebf24d

Browse files
committed
Support {enabled: true} option, to leave the rendered checkboxes enabled
1 parent 1737754 commit 8ebf24d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
// https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments
44
// https://github.com/blog/1825-task-lists-in-all-markdown-documents
55

6+
var disableCheckboxes = true;
7+
68
module.exports = function(md, options) {
9+
if (options && options.enabled) {
10+
disableCheckboxes = false;
11+
}
12+
713
md.core.ruler.after('inline', 'github-task-lists', function(state) {
814
var tokens = state.tokens;
915
for (var i = 2; i < tokens.length; i++) {
@@ -52,10 +58,11 @@ function todoify(token, TokenConstructor) {
5258

5359
function makeCheckbox(token, TokenConstructor) {
5460
var checkbox = new TokenConstructor('html_inline', '', 0);
61+
var disabledAttr = disableCheckboxes ? ' disabled="" ' : '';
5562
if (token.content.indexOf('[ ]') === 0) {
56-
checkbox.content = '<input class="task-list-item-checkbox" disabled="" type="checkbox">';
63+
checkbox.content = '<input class="task-list-item-checkbox"' + disabledAttr + 'type="checkbox">';
5764
} else if (token.content.indexOf('[x]') === 0 || token.content.indexOf('[X]') === 0) {
58-
checkbox.content = '<input class="task-list-item-checkbox" checked="" disabled="" type="checkbox">';
65+
checkbox.content = '<input class="task-list-item-checkbox" checked=""' + disabledAttr + 'type="checkbox">';
5966
}
6067
return checkbox;
6168
}

test/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@ describe('markdown-it-task-lists', function() {
4646
assert.equal(shouldBeChecked, $.ordered('input[type=checkbox].task-list-item-checkbox:checked').length);
4747
});
4848

49-
it('always disables the rendered checkboxes', function () {
49+
it('disables the rendered checkboxes', function () {
5050
assert(!$.bullet('input[type=checkbox].task-list-item-checkbox:not([disabled])').length);
5151
});
5252

53+
it('enables the rendered checkboxes when options.enabled is truthy', function () {
54+
var enabledParser = md().use(taskLists, {enabled: true});
55+
var $$ = cheerio.load(enabledParser.render(fixtures.ordered));
56+
assert($$('input[type=checkbox].task-list-item-checkbox:not([disabled])').length > 0);
57+
});
58+
5359
it('does NOT render [ ], [ x], [x ], or [ x ] as checkboxes', function () {
5460
var html = $.dirty.html();
5561
assert(~html.indexOf('[ ]'));

0 commit comments

Comments
 (0)