Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 4d94282

Browse files
committed
Add support for whitelisting HTML automatically via trusted config option
Note that the HTML is not whitelisted by default. The user must explicitly set `trusted` to be `true` in the options configuration. Closes #97
1 parent 015d8b1 commit 4d94282

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

demo/demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
<form method="post">
1616
<textarea id="tinymce" ui-tinymce ng-model="tinymce"></textarea>
1717
</form>
18-
<div>{{tinymce}}</div>
18+
<div ng-bind-html="tinymce"></div>
1919
</body>
2020
</html>

src/tinymce.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
angular.module('ui.tinymce', [])
55
.value('uiTinymceConfig', {})
6-
.directive('uiTinymce', ['$rootScope', '$compile', '$timeout', '$window', 'uiTinymceConfig', function($rootScope, $compile, $timeout, $window, uiTinymceConfig) {
6+
.directive('uiTinymce', ['$rootScope', '$compile', '$timeout', '$window', '$sce', 'uiTinymceConfig', function($rootScope, $compile, $timeout, $window, $sce, uiTinymceConfig) {
77
uiTinymceConfig = uiTinymceConfig || {};
88
var generatedIds = 0;
99
var ID_ATTR = 'ui-tinymce';
@@ -19,7 +19,12 @@ angular.module('ui.tinymce', [])
1919

2020
var expression, options, tinyInstance,
2121
updateView = function(editor) {
22-
ngModel.$setViewValue(editor.getContent({format: options.format}).trim());
22+
var content = editor.getContent({format: options.format}).trim();
23+
if (options.trusted) {
24+
content = $sce.trustAsHtml(content);
25+
}
26+
27+
ngModel.$setViewValue(content);
2328
if (!$rootScope.$$phase) {
2429
scope.$apply();
2530
}

0 commit comments

Comments
 (0)