mirror of
https://github.com/outline/outline.git
synced 2026-11-21 13:34:02 +03:00
- Serialize code fences longer than any backtick run in the content, so content lines cannot terminate the fence early on reparse - Reduce the fence info string and language attribute to a single safe token when parsing and serializing - Share the markdown parser and serializer through the editor test helper
83 lines
2.2 KiB
TypeScript
83 lines
2.2 KiB
TypeScript
import { parser, schema, serializer } from "../../test/editor";
|
||
|
||
const docWithHardBreak = schema.nodeFromJSON({
|
||
type: "doc",
|
||
content: [
|
||
{
|
||
type: "paragraph",
|
||
content: [
|
||
{ type: "text", text: "Line one" },
|
||
{ type: "br" },
|
||
{ type: "text", text: "Line two" },
|
||
],
|
||
},
|
||
],
|
||
});
|
||
|
||
it("parses two trailing spaces as a hard break", () => {
|
||
const ast = parser.parse("Line one \nLine two");
|
||
|
||
expect(ast?.toJSON()).toEqual(docWithHardBreak.toJSON());
|
||
});
|
||
|
||
it("parses a backslash line ending as a hard break", () => {
|
||
const ast = parser.parse("Line one\\\nLine two");
|
||
|
||
expect(ast?.toJSON()).toEqual(docWithHardBreak.toJSON());
|
||
});
|
||
|
||
it("serializes hard breaks as a CommonMark break when commonMark is set", () => {
|
||
// The commonMark option is used when copying to the clipboard and exporting
|
||
// documents – two trailing spaces are a standard Markdown hard break that
|
||
// renders in external viewers and parses back into a `br`, unlike a bare
|
||
// newline.
|
||
expect(serializer.serialize(docWithHardBreak, { commonMark: true })).toBe(
|
||
"Line one \nLine two"
|
||
);
|
||
});
|
||
|
||
it("round-trips hard breaks through the copy/export serializer", () => {
|
||
let node = docWithHardBreak;
|
||
|
||
for (let i = 0; i < 3; i++) {
|
||
const markdown = serializer.serialize(node, { commonMark: true });
|
||
node = parser.parse(markdown)!;
|
||
expect(node.toJSON()).toEqual(docWithHardBreak.toJSON());
|
||
}
|
||
});
|
||
|
||
it("serializes hard breaks inside tables as a literal break tag", () => {
|
||
const docWithTable = schema.nodeFromJSON({
|
||
type: "doc",
|
||
content: [
|
||
{
|
||
type: "table",
|
||
content: [
|
||
{
|
||
type: "tr",
|
||
content: [
|
||
{
|
||
type: "td",
|
||
content: [
|
||
{
|
||
type: "paragraph",
|
||
content: [
|
||
{ type: "text", text: "Line one" },
|
||
{ type: "br" },
|
||
{ type: "text", text: "Line two" },
|
||
],
|
||
},
|
||
],
|
||
},
|
||
],
|
||
},
|
||
],
|
||
},
|
||
],
|
||
});
|
||
|
||
expect(serializer.serialize(docWithTable, { commonMark: true })).toContain(
|
||
"Line one<br>Line two"
|
||
);
|
||
});
|