Pārlūkot izejas kodu

Merge branch 'master' of github.com:Akeru/grafana into Akeru-master

Torkel Ödegaard 11 gadi atpakaļ
vecāks
revīzija
2ac7b9dabf
2 mainītis faili ar 27 papildinājumiem un 6 dzēšanām
  1. 3 4
      src/app/panels/text/module.html
  2. 24 2
      src/app/panels/text/module.js

+ 3 - 4
src/app/panels/text/module.html

@@ -1,10 +1,9 @@
 <div ng-controller='text' ng-init="init()" style="min-height:{{panel.height || row.height}}" ng-dblclick="openEditor()">
   <!--<p ng-style="panel.style" ng-bind-html-unsafe="panel.content | striphtml | newlines"></p>-->
-  <markdown ng-show="ready && panel.mode == 'markdown'">
-    {{panel.content}}
+  <markdown ng-show="ready && panel.mode == 'markdown'" ng-bind-html-unsafe="panel.content | applymarkdown | applytemplate">
   </markdown>
-  <p ng-show="panel.mode == 'text'" ng-style='panel.style' ng-bind-html-unsafe="panel.content | striphtml | newlines">
+  <p ng-show="panel.mode == 'text'" ng-style='panel.style' ng-bind-html-unsafe="panel.content | striphtml | newlines | applytemplate">
   </p>
-  <p ng-show="panel.mode == 'html'" ng-bind-html-unsafe="panel.content">
+  <p ng-show="panel.mode == 'html'" ng-bind-html-unsafe="panel.content | applytemplate">
   </p>
 </div>

+ 24 - 2
src/app/panels/text/module.js

@@ -14,7 +14,8 @@ define([
   'angular',
   'app',
   'underscore',
-  'require'
+  'require',
+  'services/filterSrv'
 ],
 function (angular, app, _, require) {
   'use strict';
@@ -98,4 +99,25 @@ function (angular, app, _, require) {
         .replace(/</g, '&lt;');
     };
   });
-});
+
+  module.filter('applytemplate', function(filterSrv) {
+    return function (input) {
+      return filterSrv.applyTemplateToTarget(input);
+    };
+  });
+
+  module.filter('applymarkdown', function() {
+    return function (input) {
+      if(require.defined('./lib/showdown')) {
+        var Showdown = require('./lib/showdown');
+        var converter = new Showdown.converter();
+        var text = input.replace(/&/g, '&amp;')
+           .replace(/>/g, '&gt;')
+           .replace(/</g, '&lt;');
+        return converter.makeHtml(text);
+      } else {
+        return input;
+      }
+    };
+  });
+});