AngularJS Markdown using marked.
npm install angular-markedbower install angular-marked
npm install angular-marked
jspm install angular-marked=npm:angular-marked
html
`
Usage
`js
var app = angular.module('example-app', ['hc.marked']);
`
$3
`js
app.config(['markedProvider', function (markedProvider) {
markedProvider.setOptions({gfm: true});
}]);
`
Example using highlight.js Javascript syntax highlighter (must include highlight.js script).
`js
app.config(['markedProvider', function (markedProvider) {
markedProvider.setOptions({
gfm: true,
tables: true,
highlight: function (code, lang) {
if (lang) {
return hljs.highlight(lang, code, true).value;
} else {
return hljs.highlightAuto(code).value;
}
}
});
}]);
`
$3
Example overriding the way custom markdown links are displayed to open in new windows:
`js
app.config(['markedProvider', function (markedProvider) {
markedProvider.setRenderer({
link: function(href, title, text) {
return "" + text + "";
}
});
}]);
`
$3
`html
# Markdown directive
It works!
`
Bind the markdown input to a scope variable:
`html
`
Include a markdown file:
`html
`
Or a template (great for md that includes code blocks):
`html
`
Use `compile` attribute to support AngularJS directives inside markdown.
`html
`
`javascript
.controller('ClickHandler', function() {
this.doClick = function() {
...
};
})
`
$3
`js
app.controller('myCtrl', ['marked', function (marked) {
$scope.html = marked('#TEST');
}]);
`
Testing
Install npm and bower dependencies:
`sh
npm install
bower install
npm test
`
Why?
I 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.