forked from Hypercubed/angular-marked
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular-marked.js
70 lines (53 loc) · 1.67 KB
/
angular-marked.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* angular-marked
* (c) 2014 J. Harshbarger
* Licensed MIT
*/
/* jshint undef: true, unused: true */
/* global angular:true */
(function() {
'use strict';
var app = angular.module('hc.marked', []);
//app.constant('marked', window.marked);
app.provider('marked', function() {
var self = this;
self.setOptions = function(opts) { // Store options for later
this.defaults = opts;
};
self.$get = ['$window',
function($window) {
var m = $window.marked;
self.setOptions = m.setOptions;
m.setOptions(self.defaults);
return m;
}
];
});
// TODO: filter tests */
//app.filter('marked', ['marked', function(marked) {
// return marked;
//}]);
app.directive('marked', ['marked',
function(marked) {
return {
restrict: 'AE',
replace: true,
scope: {
opts: '=',
marked: '='
},
link: function(scope, element, attrs) {
set(scope.marked || element.text() || '');
function set(val) {
element.html(marked(val || '', scope.opts || null));
if (MathJax)
MathJax.Hub.Queue(["Typeset", MathJax.Hub, element[0]]);
}
if (attrs.marked) {
scope.$watch('marked', set);
}
}
};
}
]);
}());