mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-26 19:47:20 +00:00
Change css-escape-polyfill to a tw uitility method (#5552)
* Replace css-escape-polyfill.js with escapecss.js utility module * Add $tw.utils.escapeCSS() method and invoke that function within the escapecss operator. * Add test cases for the "escapecss" filter operator * Fix $tw.boot.doesTaskMatchPlatform() so it works as expected if a module's export.platforms contains more than one values * Add missed files to the last commit
This commit is contained in:
parent
d6ea369f5e
commit
3b35411aba
19
boot/boot.js
19
boot/boot.js
@ -2467,16 +2467,29 @@ $tw.boot.executeNextStartupTask = function(callback) {
|
||||
};
|
||||
|
||||
/*
|
||||
Returns true if we are running on one platforms specified in a task modules `platforms` array
|
||||
Returns true if we are running on one of the platforms specified in taskModule's
|
||||
`platforms` array; or if `platforms` property is not defined.
|
||||
*/
|
||||
$tw.boot.doesTaskMatchPlatform = function(taskModule) {
|
||||
var platforms = taskModule.platforms;
|
||||
if(platforms) {
|
||||
for(var t=0; t<platforms.length; t++) {
|
||||
if((platforms[t] === "browser" && !$tw.browser) || (platforms[t] === "node" && !$tw.node)) {
|
||||
return false;
|
||||
switch (platforms[t]) {
|
||||
case "browser":
|
||||
if ($tw.browser) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case "node":
|
||||
if ($tw.node) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$tw.utils.error("Module " + taskModule.name + ": '" + platforms[t] + "' in export.platforms invalid");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
@ -102,7 +102,7 @@ exports.escapecss = function(source,operator,options) {
|
||||
var results = [];
|
||||
source(function(tiddler,title) {
|
||||
// escape any character with a special meaning in CSS using CSS.escape()
|
||||
results.push(CSS.escape(title));
|
||||
results.push($tw.utils.escapeCSS(title));
|
||||
});
|
||||
return results;
|
||||
};
|
||||
|
@ -1,33 +1,28 @@
|
||||
/*\
|
||||
title: $:/core/modules/startup/CSSescape.js
|
||||
title: $:/core/modules/utils/escapecss.js
|
||||
type: application/javascript
|
||||
module-type: startup
|
||||
module-type: utils
|
||||
|
||||
Polyfill for CSS.escape()
|
||||
Provides CSS.escape() functionality.
|
||||
|
||||
\*/
|
||||
(function(root,factory){
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
/*global $tw: false, window: false */
|
||||
"use strict";
|
||||
|
||||
// Export name and synchronous status
|
||||
exports.name = "css-escape";
|
||||
exports.platforms = ["browser"];
|
||||
exports.after = ["startup"];
|
||||
exports.synchronous = true;
|
||||
|
||||
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */
|
||||
// https://github.com/umdjs/umd/blob/master/returnExports.js
|
||||
exports.startup = function() {factory(root);};
|
||||
}(typeof global != 'undefined' ? global : this, function(root) {
|
||||
|
||||
if (root.CSS && root.CSS.escape) {
|
||||
return;
|
||||
exports.escapeCSS = (function() {
|
||||
// use browser's native CSS.escape() function if available
|
||||
if ($tw.browser && window.CSS && window.CSS.escape) {
|
||||
return window.CSS.escape;
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#serialize-an-identifier
|
||||
var cssEscape = function(value) {
|
||||
// otherwise, a utility method is provided
|
||||
// see also https://drafts.csswg.org/cssom/#serialize-an-identifier
|
||||
|
||||
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */
|
||||
return function(value) {
|
||||
if (arguments.length == 0) {
|
||||
throw new TypeError('`CSS.escape` requires an argument.');
|
||||
}
|
||||
@ -104,11 +99,6 @@ exports.startup = function() {factory(root);};
|
||||
}
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
|
||||
if (!root.CSS) {
|
||||
root.CSS = {};
|
||||
}
|
||||
|
||||
Object.getPrototypeOf(root.CSS).escape = cssEscape;
|
||||
|
||||
}));
|
||||
})();
|
@ -796,6 +796,17 @@ function runTests(wiki) {
|
||||
expect(wiki.filterTiddlers("[[12]pad[9],[abc]]").join(",")).toBe("abcabca12");
|
||||
expect(wiki.filterTiddlers("[[12]pad:suffix[9],[abc]]").join(",")).toBe("12abcabca");
|
||||
});
|
||||
|
||||
it("should handle the escapecss operator", function() {
|
||||
expect(wiki.filterTiddlers("[[Hello There]escapecss[]]").join(",")).toBe("Hello\\ There");
|
||||
expect(wiki.filterTiddlers('\'"Reveal.js" by Devin Weaver[1]\' +[escapecss[]]').join(",")).toBe('\\"Reveal\\.js\\"\\ by\\ Devin\\ Weaver\\[1\\]');
|
||||
expect(wiki.filterTiddlers(".foo#bar (){} '--a' 0 \0 +[escapecss[]]").join(",")).toBe("\\.foo\\#bar,\\(\\)\\{\\},--a,\\30 ,\ufffd");
|
||||
expect(wiki.filterTiddlers("'' +[escapecss[]]").join(",")).toBe("");
|
||||
expect(wiki.filterTiddlers("1234 +[escapecss[]]").join(",")).toBe("\\31 234");
|
||||
expect(wiki.filterTiddlers("'-25' +[escapecss[]]").join(",")).toBe("-\\32 5");
|
||||
expect(wiki.filterTiddlers("'-' +[escapecss[]]").join(",")).toBe("\\-");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user