Created
December 18, 2013 09:14
-
-
Save Hypercubed/8019475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* angular-marked-directive v0.0.1 | |
* (c) 2013 J. Harshbarger | |
* License: MIT | |
*/ | |
/* | |
Config: | |
app.config(['marked', function(marked) { | |
marked.setOptions({ | |
gfm: false, | |
tables: true, | |
breaks: false, | |
pedantic: false, | |
sanitize: true, | |
smartLists: true, | |
smartypants: false, | |
}); | |
}]); | |
In Controller: | |
function exampleController(marked) { | |
$scope.html = marked('#TEST'); | |
}; | |
In views: | |
<marked>##TEXT 1</marked> | |
<div marked>##TEXT 2</div> | |
<div ng-init="scope_element = '##TEST 4'"><div marked="scope_element"></div></div> | |
<div marked="'##TEXT 3'"></div> | |
<div marked opts="{gfm: true}"></div> | |
<div marked ng-include="'filename.md'"></div> | |
*/ | |
(function () { | |
var app = angular.module('marked', []); | |
app.constant('marked', marked); | |
app.directive("marked", ['$http', 'marked', function ($http, marked) { | |
return { | |
restrict: 'AE', | |
replace: true, | |
scope: { | |
opts: '=', | |
marked: '=' | |
}, | |
link: function (scope, element, attrs) { | |
if (attrs.marked) { | |
scope.$watch('marked', function(value) { | |
element.html(marked(value || '', scope.opts || null)); | |
}); | |
} else { | |
element.html(marked(element.text(), scope.opts || null)); | |
} | |
} | |
}; | |
}]); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment