Fix checkbox matching

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-10-11 15:18:37 +02:00
parent 7cb5045dff
commit 2bd77fd2ce
4 changed files with 32 additions and 15 deletions

View File

@@ -17,11 +17,15 @@ checkboxReplace = function(md, options, Token) {
idPrefix: 'checkbox'
};
options = Object.assign(defaults, options);
pattern = /\[(X|\s|\_|\-)\]\s(.*)/i;
createTokens = function(checked, label, Token) {
pattern = /(.*?)(\[(X|\s|\_|\-)\])(.*)/igm;
createTokens = function(checked, label, Token, before) {
var id, idNumeric, nodes, token;
nodes = [];
token = new Token("text", "", 0);
token.content = before;
nodes.push(token);
/**
* <div class="checkbox">
*/
@@ -42,6 +46,7 @@ checkboxReplace = function(md, options, Token) {
if (checked === true) {
token.attrs.push(["checked", "true"]);
}
token.attrs.push(["class", "checkbox"]);
nodes.push(token);
/**
@@ -68,19 +73,20 @@ checkboxReplace = function(md, options, Token) {
return nodes;
};
splitTextToken = function(original, Token) {
var checked, label, matches, text, value;
var checked, label, matches, text, value, before;
text = original.content;
matches = text.match(pattern);
matches = pattern.exec(text);
if (matches === null) {
return original;
}
checked = false;
value = matches[1];
label = matches[2];
before = matches[1];
value = matches[3];
label = matches[4];
if (value === "X" || value === "x") {
checked = true;
}
return createTokens(checked, label, Token);
return createTokens(checked, label, Token, before);
};
return function(state) {
lastId = 0;