ng-showdown
Advanced tools
Comparing version
@@ -37,3 +37,6 @@ { | ||
], | ||
"license": "https://github.com/showdownjs/ng-showdown/blob/master/license.txt" | ||
"license": "https://github.com/showdownjs/ng-showdown/blob/master/license.txt", | ||
"devDependencies": { | ||
"angular-mocks": "~1.4.3" | ||
} | ||
} |
@@ -0,0 +0,0 @@ <a name"1.0.0"></a> |
@@ -1,154 +0,213 @@ | ||
;/*! ng-showdown 18-07-2015 */ | ||
(function (angular, showdown) { | ||
// Conditional load for NodeJS | ||
if (typeof require !== 'undefined') { | ||
angular = require('angular'); | ||
showdown = require('showdown'); | ||
;/*! ng-showdown 19-10-2015 */ | ||
(function (root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define(['angular', 'showdown'], factory); | ||
} else if (typeof module === 'object' && module.exports) { | ||
// Node. Does not work with strict CommonJS, but | ||
// only CommonJS-like environments that support module.exports, | ||
// like Node. | ||
module.exports = factory(require('angular'), require('showdown')); | ||
} else { | ||
// Browser globals (root is window) | ||
root.ngShowdown = factory(root.angular, root.showdown); | ||
} | ||
}(this, function (angular, showdown) { | ||
//Check if AngularJs and Showdown is defined and only load ng-Showdown if both are present | ||
if (typeof angular !== 'undefined' && typeof showdown !== 'undefined') { | ||
(function (module, showdown) { | ||
'use strict'; | ||
if (typeof angular === 'undefined' || typeof showdown === 'undefined') { | ||
throw new Error('ng-showdown was not loaded because one of its dependencies (AngularJS or Showdown) was not met'); | ||
} | ||
module.provider('$showdown', ngShowdown) | ||
.directive('sdModelToHtml', ['$showdown', '$sce', markdownToHtmlDirective]) //<-- DEPRECATED: will be removed in the next major version release | ||
.directive('markdownToHtml', ['$showdown', '$sce', markdownToHtmlDirective]) | ||
.filter('sdStripHtml', ['$showdown', stripHtmlFilter]) //<-- DEPRECATED: will be removed in the next major version release | ||
.filter('stripHtml', ['$showdown', stripHtmlFilter]); | ||
angular.module('ng-showdown', ['ngSanitize']) | ||
.provider('$showdown', ngShowdown) | ||
.directive('sdModelToHtml', ['$showdown', '$sanitize', '$sce', sdModelToHtmlDirective]) //<-- DEPRECATED: will be removed in the next major version release | ||
.directive('markdownToHtml', ['$showdown', '$sanitize', '$sce', markdownToHtmlDirective]) | ||
.filter('sdStripHtml', ['$showdown', stripHtmlFilter]) //<-- DEPRECATED: will be removed in the next major version release | ||
.filter('stripHtml', ['$showdown', stripHtmlFilter]); | ||
/** | ||
* Angular Provider | ||
* Enables configuration of showdown via angular.config and Dependency Injection into controllers, views | ||
* directives, etc... This assures the directives and filters provided by the library itself stay consistent | ||
* with the user configurations. | ||
* If the user wants to use a different configuration in a determined context, he can use the "classic" Showdown | ||
* object instead. | ||
*/ | ||
function ngShowdown() { | ||
/** | ||
* Angular Provider | ||
* Enables configuration of showdown via angular.config and Dependency Injection into controllers, views | ||
* directives, etc... This assures the directives and filters provided by the library itself stay consistent | ||
* with the user configurations. | ||
* If the user wants to use a different configuration in a determined context, he can use the "classic" Showdown | ||
* object instead. | ||
*/ | ||
function ngShowdown() { | ||
// Configuration parameters for Showdown | ||
var config = { | ||
extensions: [] | ||
}; | ||
// Configuration parameters for Showdown | ||
var config = { | ||
extensions: [], | ||
sanitize: false | ||
}; | ||
/** | ||
* Sets a configuration option | ||
* | ||
* @param {string} key Config parameter key | ||
* @param {string} value Config parameter value | ||
*/ | ||
/* jshint validthis: true */ | ||
this.setOption = function (key, value) { | ||
config[key] = value; | ||
return this; | ||
}; | ||
/** | ||
* Sets a configuration option | ||
* | ||
* @param {string} key Config parameter key | ||
* @param {string} value Config parameter value | ||
*/ | ||
/* jshint validthis: true */ | ||
this.setOption = function (key, value) { | ||
config[key] = value; | ||
return this; | ||
}; | ||
/** | ||
* Gets the value of the configuration parameter specified by key | ||
* | ||
* @param {string} key The config parameter key | ||
* @returns {string|null} Returns the value of the config parameter. (or null if the config parameter is not set) | ||
*/ | ||
this.getOption = function (key) { | ||
if (config.hasOwnProperty(key)) { | ||
return config[key]; | ||
} else { | ||
return undefined; | ||
} | ||
}; | ||
/** | ||
* Gets the value of the configuration parameter specified by key | ||
* | ||
* @param {string} key The config parameter key | ||
* @returns {string|null} Returns the value of the config parameter. (or null if the config parameter is not set) | ||
*/ | ||
this.getOption = function (key) { | ||
if (config.hasOwnProperty(key)) { | ||
return config[key]; | ||
} else { | ||
return undefined; | ||
} | ||
}; | ||
/** | ||
* Loads a Showdown Extension | ||
* | ||
* @param {string} extensionName The name of the extension to load | ||
*/ | ||
this.loadExtension = function (extensionName) { | ||
config.extensions.push(extensionName); | ||
/** | ||
* Loads a Showdown Extension | ||
* | ||
* @param {string} extensionName The name of the extension to load | ||
*/ | ||
this.loadExtension = function (extensionName) { | ||
config.extensions.push(extensionName); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
function SDObject() { | ||
var converter = new showdown.Converter(config); | ||
function SDObject() { | ||
var converter = new showdown.Converter(config); | ||
/** | ||
* Converts a markdown text into HTML | ||
* | ||
* @param {string} markdown The markdown string to be converted to HTML | ||
* @returns {string} The converted HTML | ||
*/ | ||
this.makeHtml = function (markdown) { | ||
return converter.makeHtml(markdown); | ||
}; | ||
/** | ||
* Converts a markdown text into HTML | ||
* | ||
* @param {string} markdown The markdown string to be converted to HTML | ||
* @returns {string} The converted HTML | ||
*/ | ||
this.makeHtml = function (markdown) { | ||
return converter.makeHtml(markdown); | ||
}; | ||
/** | ||
* Strips a text of it's HTML tags. See http://stackoverflow.com/questions/17289448/angularjs-to-output-plain-text-instead-of-html | ||
* | ||
* @param {string} text | ||
* @returns {string} | ||
*/ | ||
this.stripHtml = function (text) { | ||
return String(text).replace(/<[^>]+>/gm, ''); | ||
}; | ||
} | ||
/** | ||
* Strips a text of it's HTML tags. See http://stackoverflow.com/questions/17289448/angularjs-to-output-plain-text-instead-of-html | ||
* | ||
* @param {string} text | ||
* @returns {string} | ||
*/ | ||
this.stripHtml = function (text) { | ||
return String(text).replace(/<[^>]+>/gm, ''); | ||
}; | ||
// The object returned by service provider | ||
this.$get = function () { | ||
return new SDObject(); | ||
}; | ||
} | ||
/** | ||
* Gets the value of the configuration parameter of CONVERTER specified by key | ||
* @param {string} key The config parameter key | ||
* @returns {*} | ||
*/ | ||
this.getOption = function (key) { | ||
return converter.getOption(key); | ||
}; | ||
/** | ||
* AngularJS Directive to Md to HTML transformation | ||
* | ||
* Usage example: | ||
* <div sd-model-to-html="markdownText" ></div> | ||
* | ||
* @param {showdown.Converter} $showdown | ||
* @param {$sce} $sce | ||
* Gets the converter configuration params | ||
* @returns {*} | ||
*/ | ||
function markdownToHtmlDirective($showdown, $sce) { | ||
return { | ||
restrict: 'A', | ||
link: link, | ||
scope: { | ||
model: '=sdModelToHtml' | ||
} | ||
}; | ||
this.getOptions = function () { | ||
return converter.getOptions(); | ||
}; | ||
function link(scope, element) { | ||
scope.$watch('model', function (newValue) { | ||
var val; | ||
if (typeof newValue === 'string') { | ||
var showdownHTML = $showdown.makeHtml(newValue); | ||
val = $sce.trustAsHtml(showdownHTML); | ||
} else { | ||
val = typeof newValue; | ||
} | ||
element.html(val); | ||
}); | ||
} | ||
} | ||
/** | ||
* AngularJS Filter to Strip HTML tags from text | ||
* Sets a configuration option | ||
* | ||
* @returns {Function} | ||
* @param {string} key Config parameter key | ||
* @param {string} value Config parameter value | ||
* @returns {SDObject} | ||
*/ | ||
function stripHtmlFilter($showdown) { | ||
return function (text) { | ||
return $showdown.stripHtml(text); | ||
}; | ||
} | ||
this.setOption = function (key, value) { | ||
converter.setOption(key, value); | ||
return this; | ||
}; | ||
} | ||
})(angular.module('ng-showdown', ['ngSanitize']), showdown); | ||
// The object returned by service provider | ||
this.$get = function () { | ||
return new SDObject(); | ||
}; | ||
} | ||
} else { | ||
throw new Error('ng-showdown was not loaded because one of its dependencies (AngularJS or Showdown) was not met'); | ||
/** | ||
* @deprecated | ||
* Legacy AngularJS Directive to Md to HTML transformation | ||
* | ||
* Usage example: | ||
* <div sd-model-to-html="markdownText" ></div> | ||
* | ||
* @param {showdown.Converter} $showdown | ||
* @param {$sanitize} $sanitize | ||
* @param {$sce} $sce | ||
* @returns {*} | ||
*/ | ||
function sdModelToHtmlDirective($showdown, $sanitize, $sce) { | ||
return { | ||
restrict: 'A', | ||
link: getLinkFn($showdown, $sanitize, $sce), | ||
scope: { | ||
model: '=sdModelToHtml' | ||
}, | ||
template: '<div ng-bind-html="trustedHtml"></div>' | ||
}; | ||
} | ||
})(angular, showdown); | ||
/** | ||
* AngularJS Directive to Md to HTML transformation | ||
* | ||
* Usage example: | ||
* <div markdown-to-html="markdownText" ></div> | ||
* | ||
* @param {showdown.Converter} $showdown | ||
* @param {$sanitize} $sanitize | ||
* @param {$sce} $sce | ||
* @returns {*} | ||
*/ | ||
function markdownToHtmlDirective($showdown, $sanitize, $sce) { | ||
return { | ||
restrict: 'A', | ||
link: getLinkFn($showdown, $sanitize, $sce), | ||
scope: { | ||
model: '=markdownToHtml' | ||
}, | ||
template: '<div ng-bind-html="trustedHtml"></div>' | ||
}; | ||
} | ||
function getLinkFn($showdown, $sanitize, $sce) { | ||
return function (scope, element, attrs) { | ||
scope.$watch('model', function (newValue) { | ||
var showdownHTML; | ||
if (typeof newValue === 'string') { | ||
showdownHTML = $showdown.makeHtml(newValue); | ||
scope.trustedHtml = ($showdown.getOption('sanitize')) ? $sanitize(showdownHTML) : $sce.trustAsHtml(showdownHTML); | ||
} else { | ||
scope.trustedHtml = typeof newValue; | ||
} | ||
}); | ||
}; | ||
} | ||
/** | ||
* AngularJS Filter to Strip HTML tags from text | ||
* | ||
* @returns {Function} | ||
*/ | ||
function stripHtmlFilter($showdown) { | ||
return function (text) { | ||
return $showdown.stripHtml(text); | ||
}; | ||
} | ||
return angular.module('ng-showdown'); | ||
})); | ||
//# sourceMappingURL=ng-showdown.js.map |
@@ -1,4 +0,4 @@ | ||
/*! ng-showdown 13-07-2015 */ | ||
/*! ng-showdown 19-10-2015 */ | ||
!function(a,b){if("undefined"!=typeof require&&(a=require("angular"),b=require("showdown")),"undefined"==typeof a||"undefined"==typeof b)throw new Error("ng-showdown was not loaded because one of its dependencies (AngularJS or Showdown) was not met");!function(a,b){"use strict";function c(){function a(){var a=new b.Converter(c);this.makeHtml=function(b){return a.makeHtml(b)},this.stripHtml=function(a){return String(a).replace(/<[^>]+>/gm,"")}}var c={extensions:[],stripHtml:!0};this.setOption=function(a,b){return c[a]=b,this},this.getOption=function(a){return c.hasOwnProperty(a)?c.key:null},this.loadExtension=function(a){return c.extensions.push(a),this},this.$get=function(){return new a}}function d(a,b){var c=function(c,d){c.$watch("model",function(c){var e;if("string"==typeof c){var f=a.makeHtml(c);e=b.trustAsHtml(f)}else e=typeof c;d.html(e)})};return{restrict:"A",link:c,scope:{model:"=sdModelToHtml"}}}function e(){return function(a){return String(a).replace(/<[^>]+>/gm,"")}}a.provider("$showdown",c).directive("sdModelToHtml",["$showdown","$sce",d]).filter("sdStripHtml",e)}(a.module("ng-showdown",["ngSanitize"]),b)}(angular,showdown); | ||
!function(a,b){"function"==typeof define&&define.amd?define(["angular","showdown"],b):"object"==typeof module&&module.exports?module.exports=b(require("angular"),require("showdown")):a.ngShowdown=b(a.angular,a.showdown)}(this,function(a,b){function c(){function a(){var a=new b.Converter(c);this.makeHtml=function(b){return a.makeHtml(b)},this.stripHtml=function(a){return String(a).replace(/<[^>]+>/gm,"")},this.getOption=function(b){return a.getOption(b)},this.getOptions=function(){return a.getOptions()},this.setOption=function(b,c){return a.setOption(b,c),this}}var c={extensions:[],sanitize:!1};this.setOption=function(a,b){return c[a]=b,this},this.getOption=function(a){return c.hasOwnProperty(a)?c[a]:void 0},this.loadExtension=function(a){return c.extensions.push(a),this},this.$get=function(){return new a}}function d(a,b,c){return{restrict:"A",link:f(a,b,c),scope:{model:"=sdModelToHtml"},template:'<div ng-bind-html="trustedHtml"></div>'}}function e(a,b,c){return{restrict:"A",link:f(a,b,c),scope:{model:"=markdownToHtml"},template:'<div ng-bind-html="trustedHtml"></div>'}}function f(a,b,c){return function(d,e,f){d.$watch("model",function(e){var f;"string"==typeof e?(f=a.makeHtml(e),d.trustedHtml=a.getOption("sanitize")?b(f):c.trustAsHtml(f)):d.trustedHtml=typeof e})}}function g(a){return function(b){return a.stripHtml(b)}}if("undefined"==typeof a||"undefined"==typeof b)throw new Error("ng-showdown was not loaded because one of its dependencies (AngularJS or Showdown) was not met");return a.module("ng-showdown",["ngSanitize"]).provider("$showdown",c).directive("sdModelToHtml",["$showdown","$sanitize","$sce",d]).directive("markdownToHtml",["$showdown","$sanitize","$sce",e]).filter("sdStripHtml",["$showdown",g]).filter("stripHtml",["$showdown",g]),a.module("ng-showdown")}); | ||
//# sourceMappingURL=ng-showdown.min.js.map |
@@ -10,14 +10,14 @@ module.exports = function (config) { | ||
files: [ | ||
'bower_components/angular/angular.js', | ||
'bower_components/angular-mocks/angular-mocks.js', | ||
'bower_components/angular-sanitize/angular-sanitize.js', | ||
'bower_components/showdown/dist/showdown.js', | ||
'src/*.js', | ||
'test/**/*.spec.js' | ||
'./bower_components/angular/angular.js', | ||
'./bower_components/angular-mocks/angular-mocks.js', | ||
'./bower_components/angular-sanitize/angular-sanitize.js', | ||
'./bower_components/showdown/dist/showdown.js', | ||
'./src/*.js', | ||
'./test/**/*.spec.js' | ||
], | ||
reporters: ['coverage'], | ||
reporters: ['progress', 'coverage'], | ||
preprocessors: { | ||
'src/**/*.js' : ['progress', 'coverage'] | ||
'src/**/*.js' : ['coverage'] | ||
}, | ||
@@ -24,0 +24,0 @@ |
{ | ||
"name": "ng-showdown", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Official Showdown integration with AngularJS", | ||
@@ -25,2 +25,3 @@ "authors": [ | ||
"devDependencies": { | ||
"angular-mocks": "^1.4.3", | ||
"chai": "^1.10.0", | ||
@@ -27,0 +28,0 @@ "grunt": "^0.4.5", |
@@ -22,2 +22,11 @@ # ng-showdown | ||
``` | ||
## Dependencies | ||
ng-showdown depends on the [ngSanitize module](https://docs.angularjs.org/api/ngSanitize). Don't forget to include it: | ||
```html | ||
<script src="angular.js"></script> | ||
<script src="angular-sanitize.js"></script> | ||
``` | ||
@@ -36,3 +45,3 @@ ## API | ||
Input: *string* - html to be striped | ||
Input: *string* - html to be stripped | ||
@@ -65,3 +74,3 @@ Output: *string* - string without `<html>` tags | ||
You can configure the options and extensions passed to showdown by useing the `$showdownProvider`. To see these options, visit the [Showdown page](https://github.com/showdownjs/showdown). | ||
You can configure the options and extensions passed to showdown by using the `$showdownProvider`. To see these options, visit the [Showdown page](https://github.com/showdownjs/showdown). | ||
@@ -68,0 +77,0 @@ `$showdownProvider.setOption(key, value)` - sets the passed in option as a configuration option in showdown |
@@ -1,151 +0,210 @@ | ||
(function (angular, showdown) { | ||
// Conditional load for NodeJS | ||
if (typeof require !== 'undefined') { | ||
angular = require('angular'); | ||
showdown = require('showdown'); | ||
(function (root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define(['angular', 'showdown'], factory); | ||
} else if (typeof module === 'object' && module.exports) { | ||
// Node. Does not work with strict CommonJS, but | ||
// only CommonJS-like environments that support module.exports, | ||
// like Node. | ||
module.exports = factory(require('angular'), require('showdown')); | ||
} else { | ||
// Browser globals (root is window) | ||
root.ngShowdown = factory(root.angular, root.showdown); | ||
} | ||
}(this, function (angular, showdown) { | ||
//Check if AngularJs and Showdown is defined and only load ng-Showdown if both are present | ||
if (typeof angular !== 'undefined' && typeof showdown !== 'undefined') { | ||
(function (module, showdown) { | ||
'use strict'; | ||
if (typeof angular === 'undefined' || typeof showdown === 'undefined') { | ||
throw new Error('ng-showdown was not loaded because one of its dependencies (AngularJS or Showdown) was not met'); | ||
} | ||
module.provider('$showdown', ngShowdown) | ||
.directive('sdModelToHtml', ['$showdown', '$sce', markdownToHtmlDirective]) //<-- DEPRECATED: will be removed in the next major version release | ||
.directive('markdownToHtml', ['$showdown', '$sce', markdownToHtmlDirective]) | ||
.filter('sdStripHtml', ['$showdown', stripHtmlFilter]) //<-- DEPRECATED: will be removed in the next major version release | ||
.filter('stripHtml', ['$showdown', stripHtmlFilter]); | ||
angular.module('ng-showdown', ['ngSanitize']) | ||
.provider('$showdown', ngShowdown) | ||
.directive('sdModelToHtml', ['$showdown', '$sanitize', '$sce', sdModelToHtmlDirective]) //<-- DEPRECATED: will be removed in the next major version release | ||
.directive('markdownToHtml', ['$showdown', '$sanitize', '$sce', markdownToHtmlDirective]) | ||
.filter('sdStripHtml', ['$showdown', stripHtmlFilter]) //<-- DEPRECATED: will be removed in the next major version release | ||
.filter('stripHtml', ['$showdown', stripHtmlFilter]); | ||
/** | ||
* Angular Provider | ||
* Enables configuration of showdown via angular.config and Dependency Injection into controllers, views | ||
* directives, etc... This assures the directives and filters provided by the library itself stay consistent | ||
* with the user configurations. | ||
* If the user wants to use a different configuration in a determined context, he can use the "classic" Showdown | ||
* object instead. | ||
*/ | ||
function ngShowdown() { | ||
/** | ||
* Angular Provider | ||
* Enables configuration of showdown via angular.config and Dependency Injection into controllers, views | ||
* directives, etc... This assures the directives and filters provided by the library itself stay consistent | ||
* with the user configurations. | ||
* If the user wants to use a different configuration in a determined context, he can use the "classic" Showdown | ||
* object instead. | ||
*/ | ||
function ngShowdown() { | ||
// Configuration parameters for Showdown | ||
var config = { | ||
extensions: [] | ||
}; | ||
// Configuration parameters for Showdown | ||
var config = { | ||
extensions: [], | ||
sanitize: false | ||
}; | ||
/** | ||
* Sets a configuration option | ||
* | ||
* @param {string} key Config parameter key | ||
* @param {string} value Config parameter value | ||
*/ | ||
/* jshint validthis: true */ | ||
this.setOption = function (key, value) { | ||
config[key] = value; | ||
return this; | ||
}; | ||
/** | ||
* Sets a configuration option | ||
* | ||
* @param {string} key Config parameter key | ||
* @param {string} value Config parameter value | ||
*/ | ||
/* jshint validthis: true */ | ||
this.setOption = function (key, value) { | ||
config[key] = value; | ||
return this; | ||
}; | ||
/** | ||
* Gets the value of the configuration parameter specified by key | ||
* | ||
* @param {string} key The config parameter key | ||
* @returns {string|null} Returns the value of the config parameter. (or null if the config parameter is not set) | ||
*/ | ||
this.getOption = function (key) { | ||
if (config.hasOwnProperty(key)) { | ||
return config[key]; | ||
} else { | ||
return undefined; | ||
} | ||
}; | ||
/** | ||
* Gets the value of the configuration parameter specified by key | ||
* | ||
* @param {string} key The config parameter key | ||
* @returns {string|null} Returns the value of the config parameter. (or null if the config parameter is not set) | ||
*/ | ||
this.getOption = function (key) { | ||
if (config.hasOwnProperty(key)) { | ||
return config[key]; | ||
} else { | ||
return undefined; | ||
} | ||
}; | ||
/** | ||
* Loads a Showdown Extension | ||
* | ||
* @param {string} extensionName The name of the extension to load | ||
*/ | ||
this.loadExtension = function (extensionName) { | ||
config.extensions.push(extensionName); | ||
/** | ||
* Loads a Showdown Extension | ||
* | ||
* @param {string} extensionName The name of the extension to load | ||
*/ | ||
this.loadExtension = function (extensionName) { | ||
config.extensions.push(extensionName); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
function SDObject() { | ||
var converter = new showdown.Converter(config); | ||
function SDObject() { | ||
var converter = new showdown.Converter(config); | ||
/** | ||
* Converts a markdown text into HTML | ||
* | ||
* @param {string} markdown The markdown string to be converted to HTML | ||
* @returns {string} The converted HTML | ||
*/ | ||
this.makeHtml = function (markdown) { | ||
return converter.makeHtml(markdown); | ||
}; | ||
/** | ||
* Converts a markdown text into HTML | ||
* | ||
* @param {string} markdown The markdown string to be converted to HTML | ||
* @returns {string} The converted HTML | ||
*/ | ||
this.makeHtml = function (markdown) { | ||
return converter.makeHtml(markdown); | ||
}; | ||
/** | ||
* Strips a text of it's HTML tags. See http://stackoverflow.com/questions/17289448/angularjs-to-output-plain-text-instead-of-html | ||
* | ||
* @param {string} text | ||
* @returns {string} | ||
*/ | ||
this.stripHtml = function (text) { | ||
return String(text).replace(/<[^>]+>/gm, ''); | ||
}; | ||
} | ||
/** | ||
* Strips a text of it's HTML tags. See http://stackoverflow.com/questions/17289448/angularjs-to-output-plain-text-instead-of-html | ||
* | ||
* @param {string} text | ||
* @returns {string} | ||
*/ | ||
this.stripHtml = function (text) { | ||
return String(text).replace(/<[^>]+>/gm, ''); | ||
}; | ||
// The object returned by service provider | ||
this.$get = function () { | ||
return new SDObject(); | ||
}; | ||
} | ||
/** | ||
* Gets the value of the configuration parameter of CONVERTER specified by key | ||
* @param {string} key The config parameter key | ||
* @returns {*} | ||
*/ | ||
this.getOption = function (key) { | ||
return converter.getOption(key); | ||
}; | ||
/** | ||
* AngularJS Directive to Md to HTML transformation | ||
* | ||
* Usage example: | ||
* <div sd-model-to-html="markdownText" ></div> | ||
* | ||
* @param {showdown.Converter} $showdown | ||
* @param {$sce} $sce | ||
* Gets the converter configuration params | ||
* @returns {*} | ||
*/ | ||
function markdownToHtmlDirective($showdown, $sce) { | ||
return { | ||
restrict: 'A', | ||
link: link, | ||
scope: { | ||
model: '=sdModelToHtml' | ||
} | ||
}; | ||
this.getOptions = function () { | ||
return converter.getOptions(); | ||
}; | ||
function link(scope, element) { | ||
scope.$watch('model', function (newValue) { | ||
var val; | ||
if (typeof newValue === 'string') { | ||
var showdownHTML = $showdown.makeHtml(newValue); | ||
val = $sce.trustAsHtml(showdownHTML); | ||
} else { | ||
val = typeof newValue; | ||
} | ||
element.html(val); | ||
}); | ||
} | ||
} | ||
/** | ||
* AngularJS Filter to Strip HTML tags from text | ||
* Sets a configuration option | ||
* | ||
* @returns {Function} | ||
* @param {string} key Config parameter key | ||
* @param {string} value Config parameter value | ||
* @returns {SDObject} | ||
*/ | ||
function stripHtmlFilter($showdown) { | ||
return function (text) { | ||
return $showdown.stripHtml(text); | ||
}; | ||
} | ||
this.setOption = function (key, value) { | ||
converter.setOption(key, value); | ||
return this; | ||
}; | ||
} | ||
})(angular.module('ng-showdown', ['ngSanitize']), showdown); | ||
// The object returned by service provider | ||
this.$get = function () { | ||
return new SDObject(); | ||
}; | ||
} | ||
} else { | ||
throw new Error('ng-showdown was not loaded because one of its dependencies (AngularJS or Showdown) was not met'); | ||
/** | ||
* @deprecated | ||
* Legacy AngularJS Directive to Md to HTML transformation | ||
* | ||
* Usage example: | ||
* <div sd-model-to-html="markdownText" ></div> | ||
* | ||
* @param {showdown.Converter} $showdown | ||
* @param {$sanitize} $sanitize | ||
* @param {$sce} $sce | ||
* @returns {*} | ||
*/ | ||
function sdModelToHtmlDirective($showdown, $sanitize, $sce) { | ||
return { | ||
restrict: 'A', | ||
link: getLinkFn($showdown, $sanitize, $sce), | ||
scope: { | ||
model: '=sdModelToHtml' | ||
}, | ||
template: '<div ng-bind-html="trustedHtml"></div>' | ||
}; | ||
} | ||
})(angular, showdown); | ||
/** | ||
* AngularJS Directive to Md to HTML transformation | ||
* | ||
* Usage example: | ||
* <div markdown-to-html="markdownText" ></div> | ||
* | ||
* @param {showdown.Converter} $showdown | ||
* @param {$sanitize} $sanitize | ||
* @param {$sce} $sce | ||
* @returns {*} | ||
*/ | ||
function markdownToHtmlDirective($showdown, $sanitize, $sce) { | ||
return { | ||
restrict: 'A', | ||
link: getLinkFn($showdown, $sanitize, $sce), | ||
scope: { | ||
model: '=markdownToHtml' | ||
}, | ||
template: '<div ng-bind-html="trustedHtml"></div>' | ||
}; | ||
} | ||
function getLinkFn($showdown, $sanitize, $sce) { | ||
return function (scope, element, attrs) { | ||
scope.$watch('model', function (newValue) { | ||
var showdownHTML; | ||
if (typeof newValue === 'string') { | ||
showdownHTML = $showdown.makeHtml(newValue); | ||
scope.trustedHtml = ($showdown.getOption('sanitize')) ? $sanitize(showdownHTML) : $sce.trustAsHtml(showdownHTML); | ||
} else { | ||
scope.trustedHtml = typeof newValue; | ||
} | ||
}); | ||
}; | ||
} | ||
/** | ||
* AngularJS Filter to Strip HTML tags from text | ||
* | ||
* @returns {Function} | ||
*/ | ||
function stripHtmlFilter($showdown) { | ||
return function (text) { | ||
return $showdown.stripHtml(text); | ||
}; | ||
} | ||
return angular.module('ng-showdown'); | ||
})); |
@@ -39,3 +39,3 @@ describe('Showdown', function () { | ||
element = createDirective(markdown); | ||
expect(element.html()).to.be.equal(parsedHtml); | ||
expect(element.html()).to.be.equal('<div ng-bind-html="trustedHtml" class="ng-binding">' + parsedHtml + '</div>'); | ||
}); | ||
@@ -42,0 +42,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
52084
23.62%725
20.03%80
12.68%20
5.26%