diff --git a/core/modules/filters/encodings.js b/core/modules/filters/encodings.js index 9ab38c54e..23c743a03 100644 --- a/core/modules/filters/encodings.js +++ b/core/modules/filters/encodings.js @@ -16,6 +16,22 @@ Filter operator for applying decodeURIComponent() to each item. Export our filter functions */ +exports.decodebase64 = function(source,operator,options) { + var results = []; + source(function(tiddler,title) { + results.push($tw.utils.base64Decode(title)); + }); + return results; +}; + +exports.encodebase64 = function(source,operator,options) { + var results = []; + source(function(tiddler,title) { + results.push($tw.utils.base64Encode(title)); + }); + return results; +}; + exports.decodeuricomponent = function(source,operator,options) { var results = []; source(function(tiddler,title) { diff --git a/editions/test/tiddlers/tests/data/filters/Base64.tid b/editions/test/tiddlers/tests/data/filters/Base64.tid new file mode 100644 index 000000000..17f1defff --- /dev/null +++ b/editions/test/tiddlers/tests/data/filters/Base64.tid @@ -0,0 +1,19 @@ +title: Filters/Base64 +description: Test {encode|decode}base64 operators +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +(<$text text={{{ [[Jeremy1234]encodebase64[]] }}}/>) +(<$text text={{{ [[]encodebase64[]] }}}/>) +(<$text text={{{ [[SmVyZW15MTIzNA==]decodebase64[]] }}}/>) +(<$text text={{{ [[]decodebase64[]] }}}/>) ++ +title: ExpectedResult + +

(SmVyZW15MTIzNA==) +() +(Jeremy1234) +()

\ No newline at end of file diff --git a/editions/tw5.com/tiddlers/filters/decodebase64 Operator.tid b/editions/tw5.com/tiddlers/filters/decodebase64 Operator.tid new file mode 100644 index 000000000..6760af8d3 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/decodebase64 Operator.tid @@ -0,0 +1,16 @@ +caption: decodebase64 +op-input: a [[selection of titles|Title Selection]] +op-output: the input with base 64 decoding applied +op-parameter: +op-parameter-name: +op-purpose: apply base 64 decoding to a string +tags: [[Filter Operators]] [[String Operators]] +title: decodebase64 Operator +type: text/vnd.tiddlywiki +from-version: 5.2.6 + +See Mozilla Developer Network for details of [[base 64 encoding|https://developer.mozilla.org/en-US/docs/Glossary/Base64]]. TiddlyWiki uses [[library code from @nijikokun|https://gist.github.com/Nijikokun/5192472]] to handle the conversion. + +The input strings must be base64 encoded. The output strings are binary data. + +<<.operator-examples "decodebase64">> diff --git a/editions/tw5.com/tiddlers/filters/encodebase64 Operator.tid b/editions/tw5.com/tiddlers/filters/encodebase64 Operator.tid new file mode 100644 index 000000000..ddbc73078 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/encodebase64 Operator.tid @@ -0,0 +1,16 @@ +caption: encodebase64 +op-input: a [[selection of titles|Title Selection]] +op-output: the input with base 64 encoding applied +op-parameter: +op-parameter-name: +op-purpose: apply base 64 encoding to a string +tags: [[Filter Operators]] [[String Operators]] +title: encodebase64 Operator +type: text/vnd.tiddlywiki +from-version: 5.2.6 + +See Mozilla Developer Network for details of [[base 64 encoding|https://developer.mozilla.org/en-US/docs/Glossary/Base64]]. TiddlyWiki uses [[library code from @nijikokun|https://gist.github.com/Nijikokun/5192472]] to handle the conversion. + +The input strings are interpreted as binary data. The output strings are base64 encoded. + +<<.operator-examples "encodebase64">>