|
511 | 511 | scope: { |
512 | 512 | markdown: '=' |
513 | 513 | }, |
514 | | - controller: ['$scope', '$sanitize', '$window', '$element', function($scope, $sanitize, $window, $element) { |
515 | | - $scope.$watch('markdown', function (markdown) { |
516 | | - var allowUnsafeMarkdown = $scope.$parent.allowUnsafeMarkdown; |
| 514 | + controller: 'MarkdownController' |
| 515 | + }; |
| 516 | + }; |
517 | 517 |
|
518 | | - var markdownString = typeof markdown === 'string' ? markdown || '' : ''; |
519 | | - var html = $window.marked(markdownString, RAML.Settings.marked); |
| 518 | + RAML.Directives.markdownString = function () { |
| 519 | + return { |
| 520 | + restrict: 'A', |
| 521 | + scope: { |
| 522 | + markdownString: '@' |
| 523 | + }, |
| 524 | + controller: 'MarkdownStringController' |
| 525 | + }; |
| 526 | + }; |
520 | 527 |
|
521 | | - if (!allowUnsafeMarkdown) { |
522 | | - html = $sanitize(html); |
523 | | - } |
| 528 | + var watchMarkdown = function(expression, $scope, $window, $sanitize, $element) { |
| 529 | + $scope.$watch(expression, function (markdown) { |
| 530 | + var allowUnsafeMarkdown = $scope.$parent.allowUnsafeMarkdown; |
| 531 | + var markdownString = typeof markdown === 'string' ? markdown || '' : ''; |
| 532 | + var html = $window.marked(markdownString, RAML.Settings.marked); |
524 | 533 |
|
525 | | - $element.html(html); |
526 | | - }); |
527 | | - }] |
528 | | - }; |
| 534 | + if (!allowUnsafeMarkdown) { |
| 535 | + html = $sanitize(html); |
| 536 | + } |
| 537 | + |
| 538 | + $element.html(html); |
| 539 | + }); |
529 | 540 | }; |
530 | 541 |
|
| 542 | + function controller($scope, $sanitize, $window, $element) { |
| 543 | + watchMarkdown('markdown', $scope, $window, $sanitize, $element); |
| 544 | + } |
| 545 | + |
| 546 | + function stringController($scope, $sanitize, $window, $element) { |
| 547 | + watchMarkdown('markdownString', $scope, $window, $sanitize, $element); |
| 548 | + } |
| 549 | + |
531 | 550 | angular.module('RAML.Directives') |
532 | | - .directive('markdown', RAML.Directives.markdown); |
| 551 | + .controller('MarkdownController', controller) |
| 552 | + .controller('MarkdownStringController', stringController) |
| 553 | + .directive('markdown', RAML.Directives.markdown) |
| 554 | + .directive('markdownString', RAML.Directives.markdownString); |
533 | 555 | })(); |
534 | 556 |
|
535 | 557 | (function () { |
|
1780 | 1802 | element.append(resourceHeadingElement(resource, currentId)); |
1781 | 1803 | element.append(resourceTypeElement(resource)); |
1782 | 1804 | element.append(resourceHeadingFlagElement($scope, resource)); |
1783 | | - element.append(resourceLevelDescriptionElement(resource)); |
| 1805 | + element.append(resourceLevelDescriptionElement($scope, $compile, resource)); |
1784 | 1806 | element.append(methodListElement($scope, resource, currentId, showResource, resourceId)); |
1785 | 1807 | element.append(closeMethodButton($scope, resource, currentId, showResource, resourceId)); |
1786 | 1808 |
|
|
1804 | 1826 | return ''; |
1805 | 1827 | } |
1806 | 1828 |
|
1807 | | - function resourceLevelDescriptionElement(resource) { |
| 1829 | + function resourceLevelDescriptionElement($scope, $compile, resource) { |
1808 | 1830 | var element = angular.element('<span class="raml-console-resource-level-description raml-console-marked-content"></span>'); |
1809 | | - element.append(angular.element('<p>' + resource.description + '</p>')); |
| 1831 | + element.attr('markdown-string', resource.description); |
| 1832 | + |
| 1833 | + $compile(element)($scope); |
| 1834 | + |
1810 | 1835 | return element; |
1811 | 1836 | } |
1812 | 1837 |
|
|
0 commit comments