Permalink
Browse files

Add simple text formatting for ticket/project description

Just first simple implementation with support for:

* new lines
* bold

Closes #2
  • Loading branch information...
1 parent 7644338 commit 73c1169eeae483a262fba04e315470fd3337160c @alenkacz alenkacz committed with Jul 22, 2011
Showing with 39 additions and 2 deletions.
  1. +13 −0 app/js/filters.js
  2. +1 −1 app/partials/projects.html
  3. +1 −1 app/partials/tickets.html
  4. 0 httpd-vhosts.conf
  5. +24 −0 test/unit/filtersSpec.js
View
@@ -31,3 +31,16 @@ angular.filter('userInfo', function(user) {
return '';
});
+
+/**
+ * Simple text formatter
+ * Supporting this syntax:
+ * - * something bold * -> <b>something bold</b>
+ * - first \n second line -> first <br /> second line
+ *
+ * @param {string} text Text that should be formatted
+ * @returns {string} text Formatted string
+ */
+angular.filter('textFormat', function(text) {
+ return text.replace(/\n/mg, '<br />').replace(/\*([^\*]*)\*/g, '<b>\$1</b>');
+});
@@ -13,7 +13,7 @@
<ul class="project list">
<li ng:repeat="project in projects.items">
<h3>{{project.name}}</h3>
- <p>{{project.description}}</p>
+ <p>{{project.description | textFormat | html}}</p>
<a href ng:click="projects.destroy(project)" class="right">delete</a>
<div class="wrapper"></div>
</li>
@@ -14,7 +14,7 @@
<span class="ticket-state" ng:class="ticket.state.toLowerCase()">{{ticket.state}}</span>
<span class="ticket-number">#{{ticket.number}}</span> by <span class="ticket-author">{{ticket.Author|userInfo}}</span> at <span class="ticket-created">{{ticket.created | gmtdate: 'd.M.yyyy HH:mm:ss'}}</span><br />
- <p class="ticket-description">{{ticket.description}}</p>
+ <p class="ticket-description">{{ticket.description | textFormat | html}}</p>
<!-- revisions -->
<div ng:show="revLoaded">
View
No changes.
@@ -31,3 +31,27 @@ describe('userInfo', function() {
expect(userInfo(null)).toEqual('');
});
});
+
+describe('textFormat', function() {
+ var textFormat = angular.filter.textFormat;
+
+ it('should rewrite text with multiple bolds', function() {
+ expect(textFormat('a *b* c *d e*')).toEqual('a <b>b</b> c <b>d e</b>');
+ });
+
+ it('should rewrite text with one bold', function() {
+ expect(textFormat('*text*')).toEqual('<b>text</b>');
+ });
+
+ it('should rewrite text with single newline', function() {
+ expect(textFormat('text \n newline')).toEqual('text <br /> newline');
+ });
+
+ it('should rewrite text with two newlines', function() {
+ expect(textFormat('a \n b \n c')).toEqual('a <br /> b <br /> c');
+ });
+
+ it('should rewrite combination of newline and bold text', function() {
+ expect(textFormat('*bold* \n newline')).toEqual('<b>bold</b> <br /> newline');
+ });
+});

0 comments on commit 73c1169

Please sign in to comment.