module.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*jshint globalstrict:true */
  2. /*global angular:true */
  3. /*global Showdown:false */
  4. /*
  5. ## Text
  6. ### Parameters
  7. * mode :: 'text', 'html', 'markdown'
  8. * content :: Content of the panel
  9. * style :: Hash containing css properties
  10. */
  11. 'use strict';
  12. angular.module('kibana.text', [])
  13. .controller('text', function($scope, $rootScope) {
  14. $scope.panelMeta = {
  15. status : "Stable",
  16. description : "A static text panel that can use plain text, markdown, or (sanitized) HTML"
  17. };
  18. // Set and populate defaults
  19. var _d = {
  20. status : "Stable",
  21. mode : "markdown",
  22. content : "",
  23. style: {},
  24. };
  25. _.defaults($scope.panel,_d);
  26. $scope.init = function() {
  27. $scope.ready = false;
  28. };
  29. }).directive('markdown', function() {
  30. return {
  31. restrict: 'E',
  32. link: function(scope, element, attrs) {
  33. scope.$on('render', function() {
  34. render_panel();
  35. });
  36. function render_panel() {
  37. var scripts = $LAB.script("panels/text/lib/showdown.js");
  38. scripts.wait(function(){
  39. scope.ready = true;
  40. var converter = new Showdown.converter();
  41. var text = scope.panel.content.replace(/&/g, '&')
  42. .replace(/>/g, '>')
  43. .replace(/</g, '&lt;');
  44. var htmlText = converter.makeHtml(text);
  45. element.html(htmlText);
  46. // For whatever reason, this fixes chrome. I don't like it, I think
  47. // it makes things slow?
  48. if(!scope.$$phase) {
  49. scope.$apply();
  50. }
  51. });
  52. }
  53. render_panel();
  54. }
  55. };
  56. })
  57. .filter('newlines', function(){
  58. return function (input) {
  59. return input.replace(/\n/g, '<br/>');
  60. };
  61. })
  62. .filter('striphtml', function () {
  63. return function(text) {
  64. return text
  65. .replace(/&/g, '&amp;')
  66. .replace(/>/g, '&gt;')
  67. .replace(/</g, '&lt;');
  68. };
  69. });