mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-06-04 23:54:06 +00:00
Add jsonstringify operator
This commit is contained in:
parent
e646d207c3
commit
d7a6816307
@ -72,6 +72,14 @@ exports.stringify = function(source,operator,options) {
|
|||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.jsonstringify = function(source,operator,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
results.push($tw.utils.jsonStringify(title));
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
exports.escaperegexp = function(source,operator,options) {
|
exports.escaperegexp = function(source,operator,options) {
|
||||||
var results = [];
|
var results = [];
|
||||||
source(function(tiddler,title) {
|
source(function(tiddler,title) {
|
||||||
|
@ -543,7 +543,24 @@ exports.stringify = function(s) {
|
|||||||
.replace(/'/g, "\\'") // single quote character
|
.replace(/'/g, "\\'") // single quote character
|
||||||
.replace(/\r/g, '\\r') // carriage return
|
.replace(/\r/g, '\\r') // carriage return
|
||||||
.replace(/\n/g, '\\n') // line feed
|
.replace(/\n/g, '\\n') // line feed
|
||||||
.replace(/[\x80-\uFFFF]/g, exports.escape); // non-ASCII characters
|
.replace(/[\x00-\x1f\x80-\uFFFF]/g, exports.escape); // non-ASCII characters
|
||||||
|
};
|
||||||
|
|
||||||
|
// Turns a string into a legal JSON string
|
||||||
|
// Derived from peg.js, thanks to David Majda
|
||||||
|
exports.jsonStringify = function(s) {
|
||||||
|
// See http://www.json.org/
|
||||||
|
return (s || "")
|
||||||
|
.replace(/\\/g, '\\\\') // backslash
|
||||||
|
.replace(/"/g, '\\"') // double quote character
|
||||||
|
.replace(/\r/g, '\\r') // carriage return
|
||||||
|
.replace(/\n/g, '\\n') // line feed
|
||||||
|
.replace(/\x08/g, '\\b') // backspace
|
||||||
|
.replace(/\x0c/g, '\\f') // formfeed
|
||||||
|
.replace(/\t/g, '\\t') // tab
|
||||||
|
.replace(/[\x00-\x1f\x80-\uFFFF]/g,function(s) {
|
||||||
|
return '\\u' + $tw.utils.pad(s.charCodeAt(0).toString(16).toUpperCase(),4);
|
||||||
|
}); // non-ASCII characters
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
created: 20161017154944352
|
created: 20161017154944352
|
||||||
modified: 20161017155350400
|
modified: 20171029155233487
|
||||||
tags: [[Operator Examples]] [[stringify Operator]]
|
tags: [[Operator Examples]] [[stringify Operator]]
|
||||||
title: stringify Operator (Examples)
|
title: stringify Operator (Examples)
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
<<.operator-example 1 """[[Title with "double quotes" and \backslash]] +[stringify[]]""">>
|
<<.operator-example 1 """[[Title with "double quotes" and single ' and \backslash]] +[stringify[]]""">>
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
created: 20171029155046637
|
||||||
|
modified: 20171029155227382
|
||||||
|
tags: [[Operator Examples]] [[stringify Operator]]
|
||||||
|
title: jsonstringify Operator (Examples)
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
<<.operator-example 1 """[[Title with "double quotes" and single ' and \backslash]] +[jsonstringify[]]""">>
|
14
editions/tw5.com/tiddlers/jsonstringify Operator.tid
Normal file
14
editions/tw5.com/tiddlers/jsonstringify Operator.tid
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
caption: jsonstringify
|
||||||
|
created: 20171029155051467
|
||||||
|
from-version: 5.1.14
|
||||||
|
modified: 20171029155143797
|
||||||
|
op-input: a [[selection of titles|Title Selection]]
|
||||||
|
op-output: the input with JSON string encodings applied
|
||||||
|
op-parameter:
|
||||||
|
op-parameter-name:
|
||||||
|
op-purpose: apply JSON string encoding to a string
|
||||||
|
tags: [[Filter Operators]] [[String Operators]]
|
||||||
|
title: jsonstringify Operator
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
<<.operator-examples "jsonstringify">>
|
Loading…
x
Reference in New Issue
Block a user