-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't render terminal linebreaks
Our markdown syntax does not support teminal line-breaks, either in blocks like a paragraph or just in text. We had correctly been suppressing rendering the slash-escaped line break when it appeared in a paragraph, but not in text
- Loading branch information
Showing
2 changed files
with
106 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
105 changes: 105 additions & 0 deletions
105
packages/@atjson/renderer-commonmark/test/line-break.test.ts
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,105 @@ | ||
import CommonmarkRenderer from "../src"; | ||
|
||
describe("terminal line breaks are removed", () => { | ||
test("in text", () => { | ||
const document = { | ||
text: "\ufffctest\ufffc", | ||
blocks: [ | ||
{ | ||
id: "B00000000", | ||
type: "text", | ||
parents: [], | ||
selfClosing: false, | ||
attributes: {}, | ||
}, | ||
{ | ||
id: "B00000000", | ||
type: "line-break", | ||
parents: ["text"], | ||
selfClosing: true, | ||
attributes: {}, | ||
}, | ||
], | ||
marks: [], | ||
}; | ||
|
||
expect(CommonmarkRenderer.render(document)).toBe("test"); | ||
}); | ||
|
||
test("in paragraph", () => { | ||
const document = { | ||
text: "\ufffctest\ufffc", | ||
blocks: [ | ||
{ | ||
id: "B00000000", | ||
type: "paragraph", | ||
parents: [], | ||
selfClosing: false, | ||
attributes: {}, | ||
}, | ||
{ | ||
id: "B00000000", | ||
type: "line-break", | ||
parents: ["paragraph"], | ||
selfClosing: true, | ||
attributes: {}, | ||
}, | ||
], | ||
marks: [], | ||
}; | ||
|
||
expect(CommonmarkRenderer.render(document)).toBe("test\n\n"); | ||
}); | ||
}); | ||
|
||
describe("are slash escaped", () => { | ||
test("in text", () => { | ||
const document = { | ||
text: "\ufffcline 1\ufffcline 2", | ||
blocks: [ | ||
{ | ||
id: "B00000000", | ||
type: "text", | ||
parents: [], | ||
selfClosing: false, | ||
attributes: {}, | ||
}, | ||
{ | ||
id: "B00000000", | ||
type: "line-break", | ||
parents: ["text"], | ||
selfClosing: true, | ||
attributes: {}, | ||
}, | ||
], | ||
marks: [], | ||
}; | ||
|
||
expect(CommonmarkRenderer.render(document)).toBe("line 1\\\nline 2"); | ||
}); | ||
|
||
test("in paragraph", () => { | ||
const document = { | ||
text: "\ufffcline 1\ufffcline 2", | ||
blocks: [ | ||
{ | ||
id: "B00000000", | ||
type: "paragraph", | ||
parents: [], | ||
selfClosing: false, | ||
attributes: {}, | ||
}, | ||
{ | ||
id: "B00000000", | ||
type: "line-break", | ||
parents: ["paragraph"], | ||
selfClosing: true, | ||
attributes: {}, | ||
}, | ||
], | ||
marks: [], | ||
}; | ||
|
||
expect(CommonmarkRenderer.render(document)).toBe("line 1\\\nline 2\n\n"); | ||
}); | ||
}); |