mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-27 14:48:19 +00:00
Docs: format:json
Also tweak to the behaviour of format:json if the input string is not valid JSON
This commit is contained in:
parent
688c3bc5f6
commit
3e33d309ed
@ -20,7 +20,14 @@ exports.json = function(source,operand,options) {
|
|||||||
}
|
}
|
||||||
source(function(tiddler,title) {
|
source(function(tiddler,title) {
|
||||||
var data = $tw.utils.parseJSONSafe(title);
|
var data = $tw.utils.parseJSONSafe(title);
|
||||||
results.push(JSON.stringify(data,null,spaces));
|
try {
|
||||||
|
data = JSON.parse(title);
|
||||||
|
} catch(e) {
|
||||||
|
data = undefined;
|
||||||
|
}
|
||||||
|
if(data !== undefined) {
|
||||||
|
results.push(JSON.stringify(data,null,spaces));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
created: 20201020102735123
|
created: 20201020102735123
|
||||||
modified: 20210524044020645
|
modified: 20220611104737314
|
||||||
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
|
||||||
@ -18,9 +18,12 @@ Modified date shown as a relative date:
|
|||||||
A tiddler title with spaces formatted as a title list:
|
A tiddler title with spaces formatted as a title list:
|
||||||
<<.operator-example 4 """[[Hello There]format:titlelist[]]""">>
|
<<.operator-example 4 """[[Hello There]format:titlelist[]]""">>
|
||||||
|
|
||||||
All tiddler titles tagged with <<tag TableOfContents>> formatted as a title list :
|
All tiddler titles tagged with <<tag TableOfContents>> formatted as a title list:
|
||||||
<<.operator-example 5 """[tag[TableOfContents]format:titlelist[]]""">>
|
<<.operator-example 5 """[tag[TableOfContents]format:titlelist[]]""">>
|
||||||
|
|
||||||
|
A JSON string formatted as JSON – note how the JSON string is normalised to remove the duplicated properties:
|
||||||
|
<<.operator-example 6 """[[{"one":"first","one":"another","two":"second"}]format:json[]]""">>
|
||||||
|
|
||||||
<<.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]]">>
|
<<.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[ ]]""">>
|
<<.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]]:
|
For example, to save titles tagged `TableOfContents` to the titles field of the tiddler [[format titlelist test]]:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
caption: format
|
caption: format
|
||||||
created: 20201020100834443
|
created: 20201020100834443
|
||||||
modified: 20220523075550449
|
modified: 20220611104737314
|
||||||
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
|
||||||
@ -17,9 +17,10 @@ type: text/vnd.tiddlywiki
|
|||||||
The suffix <<.place B>> is one of the following supported string formats:
|
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 operand. (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. |
|
|^`json` |<<.from-version "5.3.0">> The input string is interpreted as JSON and displayed with standard formatting. The optional operator operand specifies the number of spaces to use for indenting, or a string to use for indenting. Nothing is returned if the input string is not valid JSON |
|
||||||
|^`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]]. |
|
|^`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]]. |
|
||||||
|
|
||||||
<<.warning """The [[Title List]] format cannot reliably represent items that contain certain specific character sequences such as `]] `. Thus it should not be used where there is a possibility of such sequences occurring.""">>
|
<<.warning """The [[Title List]] format cannot reliably represent items that contain certain specific character sequences such as `]] `. Thus it should not be used where there is a possibility of such sequences occurring.""">>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user