diff --git a/contribs/gmf/src/query/windowComponent.html b/contribs/gmf/src/query/windowComponent.html index bd2810d3e5b7..cf13f145c941 100644 --- a/contribs/gmf/src/query/windowComponent.html +++ b/contribs/gmf/src/query/windowComponent.html @@ -53,7 +53,7 @@ > diff --git a/options/ngeox.js b/options/ngeox.js index 7d7e1a939b04..8a9472788506 100644 --- a/options/ngeox.js +++ b/options/ngeox.js @@ -792,6 +792,30 @@ ngeox.ScaleselectorOptions.prototype.dropup; ngeox.SortableOptions; +/** + * @typedef {{ + * regex: (string), + * template: (string) + * }} + */ +ngeox.StringToHtmlReplacement; + + +/** + * The regex expression that must match to do the replacement. + * @type {string} + */ +ngeox.StringToHtmlReplacement.prototype.expression; + + +/** + * The template to use to create a new value as replacement if the + * regex matches. + * @type {string} + */ +ngeox.StringToHtmlReplacement.prototype.template; + + /** * A WFS type. To be used with {@link ngeox.WfsPermalinkOptions}. * @typedef {{ diff --git a/src/grid/component.html b/src/grid/component.html index 5fcf06049e60..60767327c640 100644 --- a/src/grid/component.html +++ b/src/grid/component.html @@ -15,7 +15,7 @@ - + diff --git a/src/misc/filters.js b/src/misc/filters.js index 244e90ef193c..315c9ee84430 100644 --- a/src/misc/filters.js +++ b/src/misc/filters.js @@ -323,6 +323,48 @@ exports.trustHtmlFilter = function($sce) { exports.filter('ngeoTrustHtml', exports.trustHtmlFilter); +/** + * A filter to mark a value as trusted HTML, with the addition of + * automatically converting any string that matches the + * StringToHtmlReplacements list to HTML. + * + * Usage: + * + *

+ * + * If you use it, you don't require the "ngSanitize". + * @return {function(?):string} The filter function. + * @ngInject + * @ngdoc filter + * @param {angular.$sce} $sce Angular sce service. + * @param {!Array.} + * ngeoStringToHtmlReplacements List of replacements for string to html. + * html. + * @ngname ngeoTrustHtmlAuto + */ +exports.trustHtmlAutoFilter = function($sce, ngeoStringToHtmlReplacements) { + return function(input) { + if (input !== undefined && input !== null) { + if (typeof input === 'string') { + for (const replacement of ngeoStringToHtmlReplacements) { + if (input.match(replacement.expression)) { + input = replacement.template.replace(/\$1/g, input); + break; + } + } + return $sce.trustAsHtml(`${input}`); + } else { + return $sce.trustAsHtml(`${input}`); + } + } else { + return $sce.trustAsHtml(' '); + } + }; +}; + +exports.filter('ngeoTrustHtmlAuto', exports.trustHtmlAutoFilter); + + /** * A filter used to format a time duration in seconds into a more * readable form. @@ -427,4 +469,27 @@ exports.Duration = function(gettextCatalog) { exports.filter('ngeoDuration', exports.Duration); +/** + * @type {!Array.} + * @ngname ngeoStringToHtmlReplacements + */ +exports.StringToHtmlReplacements = [ + // Hyperlink + { + expression: /^(https?:\/\/.+)$/gm, + template: '$1' + }, + // Mailto + { + expression: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/gmi, + template: '$1' + } +]; + +exports.constant( + 'ngeoStringToHtmlReplacements', + exports.StringToHtmlReplacements +); + + export default exports;