Add markdown support for comments and repo descriptions

This commit is contained in:
Joseph Schorr 2013-09-30 19:08:24 -04:00
parent e4653cd7cf
commit 461f324e09
12 changed files with 3816 additions and 14 deletions

View file

@ -1,3 +1,40 @@
function getFirstTextLine(commentString) {
if (!commentString) { return; }
var lines = commentString.split('\n');
var MARKDOWN_CHARS = {
'#': true,
'-': true,
'>': true,
'`': true
};
for (var i = 0; i < lines.length; ++i) {
// Skip code lines.
if (lines[i].indexOf(' ') == 0) {
continue;
}
// Skip empty lines.
if ($.trim(lines[i]).length == 0) {
continue;
}
// Skip control lines.
if (MARKDOWN_CHARS[$.trim(lines[i])[0]]) {
continue;
}
return getMarkedDown(lines[i]);
}
return '';
}
function getMarkedDown(string) {
return Markdown.getSanitizingConverter().makeHtml(string || '');
}
function HeaderCtrl($scope, UserService) {
$scope.$watch( function () { return UserService.currentUser(); }, function (currentUser) {
$scope.user = currentUser;
@ -25,7 +62,7 @@ function HeaderCtrl($scope, UserService) {
template += '<i class="icon-hdd icon-large"></i>'
template += '<span class="name">' + datum.repo.namespace +'/' + datum.repo.name + '</span>'
if (datum.repo.description) {
template += '<span class="description">' + datum.repo.description + '</span>'
template += '<span class="description">' + getFirstTextLine(datum.repo.description) + '</span>'
}
template += '</div>'
@ -45,6 +82,15 @@ function RepoListCtrl($scope, Restangular) {
repositoryFetch.getList().then(function(resp) {
$scope.repositories = resp.repositories;
});
$scope.getCommentFirstLine = function(commentString) {
return getMarkedDown(getFirstTextLine(commentString));
};
$scope.getMarkedDown = function(string) {
if (!string) { return ''; }
return getMarkedDown(string);
};
}
function LandingCtrl($scope) {
@ -72,19 +118,36 @@ function RepoCtrl($scope, Restangular, $routeParams, $rootScope) {
$scope.editDescription = function() {
if (!$scope.repo.can_write) { return; }
$('#descriptionEdit')[0].value = $scope.repo.description || '';
if (!$scope.markdownDescriptionEditor) {
var converter = Markdown.getSanitizingConverter();
var editor = new Markdown.Editor(converter, '-description');
editor.run();
$scope.markdownDescriptionEditor = editor;
}
$('#wmd-input-description')[0].value = $scope.repo.description;
$('#editModal').modal({});
};
$scope.saveDescription = function() {
$('#editModal').modal('hide');
$scope.repo.description = $('#descriptionEdit')[0].value;
$scope.repo.description = $('#wmd-input-description')[0].value;
$scope.repo.put();
};
$scope.parseDate = function(dateString) {
return Date.parse(dateString);
};
$scope.getCommentFirstLine = function(commentString) {
return getMarkedDown(getFirstTextLine(commentString));
};
$scope.getMarkedDown = function(string) {
if (!string) { return ''; }
return getMarkedDown(string);
};
$scope.listImages = function() {
if ($scope.imageHistory) { return; }