|
12 | 12 |
|
13 | 13 | module |
14 | 14 | .provider('$showdown', ngShowdown) |
15 | | - .directive('sdModelToHtml', ['$showdown', '$sce', sdModelToHtmlDirective]) //<-- DEPRECATED: will be removed in the next major version release |
16 | | - .directive('markdownToHtml', ['$showdown', '$sce', markdownToHtmlDirective]) |
| 15 | + .directive('sdModelToHtml', ['$showdown', '$sanitize', sdModelToHtmlDirective]) //<-- DEPRECATED: will be removed in the next major version release |
| 16 | + .directive('markdownToHtml', ['$showdown', '$sanitize', markdownToHtmlDirective]) |
17 | 17 | .filter('sdStripHtml', ['$showdown', stripHtmlFilter]) //<-- DEPRECATED: will be removed in the next major version release |
18 | 18 | .filter('stripHtml', ['$showdown', stripHtmlFilter]); |
19 | 19 |
|
|
29 | 29 |
|
30 | 30 | // Configuration parameters for Showdown |
31 | 31 | var config = { |
32 | | - extensions: [] |
| 32 | + extensions: [], |
| 33 | + sanitize: false |
33 | 34 | }; |
34 | 35 |
|
35 | 36 | /** |
|
91 | 92 | this.stripHtml = function (text) { |
92 | 93 | return String(text).replace(/<[^>]+>/gm, ''); |
93 | 94 | }; |
| 95 | + |
| 96 | + /** |
| 97 | + * Gets the value of the configuration parameter of CONVERTER specified by key |
| 98 | + * @param {string} key The config parameter key |
| 99 | + * @returns {*} |
| 100 | + */ |
| 101 | + this.getOption = function (key) { |
| 102 | + return converter.getOption(key); |
| 103 | + }; |
| 104 | + |
| 105 | + /** |
| 106 | + * Gets the converter configuration params |
| 107 | + * @returns {*} |
| 108 | + */ |
| 109 | + this.getOptions = function () { |
| 110 | + return converter.getOptions(); |
| 111 | + }; |
94 | 112 | } |
95 | 113 |
|
96 | 114 | // The object returned by service provider |
|
107 | 125 | * <div sd-model-to-html="markdownText" ></div> |
108 | 126 | * |
109 | 127 | * @param {showdown.Converter} $showdown |
110 | | - * @param {$sce} $sce |
| 128 | + * @param {$sanitize} $sanitize |
111 | 129 | * @returns {*} |
112 | 130 | */ |
113 | | - function sdModelToHtmlDirective($showdown, $sce) { |
| 131 | + function sdModelToHtmlDirective($showdown, $sanitize) { |
114 | 132 | return { |
115 | 133 | restrict: 'A', |
116 | | - link: getLinkFn($showdown, $sce), |
| 134 | + link: getLinkFn($showdown, $sanitize), |
117 | 135 | scope: { |
118 | 136 | model: '=sdModelToHtml' |
119 | 137 | } |
|
127 | 145 | * <div markdown-to-html="markdownText" ></div> |
128 | 146 | * |
129 | 147 | * @param {showdown.Converter} $showdown |
130 | | - * @param {$sce} $sce |
| 148 | + * @param {$sanitize} $sanitize |
131 | 149 | * @returns {*} |
132 | 150 | */ |
133 | | - function markdownToHtmlDirective($showdown, $sce) { |
| 151 | + function markdownToHtmlDirective($showdown, $sanitize) { |
134 | 152 | return { |
135 | 153 | restrict: 'A', |
136 | | - link: getLinkFn($showdown, $sce), |
| 154 | + link: getLinkFn($showdown, $sanitize), |
137 | 155 | scope: { |
138 | 156 | model: '=markdownToHtml' |
139 | 157 | } |
140 | 158 | }; |
141 | 159 | } |
142 | 160 |
|
143 | | - function getLinkFn($showdown, $sce) { |
| 161 | + function getLinkFn($showdown, $sanitize) { |
144 | 162 | return function (scope, element) { |
145 | 163 | scope.$watch('model', function (newValue) { |
146 | | - var val; |
| 164 | + var val, |
| 165 | + showdownHTML; |
147 | 166 | if (typeof newValue === 'string') { |
148 | | - var showdownHTML = $showdown.makeHtml(newValue); |
149 | | - val = $sce.trustAsHtml(showdownHTML); |
| 167 | + showdownHTML = $showdown.makeHtml(newValue); |
| 168 | + val = ($showdown.getOption('sanitize')) ? $sanitize(showdownHTML) : showdownHTML; |
150 | 169 | } else { |
151 | 170 | val = typeof newValue; |
152 | 171 | } |
|
0 commit comments