Skip to content

Commit

Permalink
Merge pull request #1099 from basecamp/jose/account-for-lone-carriage…
Browse files Browse the repository at this point in the history
…-return-newlines

Normalize lone CRs as new lines
  • Loading branch information
josefarias authored Oct 18, 2023
2 parents 5ebe789 + 1ef222c commit 5b179f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/test/system/pasting_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ testGroup("Pasting", { template: "editor_empty" }, () => {
expectDocument("a\nb\nc\n")
})

test("paste plain text with CR", async () => {
await pasteContent("text/plain", "a\rb\rc")
expectDocument("a\nb\nc\n")
})

test("paste html with CR", async () => {
await pasteContent("text/html", "<div>a<br></div>\r<div>b<br></div>\r<div>c<br></div>")
expectDocument("a\nb\nc\n")
})

test("paste unsafe html", async () => {
window.unsanitized = []
const pasteData = {
Expand Down
2 changes: 1 addition & 1 deletion src/trix/core/helpers/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UTF16String from "trix/core/utilities/utf16_string"
export const normalizeSpaces = (string) =>
string.replace(new RegExp(`${ZERO_WIDTH_SPACE}`, "g"), "").replace(new RegExp(`${NON_BREAKING_SPACE}`, "g"), " ")

export const normalizeNewlines = (string) => string.replace(/\r\n/g, "\n")
export const normalizeNewlines = (string) => string.replace(/\r\n?/g, "\n")

export const breakableWhitespacePattern = new RegExp(`[^\\S${NON_BREAKING_SPACE}]`)

Expand Down

0 comments on commit 5b179f6

Please sign in to comment.