Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bower_components/
node_modules/
26 changes: 26 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -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
}
}
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<btf-markdown>
Expand Down
77 changes: 48 additions & 29 deletions markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
})();
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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"
}
}