diff --git a/.gitignore b/.gitignore index fbe05fc..0cfc89f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ bower_components/ +node_modules/ \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..d430ef2 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,26 @@ +{ + "node": true, + "browser": true, + "esnext": true, + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "indent": 2, + "latedef": true, + "newcap": true, + "noarg": true, + "quotmark": "single", + "regexp": true, + "undef": true, + "unused": true, + "strict": true, + "trailing": true, + "smarttabs": true, + "maxdepth": 2, + "maxcomplexity": 10, + "globals": { + "angular": false + } +} diff --git a/README.md b/README.md index dbfcff3..f5cee7c 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,29 @@ Bower Component for a simple AngularJS Markdown directive using [Showdown](https ## Usage + +### Bower + 1. `bower install angular-markdown-directive` 2. Include `angular-sanitize.js`. It should be located at `bower_components/angular-sanitize/`. 3. Include `showdown.js`. It should be located at `bower_components/showdown/`. 4. Include `markdown.js` provided by this component into your app. 5. Add `btford.markdown` as a module dependency to your app. -6. Insert the `btf-markdown` directive into your template: + +### NPM (and browserify) + +1. `npm install --save angular-markdown-directive` +2. `npm install --save angular-sanitize` +4. Require `angular-sanitize` and `angular-markdown-directive/markdown` provided by this component into your app. + ``` + require('angular-sanitize/angular-sanitize'); + require('angular-markdown-directive/markdown.js'); + ``` +5. Add `btford.markdown` as a module dependency to your app + +### Using the directive + +Insert the `btf-markdown` directive into your template: ```html diff --git a/markdown.js b/markdown.js index 989a6be..8360386 100644 --- a/markdown.js +++ b/markdown.js @@ -4,33 +4,52 @@ * License: MIT */ -'use strict'; +'format global'; /* global define */ +'deps angular'; +'deps angular-sanitize'; +'deps showdown'; -angular.module('btford.markdown', ['ngSanitize']). - provider('markdownConverter', function () { - var opts = {}; - return { - config: function (newOpts) { - opts = newOpts; - }, - $get: function () { - return new Showdown.converter(opts); - } - }; - }). - directive('btfMarkdown', ['$sanitize', 'markdownConverter', function ($sanitize, markdownConverter) { - return { - restrict: 'AE', - link: function (scope, element, attrs) { - if (attrs.btfMarkdown) { - scope.$watch(attrs.btfMarkdown, function (newVal) { - var html = newVal ? $sanitize(markdownConverter.makeHtml(newVal)) : ''; - element.html(html); - }); - } else { - var html = $sanitize(markdownConverter.makeHtml(element.text())); - element.html(html); - } - } - }; - }]); +(function () { + 'use strict'; + + function angularMarkdown(angular, Showdown) { + + angular.module('btford.markdown', ['ngSanitize']) + .constant('Showdown', Showdown) + .provider('markdownConverter', ['Showdown', function (Showdown) { + var opts = {}; + return { + config: function (newOpts) { + opts = newOpts; + }, + $get: function () { + return new Showdown.Converter(opts); + } + }; + }]) + .directive('btfMarkdown', ['$sanitize', 'markdownConverter', function ($sanitize, markdownConverter) { + return { + restrict: 'AE', + link: function (scope, element, attrs) { + if (attrs.btfMarkdown) { + scope.$watch(attrs.btfMarkdown, function (newVal) { + var html = newVal ? $sanitize(markdownConverter.makeHtml(newVal)) : ''; + element.html(html); + }); + } else { + var html = $sanitize(markdownConverter.makeHtml(element.text())); + element.html(html); + } + } + }; + }]); + } + + if (typeof define === 'function' && define.amd) { + define('angular-markdown-directive', ['angular', 'showdown'], angularMarkdown); + } else if (typeof module !== 'undefined' && module && module.exports && typeof require !== 'undefined') { + angularMarkdown(angular, require('showdown')); + } else { + angularMarkdown(angular, window.Showdown); + } +})(); \ No newline at end of file diff --git a/package.json b/package.json index b245c18..94a93d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-markdown-directive", - "version": "0.3.1", + "version": "0.3.1-browserify.1", "description": "simple AngularJS markdown directive with showdown", "main": "markdown.js", "scripts": { @@ -27,5 +27,8 @@ "karma-jasmine": "^0.1.5", "karma-firefox-launcher": "^0.1.3", "karma-chrome-launcher": "^0.1.3" + }, + "dependencies": { + "showdown": "git+https://github.com/showdownjs/showdown#showdown2" } }