I think I finally solved this problem. Hope this answer helps someone.
As I mentioned earlier, this is a three-step process.
- Exclusion of HTML inclusions in the source text.
- Apply a filter to break multi-line text into paragraphs.
- Display text without further escaping.
For the first step, I tried to find some existing function to delete the source text, but to no avail. It seems that AngularJS does not reveal any ways to do this (please correct me if I am wrong). Finally, I created my own filter to avoid HTML:
myModule.filter('htmlEscape', function() { return function(input) { if (!input) { return ''; } return input. replace(/&/g, '&'). replace(/</g, '<'). replace(/>/g, '>'). replace(/'/g, '''). replace(/"/g, '"') ; }; });
Then I created a filter to break simple text into paragraphs:
myModule.filter('textToHtml', ['$sce', 'htmlEscapeFilter', function($sce, htmlEscapeFilter) { return function(input) { if (!input) { return ''; } input = htmlEscapeFilter(input); var output = ''; $.each(input.split("\n\n"), function(key, paragraph) { output += '<p>' + paragraph + '</p>'; }); return $sce.trustAsHtml(output); }; }])
I insert the previously created htmlEscape filter to it and using the $sce.trustAsHtml method to return a value suitable for use with the ng-bind-html directive.
And at the end, I call this filter in a partial template as follows:
<div ng-bind-html="someText|textToHtml"></div>
Here is the result:

source share