Angular markdown filter/service

Address

https://github.com/bornkiller/angularMarkdown
scripts/markdown.js

Attention

  1. 所有的代码都基于https://code.google.com/p/pagedown/,只是用angular的方式封装,避免手动加载Markdown.Sanitizer.jsMarkdown.Converter.js造成的额外成本和全局变量污染。

  2. 因为个人原因,并未严格遵循Angualr封装规范,故提供了 filter/service两种使用方案。

  3. 实际应用简单的Demo(service方案)。

    angular.module('administratorApp')
      .controller('PublishCtrl', function ($scope,$log,markdown) {
         $scope.markdownContent = '####使用markdown语法####';
         $scope.preview = null;
         $scope.$watch("markdownContent",function(newVal,oldVal){
           try{
             $scope.preview = markdown.makeHtml($scope.markdownContent);
           }catch(e){
              $log.warn(e.name);
           }
         },true)
      });
    

    《Angular markdown filter/service》

  4. 实际使用Demo(filter方案)

    <div class="col-md-6 col-lg-6">
         <textarea  rows="19" ng-model="markdownContent"></textarea>
    </div>
    
    <div class="col-md-6 col-lg-6">
        <span class="label label-info">Preview</span>
        <section ng-bind="markdownContent | markdown"></section>
        <section ng-bind-html="markdownContent | markdown"></section>
    </div>
    

    《Angular markdown filter/service》

    原文作者:怀疑真爱的流浪者jason
    原文地址: https://segmentfault.com/a/1190000000404189
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