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?
new-json-store-area
jeremy@jermolene.com 2021-06-22 21:52:00 +01:00
rodzic 63fa0c4fa4
commit 83ee363cb4
4 zmienionych plików z 40 dodań i 0 usunięć

Wyświetl plik

@ -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("")];
};
})();

Wyświetl plik

@ -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("");
});
}

Wyświetl plik

@ -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">>

Wyświetl plik

@ -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]]">>