mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-08-29 20:42:44 +00:00
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
![]() |
/*\
|
||
|
title: $:/core/modules/filters/format.js
|
||
|
type: application/javascript
|
||
|
module-type: filteroperator
|
||
|
Filter operator for formatting strings
|
||
|
\*/
|
||
|
(function(){
|
||
|
|
||
|
/*jslint node: true, browser: true */
|
||
|
/*global $tw: false */
|
||
|
"use strict";
|
||
|
|
||
|
var formatFilterOperators;
|
||
|
|
||
|
function getFormatFilterOperators() {
|
||
|
if(!formatFilterOperators) {
|
||
|
formatFilterOperators = {};
|
||
|
$tw.modules.applyMethods("formatfilteroperator",formatFilterOperators);
|
||
|
}
|
||
|
return formatFilterOperators;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
Export our filter function
|
||
|
*/
|
||
|
exports.format = function(source,operator,options) {
|
||
|
// Dispatch to the correct formatfilteroperator
|
||
|
var formatFilterOperators = getFormatFilterOperators();
|
||
|
if(operator.suffix) {
|
||
|
var formatFilterOperator = formatFilterOperators[operator.suffix];
|
||
|
if(formatFilterOperator) {
|
||
|
return formatFilterOperator(source,operator.operand,options);
|
||
|
} else {
|
||
|
return [$tw.language.getString("Error/FormatFilterOperator")];
|
||
|
}
|
||
|
} else {
|
||
|
// Return all unchanged if the suffix is missing
|
||
|
var results = [];
|
||
|
source(function(tiddler,title) {
|
||
|
results.push(title);
|
||
|
});
|
||
|
return results;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
})();
|