mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-22 22:10:03 +00:00
Add new filter operators for various string encoding/decodings
This commit is contained in:
parent
b35544bf49
commit
b4b77d1681
83
core/modules/filters/encodings.js
Normal file
83
core/modules/filters/encodings.js
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/filters/decodeuricomponent.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: filteroperator
|
||||||
|
|
||||||
|
Filter operator for applying decodeURIComponent() to each item.
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/*
|
||||||
|
Export our filter functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
exports.decodeuricomponent = function(source,operator,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
results.push(decodeURIComponent(title));
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.encodeuricomponent = function(source,operator,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
results.push(encodeURIComponent(title));
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.decodeuri = function(source,operator,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
results.push(decodeURI(title));
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.encodeuri = function(source,operator,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
results.push(encodeURI(title));
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.decodehtml = function(source,operator,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
results.push($tw.utils.htmlDecode(title));
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.encodehtml = function(source,operator,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
results.push($tw.utils.htmlEncode(title));
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.stringify = function(source,operator,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
results.push($tw.utils.stringify(title));
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.escaperegexp = function(source,operator,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
results.push($tw.utils.escapeRegExp(title));
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
@ -1,5 +1,5 @@
|
|||||||
created: 20140410103123179
|
created: 20140410103123179
|
||||||
modified: 20150917193612610
|
modified: 20161017154031883
|
||||||
tags: Filters
|
tags: Filters
|
||||||
title: Filter Operators
|
title: Filter Operators
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
|
22
editions/tw5.com/tiddlers/filters/decodehtml_Operator.tid
Normal file
22
editions/tw5.com/tiddlers/filters/decodehtml_Operator.tid
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
caption: decodehtml
|
||||||
|
created: 20161017152925704
|
||||||
|
modified: 20161017152951209
|
||||||
|
op-input: a [[selection of titles|Title Selection]]
|
||||||
|
op-output: the input with HTML decoding applied
|
||||||
|
op-parameter:
|
||||||
|
op-parameter-name:
|
||||||
|
op-purpose: apply HTML decoding to a string
|
||||||
|
tags: [[Filter Operators]] [[String Operators]]
|
||||||
|
title: decodehtml Operator
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
from-version: 5.1.14
|
||||||
|
|
||||||
|
"HTML decoding" means replacing HTML entities that represent special characters with that character:
|
||||||
|
|
||||||
|
* `&` replaced with `&`
|
||||||
|
* ` ` replaced with ` ` (non breaking space)
|
||||||
|
* `<` replaced with `<`
|
||||||
|
* `>` replaced with `>`
|
||||||
|
* `"` replaced with `"`
|
||||||
|
|
||||||
|
<<.operator-examples "decodehtml">>
|
16
editions/tw5.com/tiddlers/filters/decodeuri_Operator.tid
Normal file
16
editions/tw5.com/tiddlers/filters/decodeuri_Operator.tid
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
caption: decodeuri
|
||||||
|
created: 20161017152854460
|
||||||
|
modified: 20161017152914038
|
||||||
|
op-input: a [[selection of titles|Title Selection]]
|
||||||
|
op-output: the input with URI decoding applied
|
||||||
|
op-parameter:
|
||||||
|
op-parameter-name:
|
||||||
|
op-purpose: apply URI decoding to a string
|
||||||
|
tags: [[Filter Operators]] [[String Operators]]
|
||||||
|
title: decodeuri Operator
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
from-version: 5.1.14
|
||||||
|
|
||||||
|
See Mozilla Developer Network for details of the [[decodeURI|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI]] operation.
|
||||||
|
|
||||||
|
<<.operator-examples "decodeuri">>
|
@ -0,0 +1,16 @@
|
|||||||
|
caption: decodeuricomponent
|
||||||
|
created: 20161017152454726
|
||||||
|
modified: 20161017152630625
|
||||||
|
op-input: a [[selection of titles|Title Selection]]
|
||||||
|
op-output: the input with URI component decoding applied
|
||||||
|
op-parameter:
|
||||||
|
op-parameter-name:
|
||||||
|
op-purpose: apply URI component decoding to a string
|
||||||
|
tags: [[Filter Operators]] [[String Operators]]
|
||||||
|
title: decodeuricomponent Operator
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
from-version: 5.1.14
|
||||||
|
|
||||||
|
See Mozilla Developer Network for details of the [[decodeURIComponent|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent]] operation.
|
||||||
|
|
||||||
|
<<.operator-examples "decodeuricomponent">>
|
21
editions/tw5.com/tiddlers/filters/encodehtml_Operator.tid
Normal file
21
editions/tw5.com/tiddlers/filters/encodehtml_Operator.tid
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
caption: encodehtml
|
||||||
|
created: 20161017152953211
|
||||||
|
modified: 20161017153015687
|
||||||
|
op-input: a [[selection of titles|Title Selection]]
|
||||||
|
op-output: the input with HTML encoding applied
|
||||||
|
op-parameter:
|
||||||
|
op-parameter-name:
|
||||||
|
op-purpose: apply HTML encoding to a string
|
||||||
|
tags: [[Filter Operators]] [[String Operators]]
|
||||||
|
title: encodehtml Operator
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
from-version: 5.1.14
|
||||||
|
|
||||||
|
"HTML encoding" means replacing special HTML characters with the corresponding HTML entity:
|
||||||
|
|
||||||
|
* `&` replaced with `&`
|
||||||
|
* `<` replaced with `<`
|
||||||
|
* `>` replaced with `>`
|
||||||
|
* `"` replaced with `"`
|
||||||
|
|
||||||
|
<<.operator-examples "encodehtml">>
|
16
editions/tw5.com/tiddlers/filters/encodeuri_Operator.tid
Normal file
16
editions/tw5.com/tiddlers/filters/encodeuri_Operator.tid
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
caption: encodeuri
|
||||||
|
created: 20161017152827112
|
||||||
|
modified: 20161017152845585
|
||||||
|
op-input: a [[selection of titles|Title Selection]]
|
||||||
|
op-output: the input with URI encoding applied
|
||||||
|
op-parameter:
|
||||||
|
op-parameter-name:
|
||||||
|
op-purpose: apply URI encoding to a string
|
||||||
|
tags: [[Filter Operators]] [[String Operators]]
|
||||||
|
title: encodeuri Operator
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
from-version: 5.1.14
|
||||||
|
|
||||||
|
See Mozilla Developer Network for details of the [[encodeURI|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI]] operation.
|
||||||
|
|
||||||
|
<<.operator-examples "encodeuri">>
|
@ -0,0 +1,16 @@
|
|||||||
|
caption: encodeuricomponent
|
||||||
|
created: 20161017152747386
|
||||||
|
modified: 20161017152809900
|
||||||
|
op-input: a [[selection of titles|Title Selection]]
|
||||||
|
op-output: the input with URI component encoding applied
|
||||||
|
op-parameter:
|
||||||
|
op-parameter-name:
|
||||||
|
op-purpose: apply URI component encoding to a string
|
||||||
|
tags: [[Filter Operators]] [[String Operators]]
|
||||||
|
title: encodeuricomponent Operator
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
from-version: 5.1.14
|
||||||
|
|
||||||
|
See Mozilla Developer Network for details of the [[encodeURIComponent|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent]] operation.
|
||||||
|
|
||||||
|
<<.operator-examples "encodeuricomponent">>
|
16
editions/tw5.com/tiddlers/filters/escaperegexp_Operator.tid
Normal file
16
editions/tw5.com/tiddlers/filters/escaperegexp_Operator.tid
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
caption: escaperegexp
|
||||||
|
created: 20161017153116372
|
||||||
|
modified: 20161017153230962
|
||||||
|
op-input: a [[selection of titles|Title Selection]]
|
||||||
|
op-output: the input with escaping applied to special regular expression characters
|
||||||
|
op-parameter:
|
||||||
|
op-parameter-name:
|
||||||
|
op-purpose: escape special characters used in regular expressions
|
||||||
|
tags: [[Filter Operators]] [[String Operators]]
|
||||||
|
title: escaperegexp Operator
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
from-version: 5.1.14
|
||||||
|
|
||||||
|
See Mozilla Developer Network for details of the [[regular expression syntax|https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp]].
|
||||||
|
|
||||||
|
<<.operator-examples "escaperegexp">>
|
@ -0,0 +1,8 @@
|
|||||||
|
created: 20161017154848886
|
||||||
|
modified: 20161017155350389
|
||||||
|
tags: [[Operator Examples]] [[decodehtml Operator]]
|
||||||
|
title: decodehtml Operator (Examples)
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
<<.operator-example 1 "[[Title with < angle brackets >]] +[decodehtml[]]">>
|
||||||
|
<<.operator-example 2 "[[Title with an & ampersand]] +[decodehtml[]]">>
|
@ -0,0 +1,8 @@
|
|||||||
|
created: 20161017154558573
|
||||||
|
modified: 20161017155350399
|
||||||
|
tags: [[Operator Examples]] [[decodeuri Operator]]
|
||||||
|
title: decodeuri Operator (Examples)
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
<<.operator-example 1 "[[Title%20with%20Space]] +[decodeuri[]]">>
|
||||||
|
<<.operator-example 2 "[[Title%20with%20Space]] [[Another%20title%20with%20Space]] +[decodeuri[]]">>
|
@ -0,0 +1,8 @@
|
|||||||
|
created: 20161017153616709
|
||||||
|
modified: 20161017155350393
|
||||||
|
tags: [[Operator Examples]] [[decodeuricomponent Operator]]
|
||||||
|
title: decodeuricomponent Operator (Examples)
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
<<.operator-example 1 "[[Title%20with%20Space]] +[decodeuricomponent[]]">>
|
||||||
|
<<.operator-example 2 "[[Title%20with%20Space]] [[Another%20title%20with%20Space]] +[decodeuricomponent[]]">>
|
@ -0,0 +1,8 @@
|
|||||||
|
created: 20161017154758523
|
||||||
|
modified: 20161017155350391
|
||||||
|
tags: [[Operator Examples]] [[encodehtml Operator]]
|
||||||
|
title: encodehtml Operator (Examples)
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
<<.operator-example 1 "[[Title with <angle brackets>]] +[encodehtml[]]">>
|
||||||
|
<<.operator-example 2 "[[Title with an & ampersand]] +[encodehtml[]]">>
|
@ -0,0 +1,8 @@
|
|||||||
|
created: 20161017154702282
|
||||||
|
modified: 20161017155350397
|
||||||
|
tags: [[Operator Examples]] [[encodeuri Operator]]
|
||||||
|
title: encodeuri Operator (Examples)
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
<<.operator-example 1 "[[Title with Space]] +[encodeuri[]]">>
|
||||||
|
<<.operator-example 2 "[[Title with Space]] [[Another title with Space]] +[encodeuri[]]">>
|
@ -0,0 +1,8 @@
|
|||||||
|
created: 20161017154451373
|
||||||
|
modified: 20161017155350395
|
||||||
|
tags: [[Operator Examples]] [[encodeuricomponent Operator]]
|
||||||
|
title: encodeuricomponent Operator (Examples)
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
<<.operator-example 1 "[[Title with Space]] +[encodeuricomponent[]]">>
|
||||||
|
<<.operator-example 2 "[[Title with Space]] [[Another title with Space]] +[encodeuricomponent[]]">>
|
@ -0,0 +1,7 @@
|
|||||||
|
created: 20161017155417183
|
||||||
|
modified: 20161017155520892
|
||||||
|
tags: [[Operator Examples]] [[escaperegexp Operator]]
|
||||||
|
title: escaperegexp Operator (Examples)
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
<<.operator-example 1 """[[Title with dots . and dollars $]] +[escaperegexp[]]""">>
|
@ -0,0 +1,7 @@
|
|||||||
|
created: 20161017154944352
|
||||||
|
modified: 20161017155350400
|
||||||
|
tags: [[Operator Examples]] [[stringify Operator]]
|
||||||
|
title: stringify Operator (Examples)
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
<<.operator-example 1 """[[Title with "double quotes" and \backslash]] +[stringify[]]""">>
|
14
editions/tw5.com/tiddlers/filters/stringify_Operator.tid
Normal file
14
editions/tw5.com/tiddlers/filters/stringify_Operator.tid
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
caption: stringify
|
||||||
|
created: 20161017153038029
|
||||||
|
modified: 20161017153114691
|
||||||
|
op-input: a [[selection of titles|Title Selection]]
|
||||||
|
op-output: the input with ~JavaScript string encodings applied
|
||||||
|
op-parameter:
|
||||||
|
op-parameter-name:
|
||||||
|
op-purpose: apply ~JavaScript string encoding to a string
|
||||||
|
tags: [[Filter Operators]] [[String Operators]]
|
||||||
|
title: stringify Operator
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
from-version: 5.1.14
|
||||||
|
|
||||||
|
<<.operator-examples "stringify">>
|
@ -20,7 +20,7 @@ tags: $:/tags/Macro
|
|||||||
<dd><$button set=<<.state>> setTo="">Hide</$button></dd>
|
<dd><$button set=<<.state>> setTo="">Hide</$button></dd>
|
||||||
</dl>
|
</dl>
|
||||||
<blockquote class="doc-example-result">
|
<blockquote class="doc-example-result">
|
||||||
<ul><$list filter="$eg$" emptyMessage="(empty)">
|
<ul><$list filter="""$eg$""" emptyMessage="(empty)">
|
||||||
<li><$link><$view field="title"/></$link></li>
|
<li><$link><$view field="title"/></$link></li>
|
||||||
</$list></ul>
|
</$list></ul>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user