mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-07-03 18:42:50 +00:00
Format:titlelist operator (#5665)
This commit is contained in:
parent
c30ce544d1
commit
7a41283c6b
25
core/modules/filters/format/titlelist.js
Normal file
25
core/modules/filters/format/titlelist.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/filters/format/titlelist.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: formatfilteroperator
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/*
|
||||||
|
Export our filter function
|
||||||
|
*/
|
||||||
|
exports.titlelist = function(source,operand,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
if(title && title.length) {
|
||||||
|
results.push($tw.utils.stringifyList([title]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
@ -809,6 +809,12 @@ function runTests(wiki) {
|
|||||||
expect(wiki.filterTiddlers("'-' +[escapecss[]]").join(",")).toBe("\\-");
|
expect(wiki.filterTiddlers("'-' +[escapecss[]]").join(",")).toBe("\\-");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should handle the format operator", function() {
|
||||||
|
expect(wiki.filterTiddlers("[[Hello There]] [[GettingStarted]] +[format:titlelist[]]").join(" ")).toBe("[[Hello There]] GettingStarted");
|
||||||
|
expect(wiki.filterTiddlers("[title[Hello There]] +[format:titlelist[]]").join(" ")).toBe("[[Hello There]]");
|
||||||
|
expect(wiki.filterTiddlers("[title[HelloThere]] +[format:titlelist[]]").join(" ")).toBe("HelloThere");
|
||||||
|
});
|
||||||
|
|
||||||
it("should handle the deserializers operator", function() {
|
it("should handle the deserializers operator", function() {
|
||||||
expect(wiki.filterTiddlers("[deserializers[]]").join(",")).toBe("application/javascript,application/json,application/x-tiddler,application/x-tiddler-html-div,application/x-tiddlers,text/css,text/html,text/plain");
|
expect(wiki.filterTiddlers("[deserializers[]]").join(",")).toBe("application/javascript,application/json,application/x-tiddler,application/x-tiddler-html-div,application/x-tiddlers,text/css,text/html,text/plain");
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
created: 20201020102735123
|
created: 20201020102735123
|
||||||
modified: 20201020104004306
|
modified: 20210524044020645
|
||||||
tags: [[Operator Examples]] [[format Operator]]
|
tags: [[Operator Examples]] [[format Operator]]
|
||||||
title: format Operator (Examples)
|
title: format Operator (Examples)
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
@ -14,3 +14,18 @@ Created date with a format string supplied as operator parameter:
|
|||||||
|
|
||||||
Modified date shown as a relative date:
|
Modified date shown as a relative date:
|
||||||
<<.operator-example 3 "[[HelloThere]get[modified]format:relativedate[]]">>
|
<<.operator-example 3 "[[HelloThere]get[modified]format:relativedate[]]">>
|
||||||
|
|
||||||
|
A tiddler title with spaces formatted as a title list:
|
||||||
|
<<.operator-example 4 """[[Hello There]format:titlelist[]]""">>
|
||||||
|
|
||||||
|
All tiddler titles tagged with <<tag TableOfContents>> formatted as a title list :
|
||||||
|
<<.operator-example 5 """[tag[TableOfContents]format:titlelist[]]""">>
|
||||||
|
|
||||||
|
<<.tip "To create a string to save a [[title list|Title List]] into a list field, use `format:titlelist[]` with the [[join operator|join Operator]]">>
|
||||||
|
<<.operator-example 6 """[tag[TableOfContents]format:titlelist[]join[ ]]""">>
|
||||||
|
For example, to save titles tagged `TableOfContents` to the titles field of the tiddler [[format titlelist test]]:
|
||||||
|
|
||||||
|
<$macrocall $name='wikitext-example-without-html'
|
||||||
|
src='<$button> test
|
||||||
|
<$action-setfield $tiddler="format titlelist test" titles={{{ [tag[TableOfContents]format:titlelist[]join[ ]] }}}/>
|
||||||
|
</$button>'/>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
caption: format
|
caption: format
|
||||||
created: 20201020100834443
|
created: 20201020100834443
|
||||||
modified: 20201020104004271
|
modified: 20210524090002126
|
||||||
op-input: a [[selection of titles|Title Selection]]
|
op-input: a [[selection of titles|Title Selection]]
|
||||||
op-output: input strings formatted according to the specified suffix <<.place B>>
|
op-output: input strings formatted according to the specified suffix <<.place B>>
|
||||||
op-parameter: optional format string for the formats
|
op-parameter: optional format string for the formats
|
||||||
@ -19,5 +19,6 @@ The suffix <<.place B>> is one of the following supported string formats:
|
|||||||
|!Format |!Description |
|
|!Format |!Description |
|
||||||
|^`date` |The input string is interpreted as a UTC date and displayed according to the DateFormat specified in the optional operator parameter. (Defaults to "YYYY MM DD 0hh:0mm") |
|
|^`date` |The input string is interpreted as a UTC date and displayed according to the DateFormat specified in the optional operator parameter. (Defaults to "YYYY MM DD 0hh:0mm") |
|
||||||
|^`relativedate` |The input string is interpreted as a UTC date and displayed as the interval from the present instant. Any operator parameters are ignored. |
|
|^`relativedate` |The input string is interpreted as a UTC date and displayed as the interval from the present instant. Any operator parameters are ignored. |
|
||||||
|
|^`titlelist` |<<.from-version "5.2.0">>The input string wrapped in double square brackets if it contains a space. Appropriate for use in a [[title list|Title List]]. |
|
||||||
|
|
||||||
<<.operator-examples "format">>
|
<<.operator-examples "format">>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user