var markdown = angular.module('markdown', []);

markdown.controller('indexCtrl', ['$scope', function($scope) {
  $scope.http = {
    url: '/md/text?_=' + new Date().getTime()
  };
}]);

markdown.directive('render', ['$http', function($http) {
  return {
    restrict: 'E',
    scope: {
      src: '='
    },
    template: '<article class="markdown-body"></article>',
    replace: true,
    link: function(scope, element, attrs) {
      $http({
        method: 'GET',
        url: scope.src
      }).then(function success(response) {
        element.html(response.data.html);
        var codes = element.find('code[class*="language-"]');
        codes.each(function() {
          if (angular.element(this).hasClass('language-html')) {
            var test = angular.element('<a href="/example/asset/show.html?html=' //
                    + encodeURIComponent(this.innerHTML) //
                    + '" target="_blank">测试一下</a>');
            angular.element(this).parent().after(test);
          }
          Prism.highlightElement(this, true);// Prism framework to highlight element.
        });
        angular.element('h2, h3, h4') //
          .css({'cursor': 'pointer'}) //
          .on('click', function() {
          var elem = angular.element(this);
          var tagName = this.tagName.toUpperCase();
          var hn = tagName.replace(/^H/, '');
          var all = elem.nextAll();
          var length = all.length;
          for (var i = 0; i < length; i++) {
            var nelem = all.get(i);
            var ntag = nelem.tagName.toUpperCase();
            var toggle = true;
            if (/H\d+/.test(ntag)) {
              for (var n = parseInt(hn); n >= 1; n--) {
                if (ntag == ('H' + n)) {
                  toggle = false;
                  break;
                }
              }
              if (!toggle) {
                break;
              }
            }
            $(nelem).toggle();
          }
        });
      }, function error(response) {
        console.log('请求失败');
      });
    }
  };
}]);
@@ -1147,16 +1147,20 @@
 lement('
+h1, 
 h2, h3, 
@@ -1205,31 +1205,16 @@
 inter'%7D)
- //%0D%0A          
 .on('cli
@@ -1322,32 +1322,145 @@
 toUpperCase();%0D%0A
+          if (tagName == 'H1') %7B%0D%0A            elem.nextAll().show();%0D%0A            return;%0D%0A          %7D else %7B%0D%0A  
           var hn
@@ -1496,24 +1496,26 @@
 %0D%0A          
+  
 var all = el
@@ -1535,24 +1535,26 @@
 %0D%0A          
+  
 var length =
@@ -1569,32 +1569,34 @@
 gth;%0D%0A          
+ 
+ 
 for (var i = 0; 
@@ -1623,24 +1623,26 @@
             
+  
 var nelem = 
@@ -1650,24 +1650,26 @@
 ll.get(i);%0D%0A
+  
             
@@ -1717,24 +1717,26 @@
             
+  
 var toggle =
@@ -1739,24 +1739,26 @@
 le = true;%0D%0A
+  
             
@@ -1779,24 +1779,26 @@
 t(ntag)) %7B%0D%0A
+  
             
@@ -1854,24 +1854,26 @@
             
+  
 if (ntag == 
@@ -1904,16 +1904,18 @@
         
+  
 toggle =
@@ -1933,32 +1933,34 @@
                 
+ 
+ 
 break;%0D%0A        
@@ -1959,35 +1959,39 @@
                 
+  
 %7D%0D%0A
+  
               %7D%0D
@@ -2001,24 +2001,26 @@
             
+  
 if (!toggle)
@@ -2031,32 +2031,34 @@
                 
+  
 break;%0D%0A        
@@ -2055,35 +2055,39 @@
 %0D%0A              
+ 
+ 
 %7D%0D%0A
+  
             %7D%0D%0A 
@@ -2077,32 +2077,34 @@
              %7D%0D%0A
+  
             $(ne
@@ -2115,24 +2115,39 @@
 .toggle();%0D%0A
+            %7D%0D%0A
           %7D%0D

Add H1 click.