From 69d3a4707370cc15064a6ed74dd4b13236dccb4a Mon Sep 17 00:00:00 2001 From: Simon Huber Date: Wed, 26 Jun 2019 13:32:01 +0200 Subject: [PATCH] Add escapecss filter (#3546) * add escapecss filter this filter would allow creating valid css classes from titles containing special characters we assign a class to an element using `encodeuricomponent[]` so that the class name is encoded in a stylesheet we create the classname by `escapecss[]` which applies the uri encoding and escapes characters that need to be escaped * Update encodings.js * refactor tagToCssSelector, add escapeCssSelector * use escapeCssSelector * escape using CSS.escape if it's available * Update encodings.js * revert factoring out escapeCssSelector --- core/modules/filters/encodings.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/modules/filters/encodings.js b/core/modules/filters/encodings.js index b03354ada..f41350791 100644 --- a/core/modules/filters/encodings.js +++ b/core/modules/filters/encodings.js @@ -98,4 +98,13 @@ exports.escaperegexp = function(source,operator,options) { return results; }; +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)); + }); + return results; +}; + })();