Skip to content

Commit ecda0fe

Browse files
Mutugiiidogi
andauthored
teams: smoother voices markdown whitespacing (fixes #9135) (#9176)
Co-authored-by: dogi <[email protected]>
1 parent d16f589 commit ecda0fe

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "planet",
33
"license": "AGPL-3.0",
4-
"version": "0.20.40",
4+
"version": "0.20.41",
55
"myplanet": {
66
"latest": "v0.33.52",
77
"min": "v0.32.52"

src/app/shared/planet-markdown.component.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export class PlanetMarkdownComponent implements OnChanges {
3939
`${environment.parentProtocol}://${this.stateService.configuration.parentDomain}/` :
4040
`${environment.couchAddress}/`;
4141

42+
this.content = this.normalizeWhitespace(this.content || '');
43+
4244
this.images = this.extractImageUrls(this.content);
4345
const textOnly = this.content.replace(this.imageMarkdownRegex, '');
4446

@@ -52,6 +54,15 @@ export class PlanetMarkdownComponent implements OnChanges {
5254
}
5355
}
5456

57+
normalizeWhitespace(content: string): string {
58+
// Replace excessive consecutive whitespace (tabs, newlines, spaces) with reasonable limits
59+
// Replace sequences of tabs/spaces with max 2 spaces
60+
content = content.replace(/[ \t]+/g, (match) => match.length > 2 ? ' ' : match);
61+
// Replace excessive newlines (more than 2 consecutive) with just 2 newlines
62+
content = content.replace(/\n{3,}/g, '\n\n');
63+
return content.trim();
64+
}
65+
5566
extractImageUrls(content: string): string[] {
5667
const matches: string[] = [];
5768
let match: RegExpExecArray | null;

0 commit comments

Comments
 (0)