Google pagedown AngularJS directive

后端 未结 4 1643
清歌不尽
清歌不尽 2020-12-23 17:50

See bottom of question for an improved solution to this problem

I have been trying for some time now to get a directive for the pagedown

4条回答
  •  被撕碎了的回忆
    2020-12-23 17:52

    It might not be the answer, but all the problem occurs when you start using Markdown.Editor which does not gives you a lot of benefits.

    Of course, you need to use it for markdown editor beginners, but when use markdown, they are already not beginners anyway(I might be wrong).

    What I approached to this problem was to make fully working version of this without using editor.

    It has preview also.

    It's also very simple.

    https://github.com/allenhwkim/wiki

    ---- edit ----
    removed
    ---- edit ----
    removed
    ---- edit ----

    To provide a fully working editor, after few hours of trial and asking questions, the following is the simplest I can get. This does require any $watch nor $formatters. It just wraps the given element with all attributes given by the textarea.

    http://plnkr.co/edit/jeZ5EdLwOfwo6HzcTAOR?p=preview

    app.directive('pagedownEditor', function($compile, $timeout) {
      var num=0;
      return {
        priority: 1001, //higher than ng-repeat, 1000
        link: function(scope, el, attrs) {
          var uniqNum = scope.$index || num++;
          var wmdPanel = document.createElement('div');
          wmdPanel.className = "wmd-panel";
          var wmdButtonBar = document.createElement('div');
          wmdButtonBar.id = 'wmd-button-bar-'+uniqNum;
          wmdPanel.appendChild(wmdButtonBar);
          el.wrap(wmdPanel); // el is ng-repeat comment, it takes tim
    
          var converter = Markdown.getSanitizingConverter();
          var editor = new Markdown.Editor(converter, "-"+uniqNum);
          $timeout(function() {
            wmdPanel.querySelector('textarea').id = 'wmd-input-'+uniqNum;
            wmdPanel.querySelector('textarea').className += ' wmd-input';
            wmdPanel.insertAdjacentHTML('afterend', '
    '); editor.run() }, 50); } };

提交回复
热议问题