Parse JSON data in Markdown format

markdown http://baike.baidu.com/link?url=A_TMdRrgzrZkjnleWuS9zgi1yahFct3tcVee2UusJme9Ye9p-djw8t7DKnS2EtD9vIyjeDLc61V5jQKL7ezmZ586JvADtnaloq2u7gMjO9u
is a simple markup syntax through which it can make normal text content have a certain



angular.module('App', []).directive('markdown',
      //declare the command and name it markdown
    function(){
      //Create showdown converter
      var converter = new Showdown.converter();
      //The command will return an object to declare the settings of the command
      return{
      //declare the custom action to wait for the value to be assigned to the markdown property
         scope:{markdown: '@'},
       //Declare the link function, its role is 'Convent Markdown To HTML!'
         link:function(scope,element,attrs){
        //The following will use the scope observation period to synchronize model changes
            scope.$watch('markdown',function(){
              var content = converter.makeHtml(attrs.markdown);//Convert markdown to html and assign content variable
              element.html(content); //Here is to inject the converted result into the element
            })
         }
      }
    }
);





Then you can use it in the corresponding position that needs to be converted!

<div markdown="{{content.content}}"></div>



Note that your data format must be markdown! otherwise invalid

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326346525&siteId=291194637