Skip to content

Commit

Permalink
started writing my own formatdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
lmatteis committed May 23, 2012
1 parent ae8f8d6 commit 4180458
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions app.js
Expand Up @@ -75,6 +75,7 @@ ddoc.views.item = {

comment.points = util.getPoints(c.voted);
comment.score = util.findScore(comment.points, c.comment_id);
comment.text = util.formatdoc(comment.text);

comments.push(comment);
}
Expand Down
13 changes: 13 additions & 0 deletions common/util.js
Expand Up @@ -78,3 +78,16 @@ exports.timeDifference = function(current, previous) {
return Math.round(elapsed/msPerYear ) + ' years ago';
}
}

exports.formatdoc = function(content) {
var newlines = '[(\\r)?\\n]+';

// first remove the newlines from the beginning and end of the content
content = content.replace(new RegExp('^' + newlines, 'g'), '');
content = content.replace(new RegExp(newlines + '$', 'g'), '');

// then replace each newlines with the paragraphs
content = '<p>' + content.replace(new RegExp(newlines, 'g'), '</p><p>') + '</p>';

return content;
}
2 changes: 1 addition & 1 deletion templates/item.html
Expand Up @@ -58,7 +58,7 @@
<br>
<span class="comment">
<font color="#000000">
{{text}}
{{{text}}}
</font>
{{#username}}
<p><font size="1"><u><a class="commentreply" comment_id="{{comment_id}}" href="#">reply</a></u></font></p>
Expand Down
6 changes: 6 additions & 0 deletions templates/partials/head.html
Expand Up @@ -14,6 +14,12 @@
});
</script>

<style>
.comment p:first-child {
margin-top:0;
}
</style>

</head>

<body>
Expand Down

0 comments on commit 4180458

Please sign in to comment.