directives: add optional placeholder for markdown
This commit is contained in:
parent
d6af389f21
commit
498d0af6a4
3 changed files with 13 additions and 6 deletions
|
@ -32,7 +32,7 @@
|
|||
<i ng-class="repository.is_starred ? 'starred fa fa-star' : 'fa fa-star-o'" class="star-icon" ng-click="toggleStar({repository: repository})"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="description markdown-view" content="repository.description" first-line-only="true"></div>
|
||||
<div class="description markdown-view" content="repository.description" first-line-only="true" placeholder-needed="true"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -10,12 +10,14 @@ angular.module('quay').directive('markdownView', function () {
|
|||
restrict: 'C',
|
||||
scope: {
|
||||
'content': '=content',
|
||||
'firstLineOnly': '=firstLineOnly'
|
||||
'firstLineOnly': '=firstLineOnly',
|
||||
'placeholderNeeded': '=placeholderNeeded'
|
||||
},
|
||||
controller: function($scope, $element, $sce, UtilService) {
|
||||
$scope.getMarkedDown = function(content, firstLineOnly) {
|
||||
if (firstLineOnly) {
|
||||
return $sce.trustAsHtml(UtilService.getFirstMarkdownLineAsText(content));
|
||||
console.log($scope.placeholderNeeded);
|
||||
return $sce.trustAsHtml(UtilService.getFirstMarkdownLineAsText(content, $scope.placeholderNeeded));
|
||||
}
|
||||
return $sce.trustAsHtml(UtilService.getMarkedDown(content));
|
||||
};
|
||||
|
|
|
@ -10,11 +10,16 @@ angular.module('quay').factory('UtilService', ['$sanitize', function($sanitize)
|
|||
};
|
||||
|
||||
utilService.getMarkedDown = function(string) {
|
||||
return Markdown.getSanitizingConverter().makeHtml(string || '');
|
||||
return html = Markdown.getSanitizingConverter().makeHtml(string || '');
|
||||
};
|
||||
|
||||
utilService.getFirstMarkdownLineAsText = function(commentString) {
|
||||
if (!commentString) { return ''; }
|
||||
utilService.getFirstMarkdownLineAsText = function(commentString, placeholderNeeded) {
|
||||
if (!commentString) {
|
||||
if (placeholderNeeded) {
|
||||
return '<p style="visibility:hidden">placeholder</p>';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
var lines = commentString.split('\n');
|
||||
var MARKDOWN_CHARS = {
|
||||
|
|
Reference in a new issue