Home

Awesome

angular-markdown-filter

Markdown filter for Angular

Installation

# As a bower component:
$ bower install angular-markdown-filter

# As an npm package:
$ npm install angular-markdown-filter

It's recomended to also use ngSanitize if you plan to bind the output using ngBindHtml to pervent XSS.

$ bower install angular-sanitize

Import dependencies

<script src="bower_components/showdown/dist/showdown.min.js"></script>
<script src="bower_components/angular-markdown-filter/markdown.js"></script>
<!-- Optional: -->
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
angular.module('myApp', [
  'ngSanitize', // Optional
  'markdown'
]);

Configuration

The underlying Showdown converter can be configured through the markdown provider

angular.module('markdown')
  .config(function(markdownProvider) {
    markdownProvider.config({
      extensions: ['table']
    });
  });

see the Showdown documentation for details on how to create extensions.

Usage

angular.module('myApp')
  // Optional Config
  .config(function ($compileProvider) {
    // Add optional support for custom schema links: "herp://" and "derp://"
    $compileProvider.aHrefSanitizationWhitelist(/^\s*(herp|derp):/);
  })
  .controller('MainCtrl', function ($scope) {
    $scope.text = '# Heading 1\n- [Link](http://example.com)\n- [Custom Link 1](herp://is.this.working?)\n- [Custom Link 2](derp://is.this.working?)';
  });
<div class="container" ng-bind-html="text | markdown"></div>