diff --git a/lib/parser_inline.js b/lib/parser_inline.js index 2010b55d..26676b8d 100644 --- a/lib/parser_inline.js +++ b/lib/parser_inline.js @@ -24,6 +24,7 @@ var _rules = [ [ 'sub', require('./rules_inline/sub') ], [ 'sup', require('./rules_inline/sup') ], [ 'links', require('./rules_inline/links') ], + [ 'checkbox', require('./rules_inline/checkbox') ], [ 'footnote_inline', require('./rules_inline/footnote_inline') ], [ 'footnote_ref', require('./rules_inline/footnote_ref') ], [ 'autolink', require('./rules_inline/autolink') ], diff --git a/lib/rules.js b/lib/rules.js index 47aa730c..2130032f 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -163,6 +163,13 @@ rules.link_close = function (/* tokens, idx, options, env */) { return ''; }; +/** + * Checkbox + */ +rules.checkbox = function (tokens, idx /*, options, env */) { + return ''; +}; + /** * Images */ diff --git a/lib/rules_inline/checkbox.js b/lib/rules_inline/checkbox.js new file mode 100644 index 00000000..103c799d --- /dev/null +++ b/lib/rules_inline/checkbox.js @@ -0,0 +1,39 @@ +// Process [x] Checkboxes + +'use strict'; + +module.exports = function links(state /*, silent */) { + var pos = state.pos; + var maxpos = state.posMax; + if (pos === maxpos) { + return false; + } + if (state.src.charCodeAt(pos) !== 91) { + return false; + } + ++pos; + if (state.src.charCodeAt(pos) === 93) { + state.push({ + type: 'checkbox', + checked: false, + level: state.level + }); + state.pos = pos + 1; + return true; + } + if (state.src.charCodeAt(pos) === 120 || state.src.charCodeAt(pos) === 88 || state.src.charCodeAt(pos) === 32) { + var checked = (state.src.charCodeAt(pos) !== 32); + ++pos; + if (state.src.charCodeAt(pos) !== 93) { + return false; + } + state.push({ + type: 'checkbox', + checked: checked, + level: state.level + }); + state.pos = pos + 1; + return true; + } + return false; +}; diff --git a/test/fixtures/remarkable/checkbox.txt b/test/fixtures/remarkable/checkbox.txt new file mode 100644 index 00000000..098531aa --- /dev/null +++ b/test/fixtures/remarkable/checkbox.txt @@ -0,0 +1,6 @@ +[x] Checked +[ ] Not checked + +# List +- [ ] Not checked +- [x] Checked \ No newline at end of file