Created
December 16, 2019 13:38
-
-
Save garpunkal/1be685c68421f64d1cf368f66f1b45ed to your computer and use it in GitHub Desktop.
Umbraco: StripHtmlFilter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, "<"); | |
} | |
} | |
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