├── .gitignore ├── test ├── fixtures │ ├── bullet.md │ ├── ordered.md │ ├── mixed-nested.md │ └── dirty.md └── index.js ├── LICENSE ├── package.json ├── README.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ 3 | npm-debug.log 4 | selenium-debug.log 5 | test/unit/coverage 6 | Test/e2e/reports 7 | -------------------------------------------------------------------------------- /test/fixtures/bullet.md: -------------------------------------------------------------------------------- 1 | - [ ] unchecked item 1 2 | - [ ] unchecked item 2 3 | - [ ] unchecked item 3 4 | - [x] checked item 4 5 | -------------------------------------------------------------------------------- /test/fixtures/ordered.md: -------------------------------------------------------------------------------- 1 | 1. [x] checked ordered 1 2 | 2. [ ] unchecked ordered 2 3 | 3. [X] checked ordered 3 4 | 4. [ ] unchecked ordered 4 5 | 5. [x] checked ordered non-breaking-space 5 6 | 6. [ ] unchecked ordered non-breaking-space 6 7 | 7. [X] checked ordered non-breaking-space 7 8 | 8. [ ] unchecked ordered non-breaking-space 8 9 | -------------------------------------------------------------------------------- /test/fixtures/mixed-nested.md: -------------------------------------------------------------------------------- 1 | # Test 1 2 | 3 | 1. foo 4 | * [ ] nested unchecked item 1 5 | * not a todo item 2 6 | * not a todo item 3 7 | * [x] nested checked item 4 8 | 2. bar 9 | 3. spam 10 | 11 | # Test 2 12 | 13 | - foo 14 | - [ ] nested unchecked item 1 15 | - [ ] nested unchecked item 2 16 | - [x] nested checked item 3 17 | - [X] nested checked item 4 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Revin Guillen 2 | Modified code Copyright (c) 2016, linsir, MIT License 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /test/fixtures/dirty.md: -------------------------------------------------------------------------------- 1 | - [ ] unchecked todo item 1 2 | - [ ] 3 | - [ ] not a todo item 2 4 | - [ x] not a todo item 3 5 | - [x ] not a todo item 4 6 | - [ x ] not a todo item 5 7 | - [x] todo item 6 8 | - [ X] not a todo item 7 9 | - [X ] not a todo item 8 10 | - [ X ] not a todo item 9 11 | - [X] todo item 10 12 | - [ ] unchecked todo item with non-breaking space 11 13 | - [ ] 14 | - [  ] not a todo item with 2 non-breaking spaces 12 15 | - [  ] not a todo item with 1 non-breaking space and 1 space 13 16 | - [  ] not a todo item with 1 space and 1 non-breaking space 14 17 | - [ x] not a todo item with non-breaking space 15 18 | - [x ] not a todo item with non-breaking space 16 19 | - [ x ] not a todo item with 2 non-breaking spaces 17 20 | - [ x ] not a todo item with 1 non-breaking space and 1 space 18 21 | - [ x ] not a todo item with 1 space and 1 non-breaking space 19 22 | - [x] todo item with non-breaking space 20 23 | - [ X] not a todo item with non-breaking space 21 24 | - [X ] not a todo item with non-breaking space 22 25 | - [ X ] not a todo item with 2 non-breaking spaces 23 26 | - [ X ] not a todo item with 1 space and 1 non-breaking space 24 27 | - [ X ] not a todo item with 1 non-breaking space and 1 space 25 28 | - [X] todo item with non-breaking space 26 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "markdown-it-task-checkbox", 3 | "version": "1.0.6", 4 | "description": "A markdown-it plugin to create GitHub-style task lists", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha --timeout 5000", 8 | "clean": "rm -Rf dist && mkdir dist", 9 | "build": "npm run clean && npm run build-dist", 10 | "build-dist": "npm run build-dist-copyright && npm run build-dist-file && npm run build-dist-min", 11 | "build-dist-copyright": "echo /*! ${npm_package_name} ${npm_package_version} ${npm_package_homepage} by ${npm_package_author} @license ${npm_package_license} \\*/ > dist/${npm_package_name}.js", 12 | "build-dist-file": "browserify ${npm_package_main} -s markdownitTaskLists >> dist/${npm_package_name}.js", 13 | "build-dist-min": "uglifyjs dist/${npm_package_name}.js -b beautify=false,ascii-only=true -c -m --preamble \"/*! ${npm_package_name} ${npm_package_version} ${npm_package_homepage} by ${npm_package_author} @license {$npm_package_license} */\" > dist/${npm_package_name}.min.js" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git@github.com:linsir/markdown-it-task-checkbox.git" 18 | }, 19 | "dependencies": {}, 20 | "devDependencies": { 21 | "browserify": "*", 22 | "cheerio": "^0.20.0", 23 | "markdown-it": "^7.0.0", 24 | "mocha": "*", 25 | "uglify": "*", 26 | "underscore": "^1.8.3" 27 | }, 28 | "keywords": [ 29 | "markdown", 30 | "markdown-it", 31 | "markdown-it-plugin", 32 | "task", 33 | "list", 34 | "todo", 35 | "checkbox" 36 | ], 37 | "author": "linsir", 38 | "license": "ISC", 39 | "bugs": { 40 | "url": "https://github.com/linsir/markdown-it-task-checkbox/issues" 41 | }, 42 | "homepage": "https://github.com/linsir/markdown-it-task-checkbox#readme" 43 | } 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # markdown-it-task-checkbox 2 | 3 | A [markdown-it](https://www.npmjs.com/package/markdown-it) plugin to create GitHub-style [task lists](https://github.com/blog/1825-task-lists-in-all-markdown-documents) 4 | 5 | Modified from and 6 | 7 | 8 | ## Usage 9 | 10 | ## Install 11 | 12 | node.js: 13 | 14 | ```bash 15 | npm install markdown-it-task-checkbox --save 16 | ``` 17 | 18 | ## Use 19 | 20 | ```js 21 | var md = require('markdown-it')() 22 | .use(require('markdown-it-task-checkbox'),{ 23 | disabled: true, 24 | divWrap: false, 25 | divClass: 'checkbox', 26 | idPrefix: 'cbx_', 27 | ulClass: 'task-list', 28 | liClass: 'task-list-item' 29 | }); 30 | 31 | md.render('- [x] unchecked') // => 32 | // 40 | ``` 41 | 42 | _Differences in browser._ If you load script directly into the page, without 43 | package system, module will add itself globally as `window.markdownitCheckbox`. 44 | 45 | ## Options 46 | 47 | 48 | ## disabled 49 | 50 | * **Type:** `Boolean` 51 | * **Default:** `true` 52 | 53 | if the value is true, the checkbox can not be selected. 54 | 55 | ## divWrap 56 | 57 | * **Type:** `Boolean` 58 | * **Default:** `false` 59 | 60 | wrap div arround checkbox. this makes it possible to use it for example with [Awesome Bootstrap Checkbox](https://github.com/flatlogic/awesome-bootstrap-checkbox/). 61 | 62 | ## divClass 63 | 64 | * **Type:** `String` 65 | * **Default:** `checkbox` 66 | 67 | classname of div wrapper. will only be used if `divWrap` is enanbled. 68 | 69 | ## idPrefix 70 | 71 | * **Type:** `String` 72 | * **Default:** `cbx_` 73 | 74 | the id of the checkboxs input contains the prefix and an incremental number starting with `0`. i.e. `cbx_1` for the 2nd checkbox. 75 | 76 | ## ulClass 77 | 78 | * **Type:** `String` 79 | * **Default:** `task-list` 80 | 81 | classname of ul wrapper. 82 | 83 | ## liClass 84 | 85 | * **Type:** `String` 86 | * **Default:** `task-list-item` 87 | 88 | classname of li wrapper. 89 | 90 | ## THANKS 91 | 92 | and 93 | 94 | ## License 95 | 96 | MIT License © 2016 Linsir 97 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | /* globals before, describe, it */ 2 | 3 | var fs = require('fs'); 4 | var assert = require('assert'); 5 | var md = require('markdown-it'); 6 | var cheerio = require('cheerio'); 7 | var taskLists = require('..'); 8 | 9 | describe('markdown-it-task-lists', function() { 10 | var fixtures = {}, rendered = {}, $ = {}, parser; 11 | 12 | before(function() { 13 | var files = { 14 | bullet: 'bullet.md', 15 | ordered: 'ordered.md', 16 | mixedNested: 'mixed-nested.md', 17 | dirty: 'dirty.md' 18 | }; 19 | 20 | parser = md().use(taskLists); 21 | 22 | for (var key in files) { 23 | fixtures[key] = fs.readFileSync(__dirname + '/fixtures/' + files[key]).toString(); 24 | rendered[key] = parser.render(fixtures[key]); 25 | $[key] = cheerio.load(rendered[key]); 26 | } 27 | }); 28 | 29 | it('renders tab-indented code differently than default markdown-it', function() { 30 | var parserDefault = md(); 31 | var parserWithPlugin = md().use(taskLists); 32 | assert.notEqual(parserDefault.render(fixtures.bullet), parserWithPlugin.render(fixtures.bullet)); 33 | }); 34 | 35 | it('adds input.task-list-item-checkbox in items', function () { 36 | assert(~$.bullet('input.task-list-item-checkbox').length); 37 | }); 38 | 39 | it('renders items marked up as [ ] as unchecked', function () { 40 | var shouldBeUnchecked = (fixtures.ordered.match(/[\.\*\+-]\s+\[[ \u00A0]\]/g) || []).length; 41 | assert.equal($.ordered('input[type=checkbox]:not(:checked)').length, shouldBeUnchecked); 42 | }); 43 | 44 | it('renders items marked up as [x] as checked', function () { 45 | var shouldBeChecked = (fixtures.ordered.match(/[\.\*\+-]\s+\[[Xx]\]/g) || []).length; 46 | assert.equal(shouldBeChecked, $.ordered('input[type=checkbox]:checked').length); 47 | }); 48 | 49 | it('disables the rendered checkboxes', function () { 50 | assert(!$.bullet('input[type=checkbox].task-list-item-checkbox:not([disabled])').length); 51 | }); 52 | 53 | it('enables the rendered checkboxes when options.disabled is falsy', function () { 54 | var enabledParser = md().use(taskLists, {disabled: false}); 55 | var $$ = cheerio.load(enabledParser.render(fixtures.ordered)); 56 | assert($$('input[type=checkbox]:not([disabled])').length > 0); 57 | }); 58 | 59 | it("gives the rendered list items a