mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Add charcode operator to make it easier to generate strings containing control characters
Avoids some confusing hacks. @saqimtiaz I'm guessing you might have already done something like this?
This commit is contained in:
parent
63fa0c4fa4
commit
83ee363cb4
@ -172,4 +172,14 @@ exports.pad = function(source,operator,options) {
|
||||
return results;
|
||||
}
|
||||
|
||||
exports.charcode = function(source,operator,options) {
|
||||
var chars = [];
|
||||
$tw.utils.each(operator.operands,function(operand) {
|
||||
if(operand !== "") {
|
||||
chars.push(String.fromCharCode($tw.utils.parseInt(operand)));
|
||||
}
|
||||
});
|
||||
return [chars.join("")];
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -818,6 +818,12 @@ function runTests(wiki) {
|
||||
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");
|
||||
});
|
||||
|
||||
it("should handle the charcode operator", function() {
|
||||
expect(wiki.filterTiddlers("[charcode[9]]").join(" ")).toBe(String.fromCharCode(9));
|
||||
expect(wiki.filterTiddlers("[charcode[9],[10]]").join(" ")).toBe(String.fromCharCode(9) + String.fromCharCode(10));
|
||||
expect(wiki.filterTiddlers("[charcode[]]").join(" ")).toBe("");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
17
editions/tw5.com/tiddlers/filters/charcode.tid
Normal file
17
editions/tw5.com/tiddlers/filters/charcode.tid
Normal file
@ -0,0 +1,17 @@
|
||||
caption: charcode
|
||||
created: 20210622214425635
|
||||
modified: 20210622214425635
|
||||
op-input: ignored
|
||||
op-output: a string formed from concatenating the characters specified by the numeric codes given in the operand(s)
|
||||
op-parameter: numeric character code
|
||||
op-parameter-name: C
|
||||
op-purpose: generates string characters from their numeric character codes
|
||||
tags: [[Filter Operators]]
|
||||
title: charcode Operator
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
<<.from-version "5.1.24">>
|
||||
|
||||
This operator returns a string formed from concatenating the characters specified by the numeric codes given in one or more operands. It is useful for generating special characters such as tab (`charcode[9]`) or new line (`charcode[13],[10]`).
|
||||
|
||||
<<.operator-examples "charcode">>
|
7
editions/tw5.com/tiddlers/filters/examples/charcode.tid
Normal file
7
editions/tw5.com/tiddlers/filters/examples/charcode.tid
Normal file
@ -0,0 +1,7 @@
|
||||
created: 20210622214849214
|
||||
modified: 20210622214849214
|
||||
tags: [[charcode Operator]] [[Operator Examples]]
|
||||
title: charcode Operator (Examples)
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
<<.operator-example 1 "[charcode[65]match[A]]">>
|
Loading…
Reference in New Issue
Block a user