module.js 1.7 KB

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