module.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. angular.module('kibana.text', [])
  2. .controller('text', function($scope, $rootScope) {
  3. // Set and populate defaults
  4. var _d = {
  5. group : "default",
  6. mode : "markdown",
  7. content : "",
  8. style: {},
  9. }
  10. _.defaults($scope.panel,_d);
  11. $scope.init = function() {
  12. $scope.ready = false;
  13. }
  14. }).directive('markdown', function() {
  15. return {
  16. restrict: 'E',
  17. link: function(scope, element, attrs) {
  18. scope.$on('render', function() {
  19. render_panel();
  20. })
  21. function render_panel() {
  22. var scripts = $LAB.script("panels/text/lib/showdown.js")
  23. scripts.wait(function(){
  24. scope.ready = true;
  25. var converter = new Showdown.converter();
  26. var text = scope.panel.content.replace(/&/g, '&')
  27. .replace(/>/g, '>')
  28. .replace(/</g, '&lt;');
  29. var htmlText = converter.makeHtml(text);
  30. element.html(htmlText);
  31. // For whatever reason, this fixes chrome. I don't like it, I think
  32. // it makes things slow?
  33. scope.$apply()
  34. });
  35. }
  36. render_panel();
  37. }
  38. }
  39. })
  40. .filter('newlines', function(){
  41. return function (input) {
  42. return input.replace(/\n/g, '<br/>');
  43. }
  44. })
  45. .filter('striphtml', function () {
  46. return function(text) {
  47. return text
  48. .replace(/&/g, '&amp;')
  49. .replace(/>/g, '&gt;')
  50. .replace(/</g, '&lt;');
  51. }
  52. });