1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2026-03-02 22:09:52 +00:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Saq Imtiaz
9d5b5111d0 Revert "Add locale support for sort operator (#9400)" (#9702)
This reverts commit 98a61f01bb.
2026-03-01 08:02:18 +01:00
btheado
48cff401b2 Add tests/examples for transclusion shortcut syntax (#9705) 2026-03-01 07:58:59 +01:00
Saq Imtiaz
7a866b93e3 fix: alt support for images in markdown (#9700) 2026-02-27 18:53:58 +01:00
16 changed files with 162 additions and 94 deletions

File diff suppressed because one or more lines are too long

View File

@@ -14,31 +14,31 @@ Export our filter function
*/
exports.sort = function(source,operator,options) {
var results = prepare_results(source);
options.wiki.sortTiddlers(results,operator.operands[0] || "title",operator.prefix === "!",false,false,undefined,operator.operands[1]);
options.wiki.sortTiddlers(results,operator.operand || "title",operator.prefix === "!",false,false);
return results;
};
exports.nsort = function(source,operator,options) {
var results = prepare_results(source);
options.wiki.sortTiddlers(results,operator.operands[0] || "title",operator.prefix === "!",false,true,undefined,operator.operands[1]);
options.wiki.sortTiddlers(results,operator.operand || "title",operator.prefix === "!",false,true);
return results;
};
exports.sortan = function(source, operator, options) {
var results = prepare_results(source);
options.wiki.sortTiddlers(results, operator.operands[0] || "title", operator.prefix === "!",false,false,true,operator.operands[1]);
options.wiki.sortTiddlers(results, operator.operand || "title", operator.prefix === "!",false,false,true);
return results;
};
exports.sortcs = function(source,operator,options) {
var results = prepare_results(source);
options.wiki.sortTiddlers(results,operator.operands[0] || "title",operator.prefix === "!",true,false,undefined,operator.operands[1]);
options.wiki.sortTiddlers(results,operator.operand || "title",operator.prefix === "!",true,false);
return results;
};
exports.nsortcs = function(source,operator,options) {
var results = prepare_results(source);
options.wiki.sortTiddlers(results,operator.operands[0] || "title",operator.prefix === "!",true,true,undefined,operator.operands[1]);
options.wiki.sortTiddlers(results,operator.operand || "title",operator.prefix === "!",true,true);
return results;
};

View File

@@ -369,16 +369,31 @@ Sort an array of tiddler titles by a specified field
isDescending: true if the sort should be descending
isCaseSensitive: true if the sort should consider upper and lower case letters to be different
*/
exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,isNumeric,isAlphaNumeric,locale) {
exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,isNumeric,isAlphaNumeric) {
var self = this;
if(sortField === "title") {
if(!isNumeric && !isAlphaNumeric) {
const sorter = new Intl.Collator(locale, { sensitivity: isCaseSensitive ? "variant" : "accent" });
if(isDescending) {
titles.sort((a,b) => sorter.compare(b, a));
if(isCaseSensitive) {
if(isDescending) {
titles.sort(function(a,b) {
return b.localeCompare(a);
});
} else {
titles.sort(function(a,b) {
return a.localeCompare(b);
});
}
} else {
titles.sort((a,b) => sorter.compare(a, b));
}
if(isDescending) {
titles.sort(function(a,b) {
return b.toLowerCase().localeCompare(a.toLowerCase());
});
} else {
titles.sort(function(a,b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
});
}
}
} else {
titles.sort(function(a,b) {
var x,y;
@@ -399,8 +414,14 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is
}
}
}
const sorter = new Intl.Collator(locale, { numeric: isAlphaNumeric, sensitivity: isAlphaNumeric ? "base" : isCaseSensitive ? "variant" : "accent" });
return isDescending ? sorter.compare(b, a) : sorter.compare(a, b);
if(isAlphaNumeric) {
return isDescending ? b.localeCompare(a,undefined,{numeric: true,sensitivity: "base"}) : a.localeCompare(b,undefined,{numeric: true,sensitivity: "base"});
}
if(!isCaseSensitive) {
a = a.toLowerCase();
b = b.toLowerCase();
}
return isDescending ? b.localeCompare(a) : a.localeCompare(b);
});
}
} else {
@@ -442,8 +463,14 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is
}
a = String(a);
b = String(b);
const sorter = new Intl.Collator(locale, { numeric: isAlphaNumeric, sensitivity: isAlphaNumeric ? "base" : isCaseSensitive ? "variant" : "accent" });
return isDescending ? sorter.compare(b, a) : sorter.compare(a, b);
if(isAlphaNumeric) {
return isDescending ? b.localeCompare(a,undefined,{numeric: true,sensitivity: "base"}) : a.localeCompare(b,undefined,{numeric: true,sensitivity: "base"});
}
if(!isCaseSensitive) {
a = a.toLowerCase();
b = b.toLowerCase();
}
return isDescending ? b.localeCompare(a) : a.localeCompare(b);
});
}
};

