-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
53 lines (44 loc) · 1.14 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// var ghm = require("ghm");
var marked = require('marked');
exports.restrict = function(req, res, next){
if(req.isAuthenticated()) next();
else res.redirect('/');
};
// exports.md = function(source, options) {
// return ghm.parse(source);
// }
exports.md = function(source, options) {
options = options || {};
options.sanitize = options.sanitize || true;
// github like mardown for tabs and newlines
source = source
// \r\n and \r -> \n
.replace(/\r\n?/g, '\n')
// 2 newline to paragraph
.replace(/\n\n+/, "\n\n")
// 1 newline to br
.replace(/([^\n]\n)(?=[^\n])/g, function(m) {
return /\n{2}/.test(m) ? m : m.replace(/\s+$/,"") + " \n";
})
// tabs to four spaces
.replace(/\t/g, ' ');
return marked(source, options);
};
exports.actions = {
vote: {
template: 'Voto en %voteTitle%.',
params: ['voteTitle']
},
comment: {
template: 'Opino en la votacion sobre %ideaTitle%.',
params: ['ideaTitle']
},
proxy: {
template: 'Delego su voto en %hashTitle% a %citizenName%.',
params: ['hashTitle', 'citizenName']
},
profileEdit: {
template: 'Editó su perfil.',
params: []
}
}