Skip to content

Commit b83a570

Browse files
committed
Merge pull request #17 from showdownjs/hotfix/issue_14
Hotfix/issue 14
2 parents 564d5be + ddd1d34 commit b83a570

File tree

6 files changed

+120
-30
lines changed

6 files changed

+120
-30
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ sudo: false
1616
cache:
1717
directories:
1818
- node_modules
19-
19+
- bower_components

dist/ng-showdown.js

Lines changed: 58 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ng-showdown.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ng-showdown.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ng-showdown.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ng-showdown.js

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
(function (module, showdown) {
1111
'use strict';
1212

13-
module.provider('$showdown', ngShowdown)
14-
.directive('sdModelToHtml', ['$showdown', '$sce', markdownToHtmlDirective]) //<-- DEPRECATED: will be removed in the next major version release
15-
.directive('markdownToHtml', ['$showdown', '$sce', markdownToHtmlDirective])
13+
module
14+
.provider('$showdown', ngShowdown)
15+
.directive('sdModelToHtml', ['$showdown', '$sanitize', '$sce', sdModelToHtmlDirective]) //<-- DEPRECATED: will be removed in the next major version release
16+
.directive('markdownToHtml', ['$showdown', '$sanitize', '$sce', markdownToHtmlDirective])
1617
.filter('sdStripHtml', ['$showdown', stripHtmlFilter]) //<-- DEPRECATED: will be removed in the next major version release
1718
.filter('stripHtml', ['$showdown', stripHtmlFilter]);
1819

@@ -28,7 +29,8 @@
2829

2930
// Configuration parameters for Showdown
3031
var config = {
31-
extensions: []
32+
extensions: [],
33+
sanitize: false
3234
};
3335

3436
/**
@@ -90,6 +92,23 @@
9092
this.stripHtml = function (text) {
9193
return String(text).replace(/<[^>]+>/gm, '');
9294
};
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+
};
93112
}
94113

95114
// The object returned by service provider
@@ -99,36 +118,62 @@
99118
}
100119

101120
/**
102-
* AngularJS Directive to Md to HTML transformation
121+
* @deprecated
122+
* Legacy AngularJS Directive to Md to HTML transformation
103123
*
104124
* Usage example:
105125
* <div sd-model-to-html="markdownText" ></div>
106126
*
107127
* @param {showdown.Converter} $showdown
128+
* @param {$sanitize} $sanitize
108129
* @param {$sce} $sce
109130
* @returns {*}
110131
*/
111-
function markdownToHtmlDirective($showdown, $sce) {
132+
function sdModelToHtmlDirective($showdown, $sanitize, $sce) {
112133
return {
113134
restrict: 'A',
114-
link: link,
135+
link: getLinkFn($showdown, $sanitize, $sce),
115136
scope: {
116137
model: '=sdModelToHtml'
117138
}
118139
};
140+
}
141+
142+
/**
143+
* AngularJS Directive to Md to HTML transformation
144+
*
145+
* Usage example:
146+
* <div markdown-to-html="markdownText" ></div>
147+
*
148+
* @param {showdown.Converter} $showdown
149+
* @param {$sanitize} $sanitize
150+
* @param {$sce} $sce
151+
* @returns {*}
152+
*/
153+
function markdownToHtmlDirective($showdown, $sanitize, $sce) {
154+
return {
155+
restrict: 'A',
156+
link: getLinkFn($showdown, $sanitize, $sce),
157+
scope: {
158+
model: '=markdownToHtml'
159+
}
160+
};
161+
}
119162

120-
function link(scope, element) {
163+
function getLinkFn($showdown, $sanitize, $sce) {
164+
return function (scope, element) {
121165
scope.$watch('model', function (newValue) {
122-
var val;
166+
var val,
167+
showdownHTML;
123168
if (typeof newValue === 'string') {
124-
var showdownHTML = $showdown.makeHtml(newValue);
125-
val = $sce.trustAsHtml(showdownHTML);
169+
showdownHTML = $showdown.makeHtml(newValue);
170+
val = ($showdown.getOption('sanitize')) ? $sanitize(showdownHTML) : $sce.trustAsHtml(showdownHTML);
126171
} else {
127172
val = typeof newValue;
128173
}
129174
element.html(val);
130175
});
131-
}
176+
};
132177
}
133178

134179
/**

0 commit comments

Comments
 (0)