View File

@@ -1,6 +0,0 @@
created: 20251001034405510
list: A a Ä ä Z z O o Õ õ Ö ö Ü ü Y y
modified: 20251218023544134
tags:
title: Locale Example
type: text/vnd.tiddlywiki

View File

@@ -1,5 +1,5 @@
created: 20150124112340000
modified: 20251218023608468
modified: 20150124113250000
tags: [[sort Operator]] [[Operator Examples]]
title: sort Operator (Examples)
type: text/vnd.tiddlywiki
@@ -11,10 +11,3 @@ type: text/vnd.tiddlywiki
<<.operator-example 3 "one two Three four +[sort[]]">>
<<.operator-example 4 "[prefix[Tiddl]sort[text]]">>
<<.operator-example 5 "[has[created]sort[created]limit[10]]" "the oldest 10 tiddlers in the wiki">>
! Using a custom locale
The following examples shows the differences when using the sort operator with default, Swedish and Estonian locale.
<<.operator-example 6 "[list[Locale Example]sort[]]">>
<<.operator-example 7 "[list[Locale Example]sort[],[sv]]">>
<<.operator-example 8 "[list[Locale Example]sort[],[et]]">>

View File

@@ -1,15 +1,15 @@
caption: nsort
created: 20140410103123179
modified: 20251227084602319
op-input: a [[selection of titles|Title Selection]]
op-neg-output: the input, likewise sorted into descending order
op-output: the input, sorted into ascending order by field <<.field F>>, treating field values as numbers
op-parameter: accept same parameters as the [[sort Operator]]
op-parameter-name: F
op-purpose: sort the input by number field
modified: 20150203190051000
tags: [[Filter Operators]] [[Field Operators]] [[Order Operators]] [[Negatable Operators]]
title: nsort Operator
type: text/vnd.tiddlywiki
caption: nsort
op-purpose: sort the input by number field
op-input: a [[selection of titles|Title Selection]]
op-parameter: the name of a [[field|TiddlerFields]], defaulting to <<.field title>>
op-parameter-name: F
op-output: the input, sorted into ascending order by field <<.field F>>, treating field values as numbers
op-neg-output: the input, likewise sorted into descending order
Non-numeric values are treated as having a higher value than any number, and the difference between capital and lowercase letters is ignored. Compare <<.olink nsortcs>>.

View File

@@ -1,10 +1,10 @@
caption: nsortcs
created: 20140410103123179
modified: 20251227084615705
modified: 20150417125717078
op-input: a [[selection of titles|Title Selection]]
op-neg-output: the input, likewise sorted into descending order
op-output: the input, sorted into ascending order by field <<.place F>>, treating field values as numbers
op-parameter: accept same parameters as the [[sort Operator]]
op-parameter: the name of a [[field|TiddlerFields]], defaulting to <<.field title>>
op-parameter-name: F
op-purpose: sort the input titles by number field, treating upper and lower case as different
tags: [[Filter Operators]] [[Field Operators]] [[Order Operators]] [[Negatable Operators]]

