From 1a4b2e5f014adedbc96a75787eff3750e251436f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 15 May 2018 23:11:40 +0200 Subject: [PATCH] Add fork of markdown-it-checkboxes to legacy scripts folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- js/legacy/markdown-it-checkbox.js | 110 ++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 js/legacy/markdown-it-checkbox.js diff --git a/js/legacy/markdown-it-checkbox.js b/js/legacy/markdown-it-checkbox.js new file mode 100644 index 000000000..3f195748d --- /dev/null +++ b/js/legacy/markdown-it-checkbox.js @@ -0,0 +1,110 @@ +var _, checkboxReplace; + +_ = require('underscore'); + +checkboxReplace = function(md, options, Token) { + "use strict"; + var arrayReplaceAt, createTokens, defaults, lastId, pattern, splitTextToken; + arrayReplaceAt = md.utils.arrayReplaceAt; + lastId = 0; + defaults = { + divWrap: false, + divClass: 'checkbox', + idPrefix: 'checkbox' + }; + options = _.extend(defaults, options); + pattern = /\[(X|\s|\_|\-)\]\s(.*)/i; + createTokens = function(checked, label, Token) { + var id, idNumeric, nodes, token; + nodes = []; + + /** + *
+ */ + if (options.divWrap) { + token = new Token("checkbox_open", "div", 1); + token.attrs = [["class", options.divClass]]; + nodes.push(token); + } + + /** + * + */ + id = options.idPrefix + lastId; + idNumeric = lastId; + lastId += 1; + token = new Token("checkbox_input", "input", 0); + token.attrs = [["type", "checkbox"], ["id", id], ["data-id", idNumeric]]; + if (checked === true) { + token.attrs.push(["checked", "true"]); + } + nodes.push(token); + + /** + *