Skip to content

Commit 4a63657

Browse files
committed
Implement markdown-it token attrSet() method ourselves for compatibility with markdown-it>=4.0
1 parent f03367c commit 4a63657

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@ module.exports = function(md, options) {
99
for (var i = 2; i < tokens.length; i++) {
1010
if (isTodoItem(tokens, i)) {
1111
todoify(tokens[i], state.Token);
12-
tokens[i-2].attrSet('class', 'task-list-item');
13-
tokens[parentToken(tokens, i-2)].attrSet('class', 'task-list');
12+
attrSet(tokens[i-2], 'class', 'task-list-item');
13+
attrSet(tokens[parentToken(tokens, i-2)], 'class', 'task-list');
1414
}
1515
}
1616
});
1717
};
1818

19+
function attrSet(token, name, value) {
20+
var index = token.attrIndex(name);
21+
var attr = [name, value];
22+
23+
if (index < 0) {
24+
token.attrPush(attr);
25+
} else {
26+
token.attrs[index] = attr;
27+
}
28+
}
29+
1930
function parentToken(tokens, index) {
2031
var targetLevel = tokens[index].level - 1;
2132
for (var i = index - 1; i >= 0; i--) {

0 commit comments

Comments
 (0)