View File

@@ -1,22 +1,16 @@
caption: sort
created: 20140410103123179
modified: 20251227084644651
op-input: a [[selection of titles|Title Selection]]
op-neg-output: the input, likewise sorted into descending order
op-output: the input, sorted into ascending order by field <<.field F>>, treating field values as text
op-parameter: the <<.op sort>> operator accepts 1 or 2 parameters, see below for details
op-parameter-name: F
op-purpose: sort the input by text field
modified: 20150203191228000
tags: [[Filter Operators]] [[Common Operators]] [[Field Operators]] [[Order Operators]] [[Negatable Operators]]
title: sort Operator
type: text/vnd.tiddlywiki
caption: sort
op-purpose: sort the input by text field
op-input: a [[selection of titles|Title Selection]]
op-parameter: the name of a [[field|TiddlerFields]], defaulting to <<.field title>>
op-parameter-name: F
op-output: the input, sorted into ascending order by field <<.field F>>, treating field values as text
op-neg-output: the input, likewise sorted into descending order
The difference between capital and lowercase letters is ignored. Compare <<.olink sortcs>>.
```
[sort[<field>],[<locale>]]
```
* ''field'' : the name of a [[field|TiddlerFields]], defaulting to <<.field title>>
* ''locale'': (optional). A string with a [[BCP 47 language tag|https://developer.mozilla.org/en-US/docs/Glossary/BCP_47_language_tag]]
<<.operator-examples "sort">>

View File

@@ -1,10 +1,10 @@
caption: sortan
created: 20180222071605739
modified: 20251227084439804
modified: 20180223012553446
op-input: a [[selection of titles|Title Selection]]
op-neg-output: the input, likewise sorted into descending order
op-output: the input, sorted into ascending order by field <<.field F>>, treating field values as alphanumerics
op-parameter: accept same parameters as the [[sort Operator]]
op-parameter: the name of a [[field|TiddlerFields]], defaulting to <<.field title>>
op-parameter-name: F
op-purpose: sort the input by text field considering them as alphanumerics
tags: [[Filter Operators]] [[Common Operators]] [[Field Operators]] [[Order Operators]] [[Negatable Operators]]

View File

@@ -1,10 +1,10 @@
caption: sortcs
created: 20140410103123179
modified: 20251227084416522
modified: 20150417125704503
op-input: a [[selection of titles|Title Selection]]
op-neg-output: the input, likewise sorted into descending order
op-output: the input, sorted into ascending order by field <<.field F>>, treating field values as text
op-parameter: accept same parameters as the [[sort Operator]]
op-parameter: the name of a [[field|TiddlerFields]], defaulting to <<.field title>>
op-parameter-name: F
op-purpose: sort the input by text field, treating upper and lower case as different
tags: [[Filter Operators]] [[Field Operators]] [[Order Operators]] [[Negatable Operators]]

View File

@@ -1,6 +1,6 @@
caption: Calls
created: 20221007130006705
modified: 20260125212303316
modified: 20260301030947969
tags: WikiText Procedures Functions Macros
title: Calls
type: text/vnd.tiddlywiki
@@ -25,6 +25,12 @@ Each parameter value can be enclosed in `'`single quotes`'`, `"`double quotes`"`
See the discussion about [[parser modes|WikiText parser mode: macro examples]]
!!! Examples
<<testcase TestCases/Calls/ProcedureStaticAttributes>>
<<testcase TestCases/Calls/ProcedureDynamicAttributes>>
!! Calls with <<.wlink TranscludeWidget>> Widget
The shortcut syntax expands to the <<.wlink TranscludeWidget>> widget with the `$variable` attribute specifying the name of the procedure to transclude.

View File

@@ -1,9 +0,0 @@
title: $:/changenotes/5.4.0/#9400/impacts/collator
changenote: $:/changenotes/5.4.0/#9400
created: 20251114102355243
modified: 20251114102355243
tags: $:/tags/ImpactNote
description: Tiddlywiki no longer works on browsers that doesn't support [[Intl.Collator|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator]]
impact-type: compatibility-break

View File

@@ -1,10 +0,0 @@
title: $:/changenotes/5.4.0/#9400
description: Add locale support for sort operators
release: 5.4.0
tags: $:/tags/ChangeNote
change-type: feature
change-category: filters
github-links: https://github.com/TiddlyWiki/TiddlyWiki5/pull/9400
github-contributors: Leilei332
Add a new parameter for `sort`, `nsort`, `sortan`, `sortcs` and `nsortcs` to support sorting with a custom locale.

View File

@@ -0,0 +1,40 @@
created: 20260301005951330
description: Procedure calls with dynamic attributes
modified: 20260301013907635
tags: $:/tags/wiki-test-spec
title: TestCases/Calls/ProcedureDynamicAttributes
type: text/vnd.tiddlywiki-multiple
title: Narrative
New-style equals sign named parameters support dynamic values
+
title: Output
\function f(a) foo [<a>] :and[join[ ]]
\procedure p(a1) <$text text=<<a1>>/>
<$let v="foo 1" v2="foo 3">
<<p a1=<<v>>>> -
<<p a1=<<f 2>>>> -
<<p a1=`$(v2)$`>> -
<<p a1={{my tiddler}}>> -
<<p a1={{my tiddler!!myfield}}>> -
<<p a1={{{ foo 6 :and[join[ ]] }}}>>
</$let>
+
title: my tiddler
myfield: foo 5
foo 4
+
title: ExpectedResult
<p>
foo 1 -
foo 2 -
foo 3 -
foo 4 -
foo 5 -
foo 6
</p>

View File

@@ -0,0 +1,48 @@
created: 20260301000418824
description: Procedure calls with static attributes
modified: 20260301031128810
tags: $:/tags/wiki-test-spec
title: TestCases/Calls/ProcedureStaticAttributes
type: text/vnd.tiddlywiki-multiple
title: Narrative
Positional, old style colon named parameters, and new-style equals sign named parameters support static values
+
title: Output
\procedure p(a1) <$text text=<<a1>>/>
<<p foo1>> -
<<p a1:foo2>> -
<<p a1=foo3>>
<<p "foo 4">> -
<<p a1:"foo 5">> -
<<p a1="foo 6">>
<<p 'foo 7'>> -
<<p a1:'foo 8'>> -
<<p a1='foo 9'>>
<<p """foo 10""">> -
<<p a1:"""foo 11""">> -
<<p a1="""foo 12""">>
<<p [[foo 13]]>> -
<<p a1:[[foo 14]]>> -
<<p a1=[[foo 15]]>>
+
title: ExpectedResult
<p>foo1 -
foo2 -
foo3</p><p>foo 4 -
foo 5 -
foo 6</p><p>foo 7 -
foo 8 -
foo 9</p><p>foo 10 -
foo 11 -
foo 12</p><p>foo 13 -
foo 14 -
foo 15</p>

View File

@@ -420,7 +420,7 @@ function extendInlineParse(thisArg,origFunc,twInlineRules) {
/// post processing ///
function wikify(state) {
var href, title, src;
var href, title, src, alt;
var tagStack = [];
state.tokens.forEach(function(blockToken) {
@@ -458,6 +458,7 @@ function wikify(state) {
token.tag = "$image";
src = token.attrGet("src");
alt = token.attrGet("alt");
token.attrSet("alt",alt);
title = token.attrGet("title");
token.attrs[token.attrIndex("src")][0] = "source";