module.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. group : "default",
  14. mode : "markdown",
  15. content : "",
  16. style: {},
  17. }
  18. _.defaults($scope.panel,_d);
  19. $scope.init = function() {
  20. $scope.ready = false;
  21. }
  22. }).directive('markdown', function() {
  23. return {
  24. restrict: 'E',
  25. link: function(scope, element, attrs) {
  26. scope.$on('render', function() {
  27. render_panel();
  28. })
  29. function render_panel() {
  30. var scripts = $LAB.script("panels/text/lib/showdown.js")
  31. scripts.wait(function(){
  32. scope.ready = true;
  33. var converter = new Showdown.converter();
  34. var text = scope.panel.content.replace(/&/g, '&')
  35. .replace(/>/g, '>')
  36. .replace(/</g, '&lt;');
  37. var htmlText = converter.makeHtml(text);
  38. element.html(htmlText);
  39. // For whatever reason, this fixes chrome. I don't like it, I think
  40. // it makes things slow?
  41. scope.$apply()
  42. });
  43. }
  44. render_panel();
  45. }
  46. }
  47. })
  48. .filter('newlines', function(){
  49. return function (input) {
  50. return input.replace(/\n/g, '<br/>');
  51. }
  52. })
  53. .filter('striphtml', function () {
  54. return function(text) {
  55. return text
  56. .replace(/&/g, '&amp;')
  57. .replace(/>/g, '&gt;')
  58. .replace(/</g, '&lt;');
  59. }
  60. });