Skip to content

Commit 4bc94c1

Browse files
authored
Compress 3 spaces down to 2 (#444)
1 parent 2569d6c commit 4bc94c1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/helpers/string.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,12 @@ export const compressLineBreaks = (s: string) => {
2525
}
2626
return s;
2727
};
28+
29+
const TOO_MANY_SPACES = / {3}/g;
30+
const APPROPRIATE_SPACES = " ";
31+
export const compressSpaces = (s: string) => {
32+
while (TOO_MANY_SPACES.test(s)) {
33+
s = s.replaceAll(TOO_MANY_SPACES, APPROPRIATE_SPACES);
34+
}
35+
return s;
36+
};

src/server.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
StoredMessage,
99
getJobPosts,
1010
} from "./features/jobs-moderation/job-mod-helpers.js";
11-
import { compressLineBreaks, simplifyString } from "./helpers/string.js";
11+
import {
12+
compressSpaces,
13+
compressLineBreaks,
14+
simplifyString,
15+
} from "./helpers/string.js";
1216
import { constructDiscordLink } from "./helpers/discord.js";
1317
import { reactibotApiKey } from "./helpers/env.js";
1418

@@ -275,7 +279,9 @@ const renderPost = (post: StoredMessage): RenderedPost => {
275279
tags: post.tags,
276280
type: post.type,
277281
createdAt: post.createdAt,
278-
description: renderMdToHtml(compressLineBreaks(post.description)),
282+
description: renderMdToHtml(
283+
compressLineBreaks(compressSpaces(post.description)),
284+
),
279285
messageLink: constructDiscordLink(post.message),
280286
reactions: post.message.reactions.cache.map((r) => [
281287
r.emoji.name ?? "☐",

0 commit comments

Comments
 (0)