Skip to content

Commit

Permalink
fix: support windows style line endings (#5)
Browse files Browse the repository at this point in the history
* fix(pre-parse): support windows style crlf line endings

* test(pre-parse): add testing for new line format and crlf
  • Loading branch information
Nytelife26 committed Feb 21, 2021
1 parent edccaab commit 5c18a28
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import type { EmbedField } from "../types/index";

export function cleanBody(body: string): string {
return body
.replace(/\r/g, "")
.replace(/\n\n/g, "\n")
.replace(/- +([*a-zA-Z0-9])/g, "$1");
.replace(/(-|\*) +([*a-zA-Z0-9])/g, "$2");
}

export function parseBody(body: string): EmbedField[] {
Expand Down
9 changes: 7 additions & 2 deletions tests/lib/cleanBody.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ describe("cleanBody (PRE-PARSE)", () => {
});

test("GIVEN body SHOULD prune markdown list notation", () => {
const result = cleanBody("# Test heading\n\n- Test item 1\n- Test item 2");
expect(result).toBe("# Test heading\nTest item 1\nTest item 2");
const result = cleanBody("# Test heading\n\n- Test item 1\n- Test item 2\n* Test item 3");
expect(result).toBe("# Test heading\nTest item 1\nTest item 2\nTest item 3");
});

test("GIVEN windows-style line endings SHOULD prune", () => {
const result = cleanBody("# Test heading\n\nTest body\r\nTest body 2\r\n\r\nTest body 3");
expect(result).toBe("# Test heading\nTest body\nTest body 2\nTest body 3");
});

test("GIVEN fallback body SHOULD not change", () => {
Expand Down

0 comments on commit 5c18a28

Please sign in to comment.