-
Notifications
You must be signed in to change notification settings - Fork 668
Expand file tree
/
Copy pathmarkdown-directive.js
More file actions
41 lines (37 loc) · 1.25 KB
/
markdown-directive.js
File metadata and controls
41 lines (37 loc) · 1.25 KB
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
angular
.module('gcloud.markdown')
.directive('gcloudMarkdown', function (mdConverter, mdDeeplink, $http, $sce, $compile, $location, $window, $timeout) {
return {
retstrict: 'A',
link: function (scope, element, attrs) {
// could be cross domain, but that's ok!
var markdown = $sce.trustAsResourceUrl(attrs.gcloudMarkdown);
// fetch markdown
$http.get(markdown).then(function (resp) {
var html, blocks;
// make it pretty!
html = mdConverter.makeHtml(resp.data);
element.html(html);
blocks = element.find('pre').find('code');
angular.forEach(blocks, hljs.highlightBlock);
// this will trigger any directives inside the markdown
// e.g. "hljs-class"
$compile(element.contents())(scope);
// wrapping in timeout to get around paint lag
$timeout(function () {
mdDeeplink($location.search().section)
}, 50);
});
}
};
})
.directive('gcloudScroll', function (mdDeeplink, $location) {
return {
restrict: 'A',
link: function (scope, elem, attrs) {
elem.on('click', function (e) {
mdDeeplink(attrs.gcloudScroll);
});
}
}
});