module.js 1.6 KB

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