1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Improve handling for titles starting with +-~= (#4084) (#4087)

* $tw.utils.stringifyList will wrap tiddlers starting with `+-~=` in brackets.
This commit is contained in:
Cameron Fischer 2019-08-24 06:35:03 -04:00 committed by Jeremy Ruston
parent fada96651e
commit 67066fe86e
2 changed files with 16 additions and 5 deletions

View File

@ -314,13 +314,13 @@ $tw.utils.parseDate = function(value) {
// Stringify an array of tiddler titles into a list string // Stringify an array of tiddler titles into a list string
$tw.utils.stringifyList = function(value) { $tw.utils.stringifyList = function(value) {
if($tw.utils.isArray(value)) { if($tw.utils.isArray(value)) {
var result = []; var result = new Array(value.length);
for(var t=0; t<value.length; t++) { for(var t=0, l=value.length; t<l; t++) {
var entry = value[t] || ""; var entry = value[t] || "";
if(entry.indexOf(" ") !== -1) { if(entry.indexOf(" ") !== -1 || "+-~=".indexOf(entry[0]) !== -1) {
result.push("[[" + entry + "]]"); result[t] = "[[" + entry + "]]";
} else { } else {
result.push(entry); result[t] = entry;
} }
} }
return result.join(" "); return result.join(" ");

View File

@ -25,6 +25,17 @@ describe("Utility tests", function() {
expect(psa(" [[Tidd\u00a0ler8]] two ")).toEqual(["Tidd\u00a0ler8","two"]); expect(psa(" [[Tidd\u00a0ler8]] two ")).toEqual(["Tidd\u00a0ler8","two"]);
}); });
it("should handle stringifying a string array", function() {
var str = $tw.utils.stringifyList;
expect(str([])).toEqual("");
expect(str(["Tiddler8"])).toEqual("Tiddler8");
expect(str(["Tiddler8 "])).toEqual("[[Tiddler8 ]]");
expect(str(["A+B", "A-B", "A=B"])).toEqual("A+B A-B A=B");
expect(str(["A B"])).toEqual("[[A B]]");
expect(str(["+T", "-T", "~T", "=T", "$T"])).toEqual("[[+T]] [[-T]] [[~T]] [[=T]] $T");
expect(str(["A", "", "B"])).toEqual("A B");
});
it("should handle formatting a date string", function() { it("should handle formatting a date string", function() {
var fds = $tw.utils.formatDateString, var fds = $tw.utils.formatDateString,
// nov is month: 10! // nov is month: 10!