-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Avoid truncating in the middle of markdown (#20)
- Loading branch information
1 parent
acec2b5
commit bc373f9
Showing
6 changed files
with
583 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = (messageText, maxLength) => { | ||
const delimiter = '\n' | ||
if (messageText.length > maxLength) { | ||
messageText = messageText.substring(0, maxLength).split(delimiter) | ||
// if no newlines, we don't remove anything, we keep the truncated message as is | ||
if (messageText.length > 1) { | ||
// remove all text after the last newline in the truncated message | ||
// this avoids truncating in the middle of markdown | ||
messageText.splice(-1, 1) | ||
} | ||
messageText = messageText.join(delimiter) + '*[...]*' | ||
} | ||
return messageText | ||
} |
Oops, something went wrong.