Skip to content

Instantly share code, notes, and snippets.

@garpunkal
Created December 16, 2019 13:38
Show Gist options
  • Save garpunkal/1be685c68421f64d1cf368f66f1b45ed to your computer and use it in GitHub Desktop.
Save garpunkal/1be685c68421f64d1cf368f66f1b45ed to your computer and use it in GitHub Desktop.
Umbraco: StripHtmlFilter
// usage: "nameTemplate": "{{ text | stripHtml }}"
(function () {
var tagBody = '(?:[^"\'>]|"[^"]*"|\'[^\']*\')*';
var tagOrComment = new RegExp(
"<(?:"
// Comment body.
+ "!--(?:(?:-*[^->])*--+|-?)"
// Special "raw text" elements whose content should be elided.
+ "|script\\b" + tagBody + ">[\\s\\S]*?</script\\s*"
+ "|style\\b" + tagBody + ">[\\s\\S]*?</style\\s*"
// Regular name
+ "|/?[a-z]"
+ tagBody
+ ")>",
"gi");
function stripHtml() {
return function(html) {
var oldHtml;
do {
oldHtml = html;
html = html.replace(tagOrComment, "");
} while (html !== oldHtml);
return html.replace(/</g, "&lt;");
}
}
angular.module("umbraco.filters").filter("stripHtml", stripHtml);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment