Skip to content

Commit c44ec69

Browse files
committed
add html code for asterisk
1 parent f34400f commit c44ec69

5 files changed

Lines changed: 15 additions & 12 deletions

File tree

index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ var Beep = {
2222
banned_urls: null,
2323
illegal_words: null,
2424

25-
parseContent: function (content) {
25+
parseContent: function (content, is_topic=false) {
2626
var nil = '^(?!x)x';
27-
return parseContent(content, Beep.banned_words || nil, Beep.banned_urls || nil, Beep.censorWholeWord);
27+
return parseContent(content, Beep.banned_words || nil, Beep.banned_urls || nil, Beep.censorWholeWord, is_topic);
2828
},
2929
toRegExp: toRegExp,
3030
loadList: function (callback) {
@@ -131,9 +131,10 @@ var Beep = {
131131
callback(null, data);
132132
},
133133
parseTopic: function (data, callback) {
134-
data.topic.title = Beep.parseContent(data.topic.title);
135-
data.topic.slug = Beep.parseContent(data.topic.slug);
136-
data.topic.titleRaw = Beep.parseContent(data.topic.titleRaw);
134+
var is_topic=true
135+
data.topic.title = Beep.parseContent(data.topic.title, is_topic);
136+
data.topic.slug = Beep.parseContent(data.topic.slug, is_topic);
137+
data.topic.titleRaw = Beep.parseContent(data.topic.titleRaw, is_topic);
137138

138139
callback(null, data);
139140
},
@@ -165,4 +166,4 @@ var Beep = {
165166
}
166167
};
167168

168-
module.exports = Beep;
169+
module.exports = Beep;

lib/parseContent.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
var isLatin = /^\w+$/;
44

5-
function parseContent(content, banned_words, banned_urls, censorWholeWord) {
5+
function parseContent(content, banned_words, banned_urls, censorWholeWord, is_topic) {
66
if (!content) {
77
return content;
88
}
9+
// from http://htmlarrows.com/symbols/
10+
var sym = is_topic ? '*' : '⁎';
911

1012
function censor(match) {
1113
if (!isLatin.test(match)) {
@@ -17,7 +19,7 @@ function parseContent(content, banned_words, banned_urls, censorWholeWord) {
1719

1820
var i = l - 2;
1921
while (i) {
20-
out += '* ';
22+
out += sym;
2123
i--;
2224
}
2325

@@ -30,4 +32,4 @@ function parseContent(content, banned_words, banned_urls, censorWholeWord) {
3032
.replace(banned_urls, '[link removed]');
3133
}
3234

33-
module.exports = parseContent;
35+
module.exports = parseContent;

lib/toRegExp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ function toRegExp(arr, fullWord) {
3838
return new RegExp(str || '^(?!x)x', 'ig');
3939
}
4040

41-
module.exports = toRegExp;
41+
module.exports = toRegExp;

tests/parseContent.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ assert.strictEqual(parseContent(
3838
false
3939
), '載点代示早面通[censored]就焼初哲[censored]質');
4040

41-
console.log('parseContent passed');
41+
console.log('parseContent passed');

tests/toRegExp.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ assert.equal(toRegExp('bad,words, here'), '/bad|words|here/gi');
99
assert.equal(toRegExp('今,野', true), '/今|野/gi');
1010
assert.equal(toRegExp(null), '/^(?!x)x/gi');
1111

12-
console.log('toRegExp passed');
12+
console.log('toRegExp passed');

0 commit comments

Comments
 (0)