===
AngularJS Markdown using marked.
Please note: neither this directive nor marked (by default) implementation sanitization. As always, sanitizing is necessary for user-generated content.
bower install angular-markedorbower install Hypercubed/angular-marked- Include the
marked.jsscript into your app. By default should be atbower_components/marked/lib/marked.js. - Include the
angular-marked.jsinto your app. By default should be atbower_components/angular-marked/angular-marked.js. - Add
hc.markedas a module dependency to your app.
app.config(['markedProvider',function(markedProvider){markedProvider.setOptions({gfm: true});}]);Example using highlight.js Javascript syntax highlighter (must include highlight.js script).
markedProvider.setOptions({gfm: true,tables: true,highlight: function(code){returnhljs.highlightAuto(code).value;}});Example overriding the way custom markdown links are displayed to open in new windows:
app.config(['markedProvider',function(markedProvider){markedProvider.setRenderer({link: function(href,title,text){return"<a href='"+href+"' title='"+title+"' target='_blank'>"+text+"</a>";}});}]);<marked>
#Markdown directive
*It works!* </marked>Bind the markdown input to a scope variable:
<divmarked="my_markdown"></div><!-- Uses $scope.my_markdown -->Include a markdown file:
<divmarkedng-include="'README.md'"></div><!-- Uses markdown content from README.md -->app.controller('myCtrl',['marked',function(marked){$scope.html=marked('#TEST');}]);Install npm and bower dependencies:
npm install
bower install
npm testI wanted to use marked instead of showdown as used in angular-markdown-directive as well as expose the option to globally set defaults. Yes, it is probably best to avoid creating a bunch of angular wrapper modules... but I use this enough across multiple projects to make it worth while for me. Use it if you like. Pull requests are welcome.
Based on angular-markdown-directive by briantford which, in turn, is based on this excellent tutorial by @johnlinquist.
