forked from evgenyneu/angular-markdown-preview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown_preview.js
More file actions
46 lines (40 loc) · 1.32 KB
/
markdown_preview.js
File metadata and controls
46 lines (40 loc) · 1.32 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
42
43
44
45
46
(function() {
'use strict';
angular.module('evgenyneu.markdown-preview', [])
.controller('Ctrl', ['$scope', '$window', '$http', '$sce',
function($scope, $window, $http, $sce) {
$scope.md2Html = function() {
$scope.html = $window.marked($scope.markdown);
$scope.htmlSafe = $sce.trustAsHtml($scope.html);
};
$scope.initFromUrl = function(url) {
$http.get(url).success(function(data) {
$scope.markdown = data;
return $scope.md2Html();
});
};
$scope.initFromText = function(text) {
$scope.markdown = text;
$scope.md2Html();
};
}
])
.directive('iiMdPreview', function() {
return {
template: "<div layout><textarea class='MdPreview-markdown' name='{{textareaName}}' ng-model='body' ng-change='md2Html()' flex='50' style='order:1 !important;'></textarea><div class='MdPreview-html' ng-bind-html='htmlSafe' flex='50' style='order:2 !important;'/></div>",
restrict: 'C',
replace: true,
controller: 'Ctrl',
scope: {},
link: function(scope, element, attrs) {
if (attrs.url) {
scope.initFromUrl(attrs.url);
}
if (attrs.text) {
scope.initFromText(attrs.text);
}
scope.textareaName = attrs.textareaName;
}
};
});
}).call(this);