|
5 | 5 |
|
6 | 6 | var disableCheckboxes = true; |
7 | 7 | var useLabelWrapper = false; |
| 8 | +var useLabelAfter = false; |
8 | 9 |
|
9 | 10 | module.exports = function(md, options) { |
10 | 11 | if (options) { |
11 | 12 | disableCheckboxes = !options.enabled; |
12 | 13 | useLabelWrapper = !!options.label; |
| 14 | +useLabelAfter = !!options.labelAfter; |
13 | 15 | } |
14 | 16 |
|
15 | 17 | md.core.ruler.after('inline', 'github-task-lists', function(state) { |
@@ -58,8 +60,17 @@ function todoify(token, TokenConstructor) { |
58 | 60 | token.content = token.content.slice(3); |
59 | 61 |
|
60 | 62 | if (useLabelWrapper) { |
61 | | -token.children.unshift(beginLabel(TokenConstructor)); |
62 | | -token.children.push(endLabel(TokenConstructor)); |
| 63 | +if (useLabelAfter) { |
| 64 | +token.children.pop(); |
| 65 | + |
| 66 | +// Use large random number as id property of the checkbox. |
| 67 | +var id = 'task-item-' + Math.ceil(Math.random() * (10000 * 1000) - 1000); |
| 68 | +token.children[0].content = token.children[0].content.slice(0, -1) + ' id="' + id + '">'; |
| 69 | +token.children.push(afterLabel(token.content, id, TokenConstructor)); |
| 70 | +} else { |
| 71 | +token.children.unshift(beginLabel(TokenConstructor)); |
| 72 | +token.children.push(endLabel(TokenConstructor)); |
| 73 | +} |
63 | 74 | } |
64 | 75 | } |
65 | 76 |
|
@@ -88,6 +99,13 @@ function endLabel(TokenConstructor) { |
88 | 99 | return token; |
89 | 100 | } |
90 | 101 |
|
| 102 | +function afterLabel(content, id, TokenConstructor) { |
| 103 | +var token = new TokenConstructor('html_inline', '', 0); |
| 104 | +token.content = '<label class="task-list-item-label" for="' + id + '">' + content + '</label>'; |
| 105 | +token.attrs = [{for: id}]; |
| 106 | +return token; |
| 107 | +} |
| 108 | + |
91 | 109 | function isInline(token) { return token.type === 'inline'; } |
92 | 110 | function isParagraph(token) { return token.type === 'paragraph_open'; } |
93 | 111 | function isListItem(token) { return token.type === 'list_item_open'; } |
|
0 commit comments