Skip to content

Instantly share code, notes, and snippets.

@Hypercubed

Hypercubed/marked.js

Created Dec 18, 2013
Embed
What would you like to do?
/*
* 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
You can’t perform that action at this time.