Skip to content

Instantly share code, notes, and snippets.

@Hypercubed
Created December 18, 2013 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hypercubed/8019475 to your computer and use it in GitHub Desktop.
Save Hypercubed/8019475 to your computer and use it in GitHub Desktop.
/*
* 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