mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Added flag to $tw.utils.parseStringArray to allow non-unique entries (#2027)
* Added flag to $tw.utils.parseStringArray to allow non-unique entries With this change if you use $tw.utils.parseStringArray(list) you get identical behavior to before and enforces uniqueness in lists, but if you use $tw.utils.parseStringArray(list,true) it allows duplicate values in the list. Because of how JavaScript handles overloaded functions this shouldn't have any affect on existing code that just passes one argument to the function. * Update to hopefully remove merge conflicts
This commit is contained in:
parent
c0c1b557eb
commit
baddd89abb
@ -268,7 +268,7 @@ $tw.utils.stringifyList = function(value) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Parse a string array from a bracketted list. For example "OneTiddler [[Another Tiddler]] LastOne"
|
// Parse a string array from a bracketted list. For example "OneTiddler [[Another Tiddler]] LastOne"
|
||||||
$tw.utils.parseStringArray = function(value) {
|
$tw.utils.parseStringArray = function(value, allowDuplicate) {
|
||||||
if(typeof value === "string") {
|
if(typeof value === "string") {
|
||||||
var memberRegExp = /(?:^|[^\S\xA0])(?:\[\[(.*?)\]\])(?=[^\S\xA0]|$)|([\S\xA0]+)/mg,
|
var memberRegExp = /(?:^|[^\S\xA0])(?:\[\[(.*?)\]\])(?=[^\S\xA0]|$)|([\S\xA0]+)/mg,
|
||||||
results = [], names = {},
|
results = [], names = {},
|
||||||
@ -277,7 +277,7 @@ $tw.utils.parseStringArray = function(value) {
|
|||||||
match = memberRegExp.exec(value);
|
match = memberRegExp.exec(value);
|
||||||
if(match) {
|
if(match) {
|
||||||
var item = match[1] || match[2];
|
var item = match[1] || match[2];
|
||||||
if(item !== undefined && !$tw.utils.hop(names,item)) {
|
if(item !== undefined && (!$tw.utils.hop(names,item) || allowDuplicate)) {
|
||||||
results.push(item);
|
results.push(item);
|
||||||
names[item] = true;
|
names[item] = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user