1

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)
      });
    

    Result

  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>
    

    result


怀疑真爱的流浪者jason
923 声望62 粉丝

For every single second in life, I want to fight with the monster deep within my heart , and I want to win.........


引用和评论

0 条评论