From 7e64ee2b68741217c2cfc2ddce66eb841a3772ea Mon Sep 17 00:00:00 2001 From: a-rena Date: Thu, 27 Jun 2024 12:59:40 +0530 Subject: [PATCH 01/12] fix: handling empty nextline doc --- .../@atjson/renderer-commonmark/src/index.ts | 9 + .../test/commonmark.test.ts | 289 ++++++++++++++++++ 2 files changed, 298 insertions(+) diff --git a/packages/@atjson/renderer-commonmark/src/index.ts b/packages/@atjson/renderer-commonmark/src/index.ts index 2c0044e62..fdc64bf9a 100644 --- a/packages/@atjson/renderer-commonmark/src/index.ts +++ b/packages/@atjson/renderer-commonmark/src/index.ts @@ -474,6 +474,15 @@ export default class CommonmarkRenderer extends Renderer { return ""; } + if ( + context.parent == null && + context.next == null && + context.document.blocks[context.document.blocks.length - 1].type === + "line-break" + ) { + return ""; + } + // MD code and html blocks cannot contain line breaks // https://spec.commonmark.org/0.29/#example-637 if (context.parent?.type === "code" || context.parent?.type === "html") { diff --git a/packages/@atjson/renderer-commonmark/test/commonmark.test.ts b/packages/@atjson/renderer-commonmark/test/commonmark.test.ts index 654f26381..5f486f383 100644 --- a/packages/@atjson/renderer-commonmark/test/commonmark.test.ts +++ b/packages/@atjson/renderer-commonmark/test/commonmark.test.ts @@ -1806,6 +1806,295 @@ After all the lists expect(CommonmarkRenderer.render(document)).toEqual("a\\\n\\\nb"); }); + test("Document with text and empty line break on next line.", () => { + let document = new OffsetSource({ + content: + "<$root>TestingOne Another", + annotations: [ + { + id: "82cc4694-3e0c-4ab6-8a7c-50670479a341", + type: "-atjson-parse-token", + start: 0, + end: 7, + attributes: { + "-atjson-reason": "$root_open", + }, + }, + { + id: "9f5a3160-4ab2-4af8-a77d-f184801103e2", + type: "-offset-line-break", + start: 14, + end: 37, + attributes: {}, + }, + { + id: "dab9716f-568a-41c8-9114-0eea9dddb283", + type: "-atjson-parse-token", + start: 14, + end: 25, + attributes: { + "-atjson-reason": "linebreak_open", + }, + }, + { + id: "eedbf178-f53e-4e4a-9929-7a2c8684a8d7", + type: "-atjson-parse-token", + start: 25, + end: 37, + attributes: { + "-atjson-reason": "linebreak_close", + }, + }, + { + id: "3d18057f-3289-4aa3-b001-04cf79110d99", + type: "-offset-line-break", + start: 37, + end: 60, + attributes: {}, + }, + { + id: "658ccabb-46d0-492e-9552-7243b0cc4fc6", + type: "-atjson-parse-token", + start: 37, + end: 48, + attributes: { + "-atjson-reason": "linebreak_open", + }, + }, + { + id: "9eec6d33-be6f-4d09-a777-488194df8950", + type: "-atjson-parse-token", + start: 48, + end: 60, + attributes: { + "-atjson-reason": "linebreak_close", + }, + }, + { + id: "6f82c9a5-760f-41b9-956b-a269b769b399", + type: "-offset-line-break", + start: 71, + end: 94, + attributes: {}, + }, + { + id: "4175f0ae-59b1-4706-b1b2-c86fe04733df", + type: "-atjson-parse-token", + start: 71, + end: 82, + attributes: { + "-atjson-reason": "linebreak_open", + }, + }, + { + id: "7637a916-a923-4717-bb0d-639f93db70cd", + type: "-atjson-parse-token", + start: 82, + end: 94, + attributes: { + "-atjson-reason": "linebreak_close", + }, + }, + { + id: "ba420b55-9fb3-4806-98b0-b2c578c54c76", + type: "-atjson-parse-token", + start: 94, + end: 102, + attributes: { + "-atjson-reason": "$root_close", + }, + }, + ], + }); + + expect(CommonmarkRenderer.render(document)).toBe( + "Testing\\\n\\\nOne Another" + ); + }); + + test("Document without any linebreak at end.", () => { + let document = new OffsetSource({ + content: + "<$root>CommonMark", + annotations: [ + { + id: "79323f50-1c55-44d7-bdb6-6ca564f9dfe4", + type: "-atjson-parse-token", + start: 0, + end: 7, + attributes: { + "-atjson-reason": "$root_open", + }, + }, + { + id: "dbe8cec9-314d-4c94-b740-bc8f702a50f6", + type: "-offset-line-break", + start: 13, + end: 36, + attributes: {}, + }, + { + id: "ae7b7dde-16f5-4f81-b61f-810481c180d2", + type: "-atjson-parse-token", + start: 13, + end: 24, + attributes: { + "-atjson-reason": "linebreak_open", + }, + }, + { + id: "5bb80af6-b265-4e70-8b0b-6d8076382cfc", + type: "-atjson-parse-token", + start: 24, + end: 36, + attributes: { + "-atjson-reason": "linebreak_close", + }, + }, + { + id: "318764e6-d1e2-4e19-b7f8-879caa24f4ef", + type: "-offset-line-break", + start: 36, + end: 59, + attributes: {}, + }, + { + id: "4d176464-f801-465d-97f6-9e1c8246b71d", + type: "-atjson-parse-token", + start: 36, + end: 47, + attributes: { + "-atjson-reason": "linebreak_open", + }, + }, + { + id: "855b3060-6d16-489b-8704-346edbe8dd1a", + type: "-atjson-parse-token", + start: 47, + end: 59, + attributes: { + "-atjson-reason": "linebreak_close", + }, + }, + { + id: "bf098c6b-bccf-4e1b-a4c2-8796a0703f38", + type: "-atjson-parse-token", + start: 63, + end: 71, + attributes: { + "-atjson-reason": "$root_close", + }, + }, + ], + }); + + expect(CommonmarkRenderer.render(document)).toBe("Common\\\n\\\nMark"); + }); + + test("Empty Document", () => { + let document = new OffsetSource({ + content: + "<$root>", + annotations: [ + { + id: "ff84442c-9b87-4936-b7d1-0741ddf03685", + type: "-atjson-parse-token", + start: 0, + end: 7, + attributes: { + "-atjson-reason": "$root_open", + }, + }, + { + id: "cc5afcc8-dddf-4dcd-aa6a-e1191465b198", + type: "-offset-line-break", + start: 7, + end: 30, + attributes: {}, + }, + { + id: "992e0537-3eb5-4b74-92d6-c46c38440436", + type: "-atjson-parse-token", + start: 7, + end: 18, + attributes: { + "-atjson-reason": "linebreak_open", + }, + }, + { + id: "c38a713f-e276-4d0f-a0e0-927e48af7fee", + type: "-atjson-parse-token", + start: 18, + end: 30, + attributes: { + "-atjson-reason": "linebreak_close", + }, + }, + { + id: "29487bae-8b0b-4c70-89b6-e5ec62a9304c", + type: "-offset-line-break", + start: 30, + end: 53, + attributes: {}, + }, + { + id: "0da8ef3b-4807-45d9-9629-1e0fd6c6d637", + type: "-atjson-parse-token", + start: 30, + end: 41, + attributes: { + "-atjson-reason": "linebreak_open", + }, + }, + { + id: "76cdea7d-b223-4b43-8fe2-7f0967246a71", + type: "-atjson-parse-token", + start: 41, + end: 53, + attributes: { + "-atjson-reason": "linebreak_close", + }, + }, + { + id: "468a3f4a-3f9b-4de1-bdef-e7ab802deb68", + type: "-offset-line-break", + start: 53, + end: 76, + attributes: {}, + }, + { + id: "58b4d429-73bc-4968-9e96-df06fc505609", + type: "-atjson-parse-token", + start: 53, + end: 64, + attributes: { + "-atjson-reason": "linebreak_open", + }, + }, + { + id: "412475eb-c68d-4aee-a6c6-c3676dbd0678", + type: "-atjson-parse-token", + start: 64, + end: 76, + attributes: { + "-atjson-reason": "linebreak_close", + }, + }, + { + id: "08f6f3b1-aae1-4586-9fc8-a5a56a63287c", + type: "-atjson-parse-token", + start: 76, + end: 84, + attributes: { + "-atjson-reason": "$root_close", + }, + }, + ], + }); + + expect(CommonmarkRenderer.render(document)).toBe("\\\n\\\n"); + }); + test.each([ ["paragraph", "a\n\n"], ["blockquote", "> a\n\n"], From b352160b5c739a1b3ad40e1396b9a5e8de212c67 Mon Sep 17 00:00:00 2001 From: Bach Bui Date: Wed, 26 Jun 2024 16:44:04 -0400 Subject: [PATCH 02/12] 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 --- .../@atjson/renderer-commonmark/src/index.ts | 4 + .../commonmark-spec.test.ts.snap | 1018 ++++++++++++++++- .../test/line-break.test.ts | 201 ++++ 3 files changed, 1174 insertions(+), 49 deletions(-) create mode 100644 packages/@atjson/renderer-commonmark/test/line-break.test.ts diff --git a/packages/@atjson/renderer-commonmark/src/index.ts b/packages/@atjson/renderer-commonmark/src/index.ts index 2c0044e62..7cb67ad00 100644 --- a/packages/@atjson/renderer-commonmark/src/index.ts +++ b/packages/@atjson/renderer-commonmark/src/index.ts @@ -474,6 +474,10 @@ export default class CommonmarkRenderer extends Renderer { return ""; } + if (context.parent == null && context.next == null) { + return ""; + } + // MD code and html blocks cannot contain line breaks // https://spec.commonmark.org/0.29/#example-637 if (context.parent?.type === "code" || context.parent?.type === "html") { diff --git a/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap b/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap index baa398c80..ce238b364 100644 --- a/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap +++ b/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap @@ -1098,6 +1098,42 @@ exports[`ATX headings foo } `; +exports[`Autolinks < http://foo.bar > + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..19]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "< http://foo.bar >", +} +`; + +exports[`Autolinks < http://foo.bar > + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..19]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "< http://foo.bar >", +} +`; + exports[`Autolinks < https://foo.bar > 1`] = ` { @@ -1458,6 +1494,168 @@ exports[`Autolinks } `; +exports[`Autolinks + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..11]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://../", + }, + "id": "M00000000", + "range": "(1..11]", + "type": "link", + }, + ], + "text": "http://../", +} +`; + +exports[`Autolinks + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..11]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://../", + }, + "id": "M00000000", + "range": "(1..11]", + "type": "link", + }, + ], + "text": "http://../", +} +`; + +exports[`Autolinks + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..23]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://example.com/%5C%5B%5C", + }, + "id": "M00000000", + "range": "(1..23]", + "type": "link", + }, + ], + "text": "http://example.com/\\[\\", +} +`; + +exports[`Autolinks + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..23]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://example.com/%5C%5B%5C", + }, + "id": "M00000000", + "range": "(1..23]", + "type": "link", + }, + ], + "text": "http://example.com/\\[\\", +} +`; + +exports[`Autolinks + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..46]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://foo.bar.baz/test?q=hello&id=22&boolean", + }, + "id": "M00000000", + "range": "(1..46]", + "type": "link", + }, + ], + "text": "http://foo.bar.baz/test?q=hello&id=22&boolean", +} +`; + +exports[`Autolinks + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..46]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://foo.bar.baz/test?q=hello&id=22&boolean", + }, + "id": "M00000000", + "range": "(1..46]", + "type": "link", + }, + ], + "text": "http://foo.bar.baz/test?q=hello&id=22&boolean", +} +`; + exports[`Autolinks 1`] = ` { @@ -1512,6 +1710,42 @@ exports[`Autolinks } `; +exports[`Autolinks + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..25]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "", +} +`; + +exports[`Autolinks + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..25]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "", +} +`; + exports[`Autolinks 1`] = ` { @@ -1944,6 +2178,42 @@ exports[`Autolinks foo@bar.example.com } `; +exports[`Autolinks http://example.com + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..19]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "http://example.com", +} +`; + +exports[`Autolinks http://example.com + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..19]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "http://example.com", +} +`; + exports[`Autolinks https://example.com 1`] = ` { @@ -2056,7 +2326,7 @@ exports[`Backslash escapes } `; -exports[`Backslash escapes +exports[`Backslash escapes 1`] = ` { "blocks": [ @@ -2064,7 +2334,7 @@ exports[`Backslash escapes "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..28]", + "range": "(0..27]", "selfClosing": false, "type": "paragraph", }, @@ -2072,18 +2342,18 @@ exports[`Backslash escapes "marks": [ { "attributes": { - "href": "https://example.com?find=%5C*", + "href": "http://example.com?find=%5C*", }, "id": "M00000000", - "range": "(1..28]", + "range": "(1..27]", "type": "link", }, ], - "text": "https://example.com?find=\\*", + "text": "http://example.com?find=\\*", } `; -exports[`Backslash escapes +exports[`Backslash escapes 2`] = ` { "blocks": [ @@ -2091,7 +2361,7 @@ exports[`Backslash escapes "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..28]", + "range": "(0..27]", "selfClosing": false, "type": "paragraph", }, @@ -2099,20 +2369,18 @@ exports[`Backslash escapes "marks": [ { "attributes": { - "href": "https://example.com?find=%5C*", + "href": "http://example.com?find=%5C*", }, "id": "M00000000", - "range": "(1..28]", + "range": "(1..27]", "type": "link", }, ], - "text": "https://example.com?find=\\*", + "text": "http://example.com?find=\\*", } `; -exports[`Backslash escapes [foo] - -[foo]: /bar\\* "ti\\*tle" +exports[`Backslash escapes 1`] = ` { "blocks": [ @@ -2120,7 +2388,7 @@ exports[`Backslash escapes [foo] "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..4]", + "range": "(0..28]", "selfClosing": false, "type": "paragraph", }, @@ -2128,21 +2396,18 @@ exports[`Backslash escapes [foo] "marks": [ { "attributes": { - "href": "/bar*", - "title": "ti*tle", + "href": "https://example.com?find=%5C*", }, "id": "M00000000", - "range": "(1..4]", + "range": "(1..28]", "type": "link", }, ], - "text": "foo", + "text": "https://example.com?find=\\*", } `; -exports[`Backslash escapes [foo] - -[foo]: /bar\\* "ti\\*tle" +exports[`Backslash escapes 2`] = ` { "blocks": [ @@ -2150,7 +2415,7 @@ exports[`Backslash escapes [foo] "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..4]", + "range": "(0..28]", "selfClosing": false, "type": "paragraph", }, @@ -2158,19 +2423,78 @@ exports[`Backslash escapes [foo] "marks": [ { "attributes": { - "href": "/bar*", - "title": "ti*tle", + "href": "https://example.com?find=%5C*", }, "id": "M00000000", - "range": "(1..4]", + "range": "(1..28]", "type": "link", }, ], - "text": "foo", + "text": "https://example.com?find=\\*", } `; -exports[`Backslash escapes [foo](/bar\\* "ti\\*tle") +exports[`Backslash escapes [foo] + +[foo]: /bar\\* "ti\\*tle" + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..4]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "/bar*", + "title": "ti*tle", + }, + "id": "M00000000", + "range": "(1..4]", + "type": "link", + }, + ], + "text": "foo", +} +`; + +exports[`Backslash escapes [foo] + +[foo]: /bar\\* "ti\\*tle" + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..4]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "/bar*", + "title": "ti*tle", + }, + "id": "M00000000", + "range": "(1..4]", + "type": "link", + }, + ], + "text": "foo", +} +`; + +exports[`Backslash escapes [foo](/bar\\* "ti\\*tle") 1`] = ` { "blocks": [ @@ -4756,6 +5080,60 @@ exports[`Code spans \` } `; +exports[`Code spans \` + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..21]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://foo.bar.%60baz", + }, + "id": "M00000000", + "range": "(1..20]", + "type": "link", + }, + ], + "text": "http://foo.bar.\`baz\`", +} +`; + +exports[`Code spans \` + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..21]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://foo.bar.%60baz", + }, + "id": "M00000000", + "range": "(1..20]", + "type": "link", + }, + ], + "text": "http://foo.bar.\`baz\`", +} +`; + exports[`Code spans \` 1`] = ` { @@ -5060,6 +5438,56 @@ exports[`Code spans \`\` } `; +exports[`Code spans \`\` + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..22]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": {}, + "id": "M00000000", + "range": "(1..17]", + "type": "code_inline", + }, + ], + "text": "\`", +} +`; + +exports[`Code spans \`\` + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..22]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": {}, + "id": "M00000000", + "range": "(1..17]", + "type": "code_inline", + }, + ], + "text": "\`", +} +`; + exports[`Code spans \`\` 1`] = ` { @@ -6642,6 +7070,60 @@ Asclepias physocarpa)", } `; +exports[`Emphasis and strong emphasis **a + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..24]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://foo.bar/?q=**", + }, + "id": "M00000000", + "range": "(4..24]", + "type": "link", + }, + ], + "text": "**ahttp://foo.bar/?q=**", +} +`; + +exports[`Emphasis and strong emphasis **a + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..24]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://foo.bar/?q=**", + }, + "id": "M00000000", + "range": "(4..24]", + "type": "link", + }, + ], + "text": "**ahttp://foo.bar/?q=**", +} +`; + exports[`Emphasis and strong emphasis **a 1`] = ` { @@ -9842,7 +10324,7 @@ exports[`Emphasis and strong emphasis ___foo__ } `; -exports[`Emphasis and strong emphasis __a +exports[`Emphasis and strong emphasis __a 1`] = ` { "blocks": [ @@ -9850,7 +10332,7 @@ exports[`Emphasis and strong emphasis __a "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..25]", + "range": "(0..24]", "selfClosing": false, "type": "paragraph", }, @@ -9858,18 +10340,18 @@ exports[`Emphasis and strong emphasis __a "marks": [ { "attributes": { - "href": "https://foo.bar/?q=__", + "href": "http://foo.bar/?q=__", }, "id": "M00000000", - "range": "(4..25]", + "range": "(4..24]", "type": "link", }, ], - "text": "__ahttps://foo.bar/?q=__", + "text": "__ahttp://foo.bar/?q=__", } `; -exports[`Emphasis and strong emphasis __a +exports[`Emphasis and strong emphasis __a 2`] = ` { "blocks": [ @@ -9877,7 +10359,7 @@ exports[`Emphasis and strong emphasis __a "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..25]", + "range": "(0..24]", "selfClosing": false, "type": "paragraph", }, @@ -9885,18 +10367,18 @@ exports[`Emphasis and strong emphasis __a "marks": [ { "attributes": { - "href": "https://foo.bar/?q=__", + "href": "http://foo.bar/?q=__", }, "id": "M00000000", - "range": "(4..25]", + "range": "(4..24]", "type": "link", }, ], - "text": "__ahttps://foo.bar/?q=__", + "text": "__ahttp://foo.bar/?q=__", } `; -exports[`Emphasis and strong emphasis __foo __bar__ baz__ +exports[`Emphasis and strong emphasis __a 1`] = ` { "blocks": [ @@ -9904,31 +10386,54 @@ exports[`Emphasis and strong emphasis __foo __bar__ baz__ "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..12]", + "range": "(0..25]", "selfClosing": false, "type": "paragraph", }, ], "marks": [ { - "attributes": {}, + "attributes": { + "href": "https://foo.bar/?q=__", + }, "id": "M00000000", - "range": "(1..12]", - "type": "strong", + "range": "(4..25]", + "type": "link", }, + ], + "text": "__ahttps://foo.bar/?q=__", +} +`; + +exports[`Emphasis and strong emphasis __a + 2`] = ` +{ + "blocks": [ { "attributes": {}, - "id": "M00000001", - "range": "(5..8]", - "type": "strong", + "id": "B00000000", + "parents": [], + "range": "(0..25]", + "selfClosing": false, + "type": "paragraph", }, ], - "text": "foo bar baz", + "marks": [ + { + "attributes": { + "href": "https://foo.bar/?q=__", + }, + "id": "M00000000", + "range": "(4..25]", + "type": "link", + }, + ], + "text": "__ahttps://foo.bar/?q=__", } `; exports[`Emphasis and strong emphasis __foo __bar__ baz__ - 2`] = ` + 1`] = ` { "blocks": [ { @@ -9958,8 +10463,39 @@ exports[`Emphasis and strong emphasis __foo __bar__ baz__ } `; -exports[`Emphasis and strong emphasis __foo _bar_ baz__ - 1`] = ` +exports[`Emphasis and strong emphasis __foo __bar__ baz__ + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..12]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": {}, + "id": "M00000000", + "range": "(1..12]", + "type": "strong", + }, + { + "attributes": {}, + "id": "M00000001", + "range": "(5..8]", + "type": "strong", + }, + ], + "text": "foo bar baz", +} +`; + +exports[`Emphasis and strong emphasis __foo _bar_ baz__ + 1`] = ` { "blocks": [ { @@ -24244,6 +24780,118 @@ exports[`Links [foo*]: /url } `; +exports[`Links [foo + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..38]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://example.com/?search=%5D(uri)", + }, + "id": "M00000000", + "range": "(5..38]", + "type": "link", + }, + ], + "text": "[foohttp://example.com/?search=](uri)", +} +`; + +exports[`Links [foo + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..38]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://example.com/?search=%5D(uri)", + }, + "id": "M00000000", + "range": "(5..38]", + "type": "link", + }, + ], + "text": "[foohttp://example.com/?search=](uri)", +} +`; + +exports[`Links [foo + +[ref]: /uri + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..38]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://example.com/?search=%5D%5Bref%5D", + }, + "id": "M00000000", + "range": "(5..38]", + "type": "link", + }, + ], + "text": "[foohttp://example.com/?search=][ref]", +} +`; + +exports[`Links [foo + +[ref]: /uri + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..38]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://example.com/?search=%5D%5Bref%5D", + }, + "id": "M00000000", + "range": "(5..38]", + "type": "link", + }, + ], + "text": "[foohttp://example.com/?search=][ref]", +} +`; + exports[`Links [foo 1`] = ` { @@ -26254,6 +26902,132 @@ exports[`Links [link]("title") exports[`Links [link](#fragment) +[link](http://example.com#fragment) + +[link](http://example.com?foo=3#frag) + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..5]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [], + "range": "(5..10]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000002", + "parents": [], + "range": "(10..15]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "#fragment", + }, + "id": "M00000000", + "range": "(1..5]", + "type": "link", + }, + { + "attributes": { + "href": "http://example.com#fragment", + }, + "id": "M00000001", + "range": "(6..10]", + "type": "link", + }, + { + "attributes": { + "href": "http://example.com?foo=3#frag", + }, + "id": "M00000002", + "range": "(11..15]", + "type": "link", + }, + ], + "text": "linklinklink", +} +`; + +exports[`Links [link](#fragment) + +[link](http://example.com#fragment) + +[link](http://example.com?foo=3#frag) + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..5]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [], + "range": "(5..10]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000002", + "parents": [], + "range": "(10..15]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "#fragment", + }, + "id": "M00000000", + "range": "(1..5]", + "type": "link", + }, + { + "attributes": { + "href": "http://example.com#fragment", + }, + "id": "M00000001", + "range": "(6..10]", + "type": "link", + }, + { + "attributes": { + "href": "http://example.com?foo=3#frag", + }, + "id": "M00000002", + "range": "(11..15]", + "type": "link", + }, + ], + "text": "linklinklink", +} +`; + +exports[`Links [link](#fragment) + [link](https://example.com#fragment) [link](https://example.com?foo=3#frag) @@ -39780,6 +40554,96 @@ exports[`Raw HTML foo &<]]> } `; +exports[`Raw HTML foo + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..42]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "foo ", +} +`; + +exports[`Raw HTML foo + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..42]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "foo ", +} +`; + +exports[`Raw HTML foo + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..45]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": {}, + "id": "M00000000", + "range": "(5..45]", + "type": "html_inline", + }, + ], + "text": "foo ", +} +`; + +exports[`Raw HTML foo + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..45]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": {}, + "id": "M00000000", + "range": "(5..45]", + "type": "html_inline", + }, + ], + "text": "foo ", +} +`; + exports[`Raw HTML foo 1`] = ` @@ -39836,6 +40700,62 @@ comment - with hyphens -->", exports[`Raw HTML foo foo --> +foo + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..18]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [], + "range": "(18..35]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "foo foo -->foo ", +} +`; + +exports[`Raw HTML foo foo --> + +foo + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..18]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [], + "range": "(18..35]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "foo foo -->foo ", +} +`; + +exports[`Raw HTML foo foo --> + foo foo --> 1`] = ` { diff --git a/packages/@atjson/renderer-commonmark/test/line-break.test.ts b/packages/@atjson/renderer-commonmark/test/line-break.test.ts new file mode 100644 index 000000000..763e09216 --- /dev/null +++ b/packages/@atjson/renderer-commonmark/test/line-break.test.ts @@ -0,0 +1,201 @@ +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 text with preceding linebreaks", () => { + const document = { + text: "\ufffctest\ufffctest\ufffc", + blocks: [ + { + id: "B00000000", + type: "text", + parents: [], + selfClosing: false, + attributes: {}, + }, + { + id: "B00000000", + type: "line-break", + parents: ["text"], + selfClosing: true, + attributes: {}, + }, + { + id: "B00000000", + type: "line-break", + parents: ["text"], + selfClosing: true, + attributes: {}, + }, + ], + marks: [], + }; + + expect(CommonmarkRenderer.render(document)).toBe("test\\\ntest"); + }); + + test.skip("in text terminating a mark", () => { + 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: [ + { + id: "M00000000", + type: "bold", + range: "(1..6]" as const, + attributes: {}, + }, + ], + }; + + 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 text terminating a mark", () => { + 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: [ + { + id: "M00000000", + type: "bold", + range: "(1..8]" as const, + attributes: {}, + }, + ], + }; + + 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"); + }); +}); From 381c7a3e79ef34d02237c4de9ac3d88ed3b23fd7 Mon Sep 17 00:00:00 2001 From: Bach Bui Date: Tue, 2 Jul 2024 10:13:58 -0400 Subject: [PATCH 03/12] fix: add cleanup step to remove all terminal linebreaks --- packages/@atjson/renderer-commonmark/src/index.ts | 8 ++++++-- .../@atjson/renderer-commonmark/test/commonmark.test.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/@atjson/renderer-commonmark/src/index.ts b/packages/@atjson/renderer-commonmark/src/index.ts index 7cb67ad00..cbd8b56f1 100644 --- a/packages/@atjson/renderer-commonmark/src/index.ts +++ b/packages/@atjson/renderer-commonmark/src/index.ts @@ -253,8 +253,12 @@ export default class CommonmarkRenderer extends Renderer { } *root(): Iterator { - let rawText = yield; - return rawText.join(""); + let rawText = (yield).join(""); + + while (rawText.length >= 2 && rawText.slice(-2) === "\\\n") { + rawText = rawText.slice(0, rawText.length - 2); + } + return rawText; } /** diff --git a/packages/@atjson/renderer-commonmark/test/commonmark.test.ts b/packages/@atjson/renderer-commonmark/test/commonmark.test.ts index 5f486f383..60dca26ad 100644 --- a/packages/@atjson/renderer-commonmark/test/commonmark.test.ts +++ b/packages/@atjson/renderer-commonmark/test/commonmark.test.ts @@ -2092,7 +2092,7 @@ After all the lists ], }); - expect(CommonmarkRenderer.render(document)).toBe("\\\n\\\n"); + expect(CommonmarkRenderer.render(document)).toBe(""); }); test.each([ From 5937b159d21b858f6a05f1070cd42d0eb6d260b6 Mon Sep 17 00:00:00 2001 From: Bach Bui Date: Tue, 2 Jul 2024 10:15:20 -0400 Subject: [PATCH 04/12] chore: remove obsolete snapshots --- .../commonmark-spec.test.ts.snap | 1020 +---------------- 1 file changed, 17 insertions(+), 1003 deletions(-) diff --git a/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap b/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap index ce238b364..327f967af 100644 --- a/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap +++ b/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap @@ -1134,42 +1134,6 @@ exports[`Autolinks < http://foo.bar > } `; -exports[`Autolinks < https://foo.bar > - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..20]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "< https://foo.bar >", -} -`; - -exports[`Autolinks < https://foo.bar > - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..20]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "< https://foo.bar >", -} -`; - exports[`Autolinks <> 1`] = ` { @@ -1746,204 +1710,6 @@ exports[`Autolinks } `; -exports[`Autolinks - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..12]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://../", - }, - "id": "M00000000", - "range": "(1..12]", - "type": "link", - }, - ], - "text": "https://../", -} -`; - -exports[`Autolinks - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..12]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://../", - }, - "id": "M00000000", - "range": "(1..12]", - "type": "link", - }, - ], - "text": "https://../", -} -`; - -exports[`Autolinks - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..24]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://example.com/%5C%5B%5C", - }, - "id": "M00000000", - "range": "(1..24]", - "type": "link", - }, - ], - "text": "https://example.com/\\[\\", -} -`; - -exports[`Autolinks - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..24]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://example.com/%5C%5B%5C", - }, - "id": "M00000000", - "range": "(1..24]", - "type": "link", - }, - ], - "text": "https://example.com/\\[\\", -} -`; - -exports[`Autolinks - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..47]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://foo.bar.baz/test?q=hello&id=22&boolean", - }, - "id": "M00000000", - "range": "(1..47]", - "type": "link", - }, - ], - "text": "https://foo.bar.baz/test?q=hello&id=22&boolean", -} -`; - -exports[`Autolinks - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..47]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://foo.bar.baz/test?q=hello&id=22&boolean", - }, - "id": "M00000000", - "range": "(1..47]", - "type": "link", - }, - ], - "text": "https://foo.bar.baz/test?q=hello&id=22&boolean", -} -`; - -exports[`Autolinks - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..26]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "", -} -`; - -exports[`Autolinks - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..26]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "", -} -`; - exports[`Autolinks 1`] = ` { @@ -2214,42 +1980,6 @@ exports[`Autolinks http://example.com } `; -exports[`Autolinks https://example.com - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..20]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "https://example.com", -} -`; - -exports[`Autolinks https://example.com - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..20]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "https://example.com", -} -`; - exports[`Backslash escapes \\[\\] 1`] = ` { @@ -2380,7 +2110,9 @@ exports[`Backslash escapes } `; -exports[`Backslash escapes +exports[`Backslash escapes [foo] + +[foo]: /bar\\* "ti\\*tle" 1`] = ` { "blocks": [ @@ -2388,7 +2120,7 @@ exports[`Backslash escapes "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..28]", + "range": "(0..4]", "selfClosing": false, "type": "paragraph", }, @@ -2396,18 +2128,21 @@ exports[`Backslash escapes "marks": [ { "attributes": { - "href": "https://example.com?find=%5C*", + "href": "/bar*", + "title": "ti*tle", }, "id": "M00000000", - "range": "(1..28]", + "range": "(1..4]", "type": "link", }, ], - "text": "https://example.com?find=\\*", + "text": "foo", } `; -exports[`Backslash escapes +exports[`Backslash escapes [foo] + +[foo]: /bar\\* "ti\\*tle" 2`] = ` { "blocks": [ @@ -2415,7 +2150,7 @@ exports[`Backslash escapes "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..28]", + "range": "(0..4]", "selfClosing": false, "type": "paragraph", }, @@ -2423,78 +2158,19 @@ exports[`Backslash escapes "marks": [ { "attributes": { - "href": "https://example.com?find=%5C*", + "href": "/bar*", + "title": "ti*tle", }, "id": "M00000000", - "range": "(1..28]", + "range": "(1..4]", "type": "link", }, ], - "text": "https://example.com?find=\\*", + "text": "foo", } `; -exports[`Backslash escapes [foo] - -[foo]: /bar\\* "ti\\*tle" - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..4]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "/bar*", - "title": "ti*tle", - }, - "id": "M00000000", - "range": "(1..4]", - "type": "link", - }, - ], - "text": "foo", -} -`; - -exports[`Backslash escapes [foo] - -[foo]: /bar\\* "ti\\*tle" - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..4]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "/bar*", - "title": "ti*tle", - }, - "id": "M00000000", - "range": "(1..4]", - "type": "link", - }, - ], - "text": "foo", -} -`; - -exports[`Backslash escapes [foo](/bar\\* "ti\\*tle") +exports[`Backslash escapes [foo](/bar\\* "ti\\*tle") 1`] = ` { "blocks": [ @@ -5134,60 +4810,6 @@ exports[`Code spans \` } `; -exports[`Code spans \` - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..22]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://foo.bar.%60baz", - }, - "id": "M00000000", - "range": "(1..21]", - "type": "link", - }, - ], - "text": "https://foo.bar.\`baz\`", -} -`; - -exports[`Code spans \` - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..22]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://foo.bar.%60baz", - }, - "id": "M00000000", - "range": "(1..21]", - "type": "link", - }, - ], - "text": "https://foo.bar.\`baz\`", -} -`; - exports[`Code spans [not a \`link](/foo\`) 1`] = ` { @@ -5488,56 +5110,6 @@ exports[`Code spans \`\` } `; -exports[`Code spans \`\` - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..23]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": {}, - "id": "M00000000", - "range": "(1..18]", - "type": "code_inline", - }, - ], - "text": "\`", -} -`; - -exports[`Code spans \`\` - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..23]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": {}, - "id": "M00000000", - "range": "(1..18]", - "type": "code_inline", - }, - ], - "text": "\`", -} -`; - exports[`Code spans \`\` foo bar @@ -6140,82 +5712,6 @@ exports[`Code spans \` b \` } `; -exports[`Emphasis and strong emphasis *$*alpha. - -*£*bravo. - -*€*charlie. - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..10]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000001", - "parents": [], - "range": "(10..20]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000002", - "parents": [], - "range": "(20..32]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "*$*alpha.*£*bravo.*€*charlie.", -} -`; - -exports[`Emphasis and strong emphasis *$*alpha. - -*£*bravo. - -*€*charlie. - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..10]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000001", - "parents": [], - "range": "(10..20]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000002", - "parents": [], - "range": "(20..32]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "*$*alpha.*£*bravo.*€*charlie.", -} -`; - exports[`Emphasis and strong emphasis *(**foo**)* 1`] = ` { @@ -7124,60 +6620,6 @@ exports[`Emphasis and strong emphasis **a } `; -exports[`Emphasis and strong emphasis **a - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..25]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://foo.bar/?q=**", - }, - "id": "M00000000", - "range": "(4..25]", - "type": "link", - }, - ], - "text": "**ahttps://foo.bar/?q=**", -} -`; - -exports[`Emphasis and strong emphasis **a - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..25]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://foo.bar/?q=**", - }, - "id": "M00000000", - "range": "(4..25]", - "type": "link", - }, - ], - "text": "**ahttps://foo.bar/?q=**", -} -`; - exports[`Emphasis and strong emphasis **foo bar** 1`] = ` @@ -10378,60 +9820,6 @@ exports[`Emphasis and strong emphasis __a } `; -exports[`Emphasis and strong emphasis __a - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..25]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://foo.bar/?q=__", - }, - "id": "M00000000", - "range": "(4..25]", - "type": "link", - }, - ], - "text": "__ahttps://foo.bar/?q=__", -} -`; - -exports[`Emphasis and strong emphasis __a - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..25]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://foo.bar/?q=__", - }, - "id": "M00000000", - "range": "(4..25]", - "type": "link", - }, - ], - "text": "__ahttps://foo.bar/?q=__", -} -`; - exports[`Emphasis and strong emphasis __foo __bar__ baz__ 1`] = ` { @@ -24892,118 +24280,6 @@ exports[`Links [foo } `; -exports[`Links [foo - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..39]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://example.com/?search=%5D(uri)", - }, - "id": "M00000000", - "range": "(5..39]", - "type": "link", - }, - ], - "text": "[foohttps://example.com/?search=](uri)", -} -`; - -exports[`Links [foo - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..39]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://example.com/?search=%5D(uri)", - }, - "id": "M00000000", - "range": "(5..39]", - "type": "link", - }, - ], - "text": "[foohttps://example.com/?search=](uri)", -} -`; - -exports[`Links [foo - -[ref]: /uri - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..39]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://example.com/?search=%5D%5Bref%5D", - }, - "id": "M00000000", - "range": "(5..39]", - "type": "link", - }, - ], - "text": "[foohttps://example.com/?search=][ref]", -} -`; - -exports[`Links [foo - -[ref]: /uri - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..39]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "https://example.com/?search=%5D%5Bref%5D", - }, - "id": "M00000000", - "range": "(5..39]", - "type": "link", - }, - ], - "text": "[foohttps://example.com/?search=][ref]", -} -`; - exports[`Links [foo] [foo]: /url "title" @@ -27026,132 +26302,6 @@ exports[`Links [link](#fragment) } `; -exports[`Links [link](#fragment) - -[link](https://example.com#fragment) - -[link](https://example.com?foo=3#frag) - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..5]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000001", - "parents": [], - "range": "(5..10]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000002", - "parents": [], - "range": "(10..15]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "#fragment", - }, - "id": "M00000000", - "range": "(1..5]", - "type": "link", - }, - { - "attributes": { - "href": "https://example.com#fragment", - }, - "id": "M00000001", - "range": "(6..10]", - "type": "link", - }, - { - "attributes": { - "href": "https://example.com?foo=3#frag", - }, - "id": "M00000002", - "range": "(11..15]", - "type": "link", - }, - ], - "text": "linklinklink", -} -`; - -exports[`Links [link](#fragment) - -[link](https://example.com#fragment) - -[link](https://example.com?foo=3#frag) - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..5]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000001", - "parents": [], - "range": "(5..10]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000002", - "parents": [], - "range": "(10..15]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "#fragment", - }, - "id": "M00000000", - "range": "(1..5]", - "type": "link", - }, - { - "attributes": { - "href": "https://example.com#fragment", - }, - "id": "M00000001", - "range": "(6..10]", - "type": "link", - }, - { - "attributes": { - "href": "https://example.com?foo=3#frag", - }, - "id": "M00000002", - "range": "(11..15]", - "type": "link", - }, - ], - "text": "linklinklink", -} -`; - exports[`Links [link]() 1`] = ` { @@ -40644,60 +39794,6 @@ comment - with hyphen -->", } `; -exports[`Raw HTML foo - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..49]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": {}, - "id": "M00000000", - "range": "(5..49]", - "type": "html_inline", - }, - ], - "text": "foo ", -} -`; - -exports[`Raw HTML foo - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..49]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": {}, - "id": "M00000000", - "range": "(5..49]", - "type": "html_inline", - }, - ], - "text": "foo ", -} -`; - exports[`Raw HTML foo foo --> foo @@ -40754,88 +39850,6 @@ foo } `; -exports[`Raw HTML foo foo --> - -foo foo --> - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..18]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000001", - "parents": [], - "range": "(18..37]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": {}, - "id": "M00000000", - "range": "(5..10]", - "type": "html_inline", - }, - { - "attributes": {}, - "id": "M00000001", - "range": "(23..29]", - "type": "html_inline", - }, - ], - "text": "foo foo -->foo foo -->", -} -`; - -exports[`Raw HTML foo foo --> - -foo foo --> - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..18]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000001", - "parents": [], - "range": "(18..37]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": {}, - "id": "M00000000", - "range": "(5..10]", - "type": "html_inline", - }, - { - "attributes": {}, - "id": "M00000001", - "range": "(23..29]", - "type": "html_inline", - }, - ], - "text": "foo foo -->foo foo -->", -} -`; - exports[`Raw HTML foo 1`] = ` { From 0910044d6e4c7581bee07ea59db41d5f42492da4 Mon Sep 17 00:00:00 2001 From: Bach Bui Date: Tue, 2 Jul 2024 10:59:21 -0400 Subject: [PATCH 05/12] fix: handle linebreaks followed by new lines --- .../@atjson/renderer-commonmark/src/index.ts | 6 +- .../test/line-break.test.ts | 81 +++++++++++++++---- 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/packages/@atjson/renderer-commonmark/src/index.ts b/packages/@atjson/renderer-commonmark/src/index.ts index cbd8b56f1..3215a860a 100644 --- a/packages/@atjson/renderer-commonmark/src/index.ts +++ b/packages/@atjson/renderer-commonmark/src/index.ts @@ -254,11 +254,7 @@ export default class CommonmarkRenderer extends Renderer { *root(): Iterator { let rawText = (yield).join(""); - - while (rawText.length >= 2 && rawText.slice(-2) === "\\\n") { - rawText = rawText.slice(0, rawText.length - 2); - } - return rawText; + return rawText.replace(/(\\\n(\n*))+$/gs, "$2"); } /** diff --git a/packages/@atjson/renderer-commonmark/test/line-break.test.ts b/packages/@atjson/renderer-commonmark/test/line-break.test.ts index 763e09216..f53c95398 100644 --- a/packages/@atjson/renderer-commonmark/test/line-break.test.ts +++ b/packages/@atjson/renderer-commonmark/test/line-break.test.ts @@ -3,7 +3,7 @@ import CommonmarkRenderer from "../src"; describe("terminal line breaks are removed", () => { test("in text", () => { const document = { - text: "\ufffctest\ufffc", + text: "\ufffctest\ufffc\ufffc", blocks: [ { id: "B00000000", @@ -13,7 +13,14 @@ describe("terminal line breaks are removed", () => { attributes: {}, }, { - id: "B00000000", + id: "B00000001", + type: "line-break", + parents: ["text"], + selfClosing: true, + attributes: {}, + }, + { + id: "B00000002", type: "line-break", parents: ["text"], selfClosing: true, @@ -26,6 +33,38 @@ describe("terminal line breaks are removed", () => { expect(CommonmarkRenderer.render(document)).toBe("test"); }); + test("in text with interleaving new lines", () => { + const document = { + text: "\ufffctest\ufffc\n\ufffc", + blocks: [ + { + id: "B00000000", + type: "text", + parents: [], + selfClosing: false, + attributes: {}, + }, + { + id: "B00000001", + type: "line-break", + parents: ["text"], + selfClosing: true, + attributes: {}, + }, + { + id: "B00000002", + type: "line-break", + parents: ["text"], + selfClosing: true, + attributes: {}, + }, + ], + marks: [], + }; + + expect(CommonmarkRenderer.render(document)).toBe("test\n"); + }); + test("in text with preceding linebreaks", () => { const document = { text: "\ufffctest\ufffctest\ufffc", @@ -38,14 +77,14 @@ describe("terminal line breaks are removed", () => { attributes: {}, }, { - id: "B00000000", + id: "B00000001", type: "line-break", parents: ["text"], selfClosing: true, attributes: {}, }, { - id: "B00000000", + id: "B00000002", type: "line-break", parents: ["text"], selfClosing: true, @@ -58,7 +97,7 @@ describe("terminal line breaks are removed", () => { expect(CommonmarkRenderer.render(document)).toBe("test\\\ntest"); }); - test.skip("in text terminating a mark", () => { + test("in text terminating a mark", () => { const document = { text: "\ufffctest\ufffc", blocks: [ @@ -70,7 +109,7 @@ describe("terminal line breaks are removed", () => { attributes: {}, }, { - id: "B00000000", + id: "B00000001", type: "line-break", parents: ["text"], selfClosing: true, @@ -79,7 +118,7 @@ describe("terminal line breaks are removed", () => { ], marks: [ { - id: "M00000000", + id: "M00000002", type: "bold", range: "(1..6]" as const, attributes: {}, @@ -90,9 +129,9 @@ describe("terminal line breaks are removed", () => { expect(CommonmarkRenderer.render(document)).toBe("**test**"); }); - test("in paragraph", () => { + test("in paragraphs", () => { const document = { - text: "\ufffctest\ufffc", + text: "\ufffctest\ufffc\ufffctest\ufffc", blocks: [ { id: "B00000000", @@ -102,7 +141,21 @@ describe("terminal line breaks are removed", () => { attributes: {}, }, { - id: "B00000000", + id: "B00000001", + type: "line-break", + parents: ["paragraph"], + selfClosing: true, + attributes: {}, + }, + { + id: "B00000002", + type: "paragraph", + parents: [], + selfClosing: false, + attributes: {}, + }, + { + id: "B00000003", type: "line-break", parents: ["paragraph"], selfClosing: true, @@ -112,7 +165,7 @@ describe("terminal line breaks are removed", () => { marks: [], }; - expect(CommonmarkRenderer.render(document)).toBe("test\n\n"); + expect(CommonmarkRenderer.render(document)).toBe("test\n\ntest\n\n"); }); }); @@ -129,7 +182,7 @@ describe("are slash escaped", () => { attributes: {}, }, { - id: "B00000000", + id: "B00000001", type: "line-break", parents: ["text"], selfClosing: true, @@ -154,7 +207,7 @@ describe("are slash escaped", () => { attributes: {}, }, { - id: "B00000000", + id: "B00000001", type: "line-break", parents: ["text"], selfClosing: true, @@ -186,7 +239,7 @@ describe("are slash escaped", () => { attributes: {}, }, { - id: "B00000000", + id: "B00000001", type: "line-break", parents: ["paragraph"], selfClosing: true, From dc124610026b74203e90562975cc07120a45715a Mon Sep 17 00:00:00 2001 From: Bach Bui Date: Tue, 2 Jul 2024 14:06:10 -0400 Subject: [PATCH 06/12] chore: revert changes to commonmark snapshots --- .../commonmark-spec.test.ts.snap | 446 ++++++++++-------- 1 file changed, 256 insertions(+), 190 deletions(-) diff --git a/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap b/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap index 327f967af..baa398c80 100644 --- a/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap +++ b/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap @@ -1098,7 +1098,7 @@ exports[`ATX headings foo } `; -exports[`Autolinks < http://foo.bar > +exports[`Autolinks < https://foo.bar > 1`] = ` { "blocks": [ @@ -1106,17 +1106,17 @@ exports[`Autolinks < http://foo.bar > "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..19]", + "range": "(0..20]", "selfClosing": false, "type": "paragraph", }, ], "marks": [], - "text": "< http://foo.bar >", + "text": "< https://foo.bar >", } `; -exports[`Autolinks < http://foo.bar > +exports[`Autolinks < https://foo.bar > 2`] = ` { "blocks": [ @@ -1124,13 +1124,13 @@ exports[`Autolinks < http://foo.bar > "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..19]", + "range": "(0..20]", "selfClosing": false, "type": "paragraph", }, ], "marks": [], - "text": "< http://foo.bar >", + "text": "< https://foo.bar >", } `; @@ -1458,7 +1458,7 @@ exports[`Autolinks } `; -exports[`Autolinks +exports[`Autolinks 1`] = ` { "blocks": [ @@ -1466,7 +1466,7 @@ exports[`Autolinks "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..11]", + "range": "(0..19]", "selfClosing": false, "type": "paragraph", }, @@ -1474,18 +1474,18 @@ exports[`Autolinks "marks": [ { "attributes": { - "href": "http://../", + "href": "http://foo.bar.baz", }, "id": "M00000000", - "range": "(1..11]", + "range": "(1..19]", "type": "link", }, ], - "text": "http://../", + "text": "http://foo.bar.baz", } `; -exports[`Autolinks +exports[`Autolinks 2`] = ` { "blocks": [ @@ -1493,7 +1493,7 @@ exports[`Autolinks "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..11]", + "range": "(0..19]", "selfClosing": false, "type": "paragraph", }, @@ -1501,18 +1501,18 @@ exports[`Autolinks "marks": [ { "attributes": { - "href": "http://../", + "href": "http://foo.bar.baz", }, "id": "M00000000", - "range": "(1..11]", + "range": "(1..19]", "type": "link", }, ], - "text": "http://../", + "text": "http://foo.bar.baz", } `; -exports[`Autolinks +exports[`Autolinks 1`] = ` { "blocks": [ @@ -1520,7 +1520,7 @@ exports[`Autolinks "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..23]", + "range": "(0..12]", "selfClosing": false, "type": "paragraph", }, @@ -1528,18 +1528,18 @@ exports[`Autolinks "marks": [ { "attributes": { - "href": "http://example.com/%5C%5B%5C", + "href": "https://../", }, "id": "M00000000", - "range": "(1..23]", + "range": "(1..12]", "type": "link", }, ], - "text": "http://example.com/\\[\\", + "text": "https://../", } `; -exports[`Autolinks +exports[`Autolinks 2`] = ` { "blocks": [ @@ -1547,7 +1547,7 @@ exports[`Autolinks "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..23]", + "range": "(0..12]", "selfClosing": false, "type": "paragraph", }, @@ -1555,18 +1555,18 @@ exports[`Autolinks "marks": [ { "attributes": { - "href": "http://example.com/%5C%5B%5C", + "href": "https://../", }, "id": "M00000000", - "range": "(1..23]", + "range": "(1..12]", "type": "link", }, ], - "text": "http://example.com/\\[\\", + "text": "https://../", } `; -exports[`Autolinks +exports[`Autolinks 1`] = ` { "blocks": [ @@ -1574,7 +1574,7 @@ exports[`Autolinks "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..46]", + "range": "(0..24]", "selfClosing": false, "type": "paragraph", }, @@ -1582,18 +1582,18 @@ exports[`Autolinks "marks": [ { "attributes": { - "href": "http://foo.bar.baz/test?q=hello&id=22&boolean", + "href": "https://example.com/%5C%5B%5C", }, "id": "M00000000", - "range": "(1..46]", + "range": "(1..24]", "type": "link", }, ], - "text": "http://foo.bar.baz/test?q=hello&id=22&boolean", + "text": "https://example.com/\\[\\", } `; -exports[`Autolinks +exports[`Autolinks 2`] = ` { "blocks": [ @@ -1601,7 +1601,7 @@ exports[`Autolinks "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..46]", + "range": "(0..24]", "selfClosing": false, "type": "paragraph", }, @@ -1609,18 +1609,18 @@ exports[`Autolinks "marks": [ { "attributes": { - "href": "http://foo.bar.baz/test?q=hello&id=22&boolean", + "href": "https://example.com/%5C%5B%5C", }, "id": "M00000000", - "range": "(1..46]", + "range": "(1..24]", "type": "link", }, ], - "text": "http://foo.bar.baz/test?q=hello&id=22&boolean", + "text": "https://example.com/\\[\\", } `; -exports[`Autolinks +exports[`Autolinks 1`] = ` { "blocks": [ @@ -1628,7 +1628,7 @@ exports[`Autolinks "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..19]", + "range": "(0..47]", "selfClosing": false, "type": "paragraph", }, @@ -1636,18 +1636,18 @@ exports[`Autolinks "marks": [ { "attributes": { - "href": "http://foo.bar.baz", + "href": "https://foo.bar.baz/test?q=hello&id=22&boolean", }, "id": "M00000000", - "range": "(1..19]", + "range": "(1..47]", "type": "link", }, ], - "text": "http://foo.bar.baz", + "text": "https://foo.bar.baz/test?q=hello&id=22&boolean", } `; -exports[`Autolinks +exports[`Autolinks 2`] = ` { "blocks": [ @@ -1655,7 +1655,7 @@ exports[`Autolinks "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..19]", + "range": "(0..47]", "selfClosing": false, "type": "paragraph", }, @@ -1663,18 +1663,18 @@ exports[`Autolinks "marks": [ { "attributes": { - "href": "http://foo.bar.baz", + "href": "https://foo.bar.baz/test?q=hello&id=22&boolean", }, "id": "M00000000", - "range": "(1..19]", + "range": "(1..47]", "type": "link", }, ], - "text": "http://foo.bar.baz", + "text": "https://foo.bar.baz/test?q=hello&id=22&boolean", } `; -exports[`Autolinks +exports[`Autolinks 1`] = ` { "blocks": [ @@ -1682,17 +1682,17 @@ exports[`Autolinks "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..25]", + "range": "(0..26]", "selfClosing": false, "type": "paragraph", }, ], "marks": [], - "text": "", + "text": "", } `; -exports[`Autolinks +exports[`Autolinks 2`] = ` { "blocks": [ @@ -1700,13 +1700,13 @@ exports[`Autolinks "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..25]", + "range": "(0..26]", "selfClosing": false, "type": "paragraph", }, ], "marks": [], - "text": "", + "text": "", } `; @@ -1944,7 +1944,7 @@ exports[`Autolinks foo@bar.example.com } `; -exports[`Autolinks http://example.com +exports[`Autolinks https://example.com 1`] = ` { "blocks": [ @@ -1952,17 +1952,17 @@ exports[`Autolinks http://example.com "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..19]", + "range": "(0..20]", "selfClosing": false, "type": "paragraph", }, ], "marks": [], - "text": "http://example.com", + "text": "https://example.com", } `; -exports[`Autolinks http://example.com +exports[`Autolinks https://example.com 2`] = ` { "blocks": [ @@ -1970,13 +1970,13 @@ exports[`Autolinks http://example.com "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..19]", + "range": "(0..20]", "selfClosing": false, "type": "paragraph", }, ], "marks": [], - "text": "http://example.com", + "text": "https://example.com", } `; @@ -2056,7 +2056,7 @@ exports[`Backslash escapes } `; -exports[`Backslash escapes +exports[`Backslash escapes 1`] = ` { "blocks": [ @@ -2064,7 +2064,7 @@ exports[`Backslash escapes "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..27]", + "range": "(0..28]", "selfClosing": false, "type": "paragraph", }, @@ -2072,18 +2072,18 @@ exports[`Backslash escapes "marks": [ { "attributes": { - "href": "http://example.com?find=%5C*", + "href": "https://example.com?find=%5C*", }, "id": "M00000000", - "range": "(1..27]", + "range": "(1..28]", "type": "link", }, ], - "text": "http://example.com?find=\\*", + "text": "https://example.com?find=\\*", } `; -exports[`Backslash escapes +exports[`Backslash escapes 2`] = ` { "blocks": [ @@ -2091,7 +2091,7 @@ exports[`Backslash escapes "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..27]", + "range": "(0..28]", "selfClosing": false, "type": "paragraph", }, @@ -2099,14 +2099,14 @@ exports[`Backslash escapes "marks": [ { "attributes": { - "href": "http://example.com?find=%5C*", + "href": "https://example.com?find=%5C*", }, "id": "M00000000", - "range": "(1..27]", + "range": "(1..28]", "type": "link", }, ], - "text": "http://example.com?find=\\*", + "text": "https://example.com?find=\\*", } `; @@ -4756,7 +4756,7 @@ exports[`Code spans \` } `; -exports[`Code spans \` +exports[`Code spans \` 1`] = ` { "blocks": [ @@ -4764,7 +4764,7 @@ exports[`Code spans \` "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..21]", + "range": "(0..22]", "selfClosing": false, "type": "paragraph", }, @@ -4772,18 +4772,18 @@ exports[`Code spans \` "marks": [ { "attributes": { - "href": "http://foo.bar.%60baz", + "href": "https://foo.bar.%60baz", }, "id": "M00000000", - "range": "(1..20]", + "range": "(1..21]", "type": "link", }, ], - "text": "http://foo.bar.\`baz\`", + "text": "https://foo.bar.\`baz\`", } `; -exports[`Code spans \` +exports[`Code spans \` 2`] = ` { "blocks": [ @@ -4791,7 +4791,7 @@ exports[`Code spans \` "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..21]", + "range": "(0..22]", "selfClosing": false, "type": "paragraph", }, @@ -4799,14 +4799,14 @@ exports[`Code spans \` "marks": [ { "attributes": { - "href": "http://foo.bar.%60baz", + "href": "https://foo.bar.%60baz", }, "id": "M00000000", - "range": "(1..20]", + "range": "(1..21]", "type": "link", }, ], - "text": "http://foo.bar.\`baz\`", + "text": "https://foo.bar.\`baz\`", } `; @@ -5060,7 +5060,7 @@ exports[`Code spans \`\` } `; -exports[`Code spans \`\` +exports[`Code spans \`\` 1`] = ` { "blocks": [ @@ -5068,7 +5068,7 @@ exports[`Code spans \`\` "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..22]", + "range": "(0..23]", "selfClosing": false, "type": "paragraph", }, @@ -5077,15 +5077,15 @@ exports[`Code spans \`\` { "attributes": {}, "id": "M00000000", - "range": "(1..17]", + "range": "(1..18]", "type": "code_inline", }, ], - "text": "\`", + "text": "\`", } `; -exports[`Code spans \`\` +exports[`Code spans \`\` 2`] = ` { "blocks": [ @@ -5093,7 +5093,7 @@ exports[`Code spans \`\` "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..22]", + "range": "(0..23]", "selfClosing": false, "type": "paragraph", }, @@ -5102,11 +5102,11 @@ exports[`Code spans \`\` { "attributes": {}, "id": "M00000000", - "range": "(1..17]", + "range": "(1..18]", "type": "code_inline", }, ], - "text": "\`", + "text": "\`", } `; @@ -5712,6 +5712,82 @@ exports[`Code spans \` b \` } `; +exports[`Emphasis and strong emphasis *$*alpha. + +*£*bravo. + +*€*charlie. + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..10]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [], + "range": "(10..20]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000002", + "parents": [], + "range": "(20..32]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "*$*alpha.*£*bravo.*€*charlie.", +} +`; + +exports[`Emphasis and strong emphasis *$*alpha. + +*£*bravo. + +*€*charlie. + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..10]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [], + "range": "(10..20]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000002", + "parents": [], + "range": "(20..32]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "*$*alpha.*£*bravo.*€*charlie.", +} +`; + exports[`Emphasis and strong emphasis *(**foo**)* 1`] = ` { @@ -6566,7 +6642,7 @@ Asclepias physocarpa)", } `; -exports[`Emphasis and strong emphasis **a +exports[`Emphasis and strong emphasis **a 1`] = ` { "blocks": [ @@ -6574,7 +6650,7 @@ exports[`Emphasis and strong emphasis **a "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..24]", + "range": "(0..25]", "selfClosing": false, "type": "paragraph", }, @@ -6582,18 +6658,18 @@ exports[`Emphasis and strong emphasis **a "marks": [ { "attributes": { - "href": "http://foo.bar/?q=**", + "href": "https://foo.bar/?q=**", }, "id": "M00000000", - "range": "(4..24]", + "range": "(4..25]", "type": "link", }, ], - "text": "**ahttp://foo.bar/?q=**", + "text": "**ahttps://foo.bar/?q=**", } `; -exports[`Emphasis and strong emphasis **a +exports[`Emphasis and strong emphasis **a 2`] = ` { "blocks": [ @@ -6601,7 +6677,7 @@ exports[`Emphasis and strong emphasis **a "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..24]", + "range": "(0..25]", "selfClosing": false, "type": "paragraph", }, @@ -6609,14 +6685,14 @@ exports[`Emphasis and strong emphasis **a "marks": [ { "attributes": { - "href": "http://foo.bar/?q=**", + "href": "https://foo.bar/?q=**", }, "id": "M00000000", - "range": "(4..24]", + "range": "(4..25]", "type": "link", }, ], - "text": "**ahttp://foo.bar/?q=**", + "text": "**ahttps://foo.bar/?q=**", } `; @@ -9766,7 +9842,7 @@ exports[`Emphasis and strong emphasis ___foo__ } `; -exports[`Emphasis and strong emphasis __a +exports[`Emphasis and strong emphasis __a 1`] = ` { "blocks": [ @@ -9774,7 +9850,7 @@ exports[`Emphasis and strong emphasis __a "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..24]", + "range": "(0..25]", "selfClosing": false, "type": "paragraph", }, @@ -9782,18 +9858,18 @@ exports[`Emphasis and strong emphasis __a "marks": [ { "attributes": { - "href": "http://foo.bar/?q=__", + "href": "https://foo.bar/?q=__", }, "id": "M00000000", - "range": "(4..24]", + "range": "(4..25]", "type": "link", }, ], - "text": "__ahttp://foo.bar/?q=__", + "text": "__ahttps://foo.bar/?q=__", } `; -exports[`Emphasis and strong emphasis __a +exports[`Emphasis and strong emphasis __a 2`] = ` { "blocks": [ @@ -9801,7 +9877,7 @@ exports[`Emphasis and strong emphasis __a "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..24]", + "range": "(0..25]", "selfClosing": false, "type": "paragraph", }, @@ -9809,14 +9885,14 @@ exports[`Emphasis and strong emphasis __a "marks": [ { "attributes": { - "href": "http://foo.bar/?q=__", + "href": "https://foo.bar/?q=__", }, "id": "M00000000", - "range": "(4..24]", + "range": "(4..25]", "type": "link", }, ], - "text": "__ahttp://foo.bar/?q=__", + "text": "__ahttps://foo.bar/?q=__", } `; @@ -24168,7 +24244,7 @@ exports[`Links [foo*]: /url } `; -exports[`Links [foo +exports[`Links [foo 1`] = ` { "blocks": [ @@ -24176,7 +24252,7 @@ exports[`Links [foo "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..38]", + "range": "(0..39]", "selfClosing": false, "type": "paragraph", }, @@ -24184,18 +24260,18 @@ exports[`Links [foo "marks": [ { "attributes": { - "href": "http://example.com/?search=%5D(uri)", + "href": "https://example.com/?search=%5D(uri)", }, "id": "M00000000", - "range": "(5..38]", + "range": "(5..39]", "type": "link", }, ], - "text": "[foohttp://example.com/?search=](uri)", + "text": "[foohttps://example.com/?search=](uri)", } `; -exports[`Links [foo +exports[`Links [foo 2`] = ` { "blocks": [ @@ -24203,7 +24279,7 @@ exports[`Links [foo "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..38]", + "range": "(0..39]", "selfClosing": false, "type": "paragraph", }, @@ -24211,18 +24287,18 @@ exports[`Links [foo "marks": [ { "attributes": { - "href": "http://example.com/?search=%5D(uri)", + "href": "https://example.com/?search=%5D(uri)", }, "id": "M00000000", - "range": "(5..38]", + "range": "(5..39]", "type": "link", }, ], - "text": "[foohttp://example.com/?search=](uri)", + "text": "[foohttps://example.com/?search=](uri)", } `; -exports[`Links [foo +exports[`Links [foo [ref]: /uri 1`] = ` @@ -24232,7 +24308,7 @@ exports[`Links [foo "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..38]", + "range": "(0..39]", "selfClosing": false, "type": "paragraph", }, @@ -24240,18 +24316,18 @@ exports[`Links [foo "marks": [ { "attributes": { - "href": "http://example.com/?search=%5D%5Bref%5D", + "href": "https://example.com/?search=%5D%5Bref%5D", }, "id": "M00000000", - "range": "(5..38]", + "range": "(5..39]", "type": "link", }, ], - "text": "[foohttp://example.com/?search=][ref]", + "text": "[foohttps://example.com/?search=][ref]", } `; -exports[`Links [foo +exports[`Links [foo [ref]: /uri 2`] = ` @@ -24261,7 +24337,7 @@ exports[`Links [foo "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..38]", + "range": "(0..39]", "selfClosing": false, "type": "paragraph", }, @@ -24269,14 +24345,14 @@ exports[`Links [foo "marks": [ { "attributes": { - "href": "http://example.com/?search=%5D%5Bref%5D", + "href": "https://example.com/?search=%5D%5Bref%5D", }, "id": "M00000000", - "range": "(5..38]", + "range": "(5..39]", "type": "link", }, ], - "text": "[foohttp://example.com/?search=][ref]", + "text": "[foohttps://example.com/?search=][ref]", } `; @@ -26178,9 +26254,9 @@ exports[`Links [link]("title") exports[`Links [link](#fragment) -[link](http://example.com#fragment) +[link](https://example.com#fragment) -[link](http://example.com?foo=3#frag) +[link](https://example.com?foo=3#frag) 1`] = ` { "blocks": [ @@ -26220,7 +26296,7 @@ exports[`Links [link](#fragment) }, { "attributes": { - "href": "http://example.com#fragment", + "href": "https://example.com#fragment", }, "id": "M00000001", "range": "(6..10]", @@ -26228,7 +26304,7 @@ exports[`Links [link](#fragment) }, { "attributes": { - "href": "http://example.com?foo=3#frag", + "href": "https://example.com?foo=3#frag", }, "id": "M00000002", "range": "(11..15]", @@ -26241,9 +26317,9 @@ exports[`Links [link](#fragment) exports[`Links [link](#fragment) -[link](http://example.com#fragment) +[link](https://example.com#fragment) -[link](http://example.com?foo=3#frag) +[link](https://example.com?foo=3#frag) 2`] = ` { "blocks": [ @@ -26283,7 +26359,7 @@ exports[`Links [link](#fragment) }, { "attributes": { - "href": "http://example.com#fragment", + "href": "https://example.com#fragment", }, "id": "M00000001", "range": "(6..10]", @@ -26291,7 +26367,7 @@ exports[`Links [link](#fragment) }, { "attributes": { - "href": "http://example.com?foo=3#frag", + "href": "https://example.com?foo=3#frag", }, "id": "M00000002", "range": "(11..15]", @@ -39704,44 +39780,8 @@ exports[`Raw HTML foo &<]]> } `; -exports[`Raw HTML foo - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..42]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "foo ", -} -`; - -exports[`Raw HTML foo - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..42]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "foo ", -} -`; - -exports[`Raw HTML foo +exports[`Raw HTML foo 1`] = ` { "blocks": [ @@ -39749,7 +39789,7 @@ comment - with hyphen --> "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..45]", + "range": "(0..49]", "selfClosing": false, "type": "paragraph", }, @@ -39758,17 +39798,17 @@ comment - with hyphen --> { "attributes": {}, "id": "M00000000", - "range": "(5..45]", + "range": "(5..49]", "type": "html_inline", }, ], - "text": "foo ", + "text": "foo ", } `; -exports[`Raw HTML foo +exports[`Raw HTML foo 2`] = ` { "blocks": [ @@ -39776,7 +39816,7 @@ comment - with hyphen --> "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..45]", + "range": "(0..49]", "selfClosing": false, "type": "paragraph", }, @@ -39785,18 +39825,18 @@ comment - with hyphen --> { "attributes": {}, "id": "M00000000", - "range": "(5..45]", + "range": "(5..49]", "type": "html_inline", }, ], - "text": "foo ", + "text": "foo ", } `; exports[`Raw HTML foo foo --> -foo +foo foo --> 1`] = ` { "blocks": [ @@ -39812,19 +39852,32 @@ foo "attributes": {}, "id": "B00000001", "parents": [], - "range": "(18..35]", + "range": "(18..37]", "selfClosing": false, "type": "paragraph", }, ], - "marks": [], - "text": "foo foo -->foo ", + "marks": [ + { + "attributes": {}, + "id": "M00000000", + "range": "(5..10]", + "type": "html_inline", + }, + { + "attributes": {}, + "id": "M00000001", + "range": "(23..29]", + "type": "html_inline", + }, + ], + "text": "foo foo -->foo foo -->", } `; exports[`Raw HTML foo foo --> -foo +foo foo --> 2`] = ` { "blocks": [ @@ -39840,13 +39893,26 @@ foo "attributes": {}, "id": "B00000001", "parents": [], - "range": "(18..35]", + "range": "(18..37]", "selfClosing": false, "type": "paragraph", }, ], - "marks": [], - "text": "foo foo -->foo ", + "marks": [ + { + "attributes": {}, + "id": "M00000000", + "range": "(5..10]", + "type": "html_inline", + }, + { + "attributes": {}, + "id": "M00000001", + "range": "(23..29]", + "type": "html_inline", + }, + ], + "text": "foo foo -->foo foo -->", } `; From e0275c68926cec3b414a2ec598065122f0c3f738 Mon Sep 17 00:00:00 2001 From: a-rena Date: Wed, 3 Jul 2024 12:15:00 +0530 Subject: [PATCH 07/12] fix: revertin g changes --- packages/@atjson/renderer-commonmark/src/index.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/@atjson/renderer-commonmark/src/index.ts b/packages/@atjson/renderer-commonmark/src/index.ts index 3215a860a..dc07b095a 100644 --- a/packages/@atjson/renderer-commonmark/src/index.ts +++ b/packages/@atjson/renderer-commonmark/src/index.ts @@ -253,8 +253,8 @@ export default class CommonmarkRenderer extends Renderer { } *root(): Iterator { - let rawText = (yield).join(""); - return rawText.replace(/(\\\n(\n*))+$/gs, "$2"); + let rawText = yield; + return rawText.join(""); } /** @@ -474,11 +474,6 @@ export default class CommonmarkRenderer extends Renderer { return ""; } - if (context.parent == null && context.next == null) { - return ""; - } - - // MD code and html blocks cannot contain line breaks // https://spec.commonmark.org/0.29/#example-637 if (context.parent?.type === "code" || context.parent?.type === "html") { return "\n"; From 57716cb34e5e70993fa12e69d6e9e2522c28a0ce Mon Sep 17 00:00:00 2001 From: a-rena Date: Wed, 3 Jul 2024 13:34:21 +0530 Subject: [PATCH 08/12] fix: adding changes --- .../@atjson/renderer-commonmark/src/index.ts | 9 +- .../commonmark-spec.test.ts.snap | 1018 ++++++++++++++++- 2 files changed, 976 insertions(+), 51 deletions(-) diff --git a/packages/@atjson/renderer-commonmark/src/index.ts b/packages/@atjson/renderer-commonmark/src/index.ts index dc07b095a..3215a860a 100644 --- a/packages/@atjson/renderer-commonmark/src/index.ts +++ b/packages/@atjson/renderer-commonmark/src/index.ts @@ -253,8 +253,8 @@ export default class CommonmarkRenderer extends Renderer { } *root(): Iterator { - let rawText = yield; - return rawText.join(""); + let rawText = (yield).join(""); + return rawText.replace(/(\\\n(\n*))+$/gs, "$2"); } /** @@ -474,6 +474,11 @@ export default class CommonmarkRenderer extends Renderer { return ""; } + if (context.parent == null && context.next == null) { + return ""; + } + + // MD code and html blocks cannot contain line breaks // https://spec.commonmark.org/0.29/#example-637 if (context.parent?.type === "code" || context.parent?.type === "html") { return "\n"; diff --git a/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap b/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap index baa398c80..ce238b364 100644 --- a/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap +++ b/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap @@ -1098,6 +1098,42 @@ exports[`ATX headings foo } `; +exports[`Autolinks < http://foo.bar > + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..19]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "< http://foo.bar >", +} +`; + +exports[`Autolinks < http://foo.bar > + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..19]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "< http://foo.bar >", +} +`; + exports[`Autolinks < https://foo.bar > 1`] = ` { @@ -1458,6 +1494,168 @@ exports[`Autolinks } `; +exports[`Autolinks + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..11]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://../", + }, + "id": "M00000000", + "range": "(1..11]", + "type": "link", + }, + ], + "text": "http://../", +} +`; + +exports[`Autolinks + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..11]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://../", + }, + "id": "M00000000", + "range": "(1..11]", + "type": "link", + }, + ], + "text": "http://../", +} +`; + +exports[`Autolinks + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..23]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://example.com/%5C%5B%5C", + }, + "id": "M00000000", + "range": "(1..23]", + "type": "link", + }, + ], + "text": "http://example.com/\\[\\", +} +`; + +exports[`Autolinks + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..23]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://example.com/%5C%5B%5C", + }, + "id": "M00000000", + "range": "(1..23]", + "type": "link", + }, + ], + "text": "http://example.com/\\[\\", +} +`; + +exports[`Autolinks + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..46]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://foo.bar.baz/test?q=hello&id=22&boolean", + }, + "id": "M00000000", + "range": "(1..46]", + "type": "link", + }, + ], + "text": "http://foo.bar.baz/test?q=hello&id=22&boolean", +} +`; + +exports[`Autolinks + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..46]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://foo.bar.baz/test?q=hello&id=22&boolean", + }, + "id": "M00000000", + "range": "(1..46]", + "type": "link", + }, + ], + "text": "http://foo.bar.baz/test?q=hello&id=22&boolean", +} +`; + exports[`Autolinks 1`] = ` { @@ -1512,6 +1710,42 @@ exports[`Autolinks } `; +exports[`Autolinks + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..25]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "", +} +`; + +exports[`Autolinks + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..25]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "", +} +`; + exports[`Autolinks 1`] = ` { @@ -1944,6 +2178,42 @@ exports[`Autolinks foo@bar.example.com } `; +exports[`Autolinks http://example.com + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..19]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "http://example.com", +} +`; + +exports[`Autolinks http://example.com + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..19]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "http://example.com", +} +`; + exports[`Autolinks https://example.com 1`] = ` { @@ -2056,7 +2326,7 @@ exports[`Backslash escapes } `; -exports[`Backslash escapes +exports[`Backslash escapes 1`] = ` { "blocks": [ @@ -2064,7 +2334,7 @@ exports[`Backslash escapes "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..28]", + "range": "(0..27]", "selfClosing": false, "type": "paragraph", }, @@ -2072,18 +2342,18 @@ exports[`Backslash escapes "marks": [ { "attributes": { - "href": "https://example.com?find=%5C*", + "href": "http://example.com?find=%5C*", }, "id": "M00000000", - "range": "(1..28]", + "range": "(1..27]", "type": "link", }, ], - "text": "https://example.com?find=\\*", + "text": "http://example.com?find=\\*", } `; -exports[`Backslash escapes +exports[`Backslash escapes 2`] = ` { "blocks": [ @@ -2091,7 +2361,7 @@ exports[`Backslash escapes "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..28]", + "range": "(0..27]", "selfClosing": false, "type": "paragraph", }, @@ -2099,20 +2369,18 @@ exports[`Backslash escapes "marks": [ { "attributes": { - "href": "https://example.com?find=%5C*", + "href": "http://example.com?find=%5C*", }, "id": "M00000000", - "range": "(1..28]", + "range": "(1..27]", "type": "link", }, ], - "text": "https://example.com?find=\\*", + "text": "http://example.com?find=\\*", } `; -exports[`Backslash escapes [foo] - -[foo]: /bar\\* "ti\\*tle" +exports[`Backslash escapes 1`] = ` { "blocks": [ @@ -2120,7 +2388,7 @@ exports[`Backslash escapes [foo] "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..4]", + "range": "(0..28]", "selfClosing": false, "type": "paragraph", }, @@ -2128,21 +2396,18 @@ exports[`Backslash escapes [foo] "marks": [ { "attributes": { - "href": "/bar*", - "title": "ti*tle", + "href": "https://example.com?find=%5C*", }, "id": "M00000000", - "range": "(1..4]", + "range": "(1..28]", "type": "link", }, ], - "text": "foo", + "text": "https://example.com?find=\\*", } `; -exports[`Backslash escapes [foo] - -[foo]: /bar\\* "ti\\*tle" +exports[`Backslash escapes 2`] = ` { "blocks": [ @@ -2150,7 +2415,7 @@ exports[`Backslash escapes [foo] "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..4]", + "range": "(0..28]", "selfClosing": false, "type": "paragraph", }, @@ -2158,19 +2423,78 @@ exports[`Backslash escapes [foo] "marks": [ { "attributes": { - "href": "/bar*", - "title": "ti*tle", + "href": "https://example.com?find=%5C*", }, "id": "M00000000", - "range": "(1..4]", + "range": "(1..28]", "type": "link", }, ], - "text": "foo", + "text": "https://example.com?find=\\*", } `; -exports[`Backslash escapes [foo](/bar\\* "ti\\*tle") +exports[`Backslash escapes [foo] + +[foo]: /bar\\* "ti\\*tle" + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..4]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "/bar*", + "title": "ti*tle", + }, + "id": "M00000000", + "range": "(1..4]", + "type": "link", + }, + ], + "text": "foo", +} +`; + +exports[`Backslash escapes [foo] + +[foo]: /bar\\* "ti\\*tle" + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..4]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "/bar*", + "title": "ti*tle", + }, + "id": "M00000000", + "range": "(1..4]", + "type": "link", + }, + ], + "text": "foo", +} +`; + +exports[`Backslash escapes [foo](/bar\\* "ti\\*tle") 1`] = ` { "blocks": [ @@ -4756,6 +5080,60 @@ exports[`Code spans \` } `; +exports[`Code spans \` + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..21]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://foo.bar.%60baz", + }, + "id": "M00000000", + "range": "(1..20]", + "type": "link", + }, + ], + "text": "http://foo.bar.\`baz\`", +} +`; + +exports[`Code spans \` + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..21]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://foo.bar.%60baz", + }, + "id": "M00000000", + "range": "(1..20]", + "type": "link", + }, + ], + "text": "http://foo.bar.\`baz\`", +} +`; + exports[`Code spans \` 1`] = ` { @@ -5060,6 +5438,56 @@ exports[`Code spans \`\` } `; +exports[`Code spans \`\` + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..22]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": {}, + "id": "M00000000", + "range": "(1..17]", + "type": "code_inline", + }, + ], + "text": "\`", +} +`; + +exports[`Code spans \`\` + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..22]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": {}, + "id": "M00000000", + "range": "(1..17]", + "type": "code_inline", + }, + ], + "text": "\`", +} +`; + exports[`Code spans \`\` 1`] = ` { @@ -6642,6 +7070,60 @@ Asclepias physocarpa)", } `; +exports[`Emphasis and strong emphasis **a + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..24]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://foo.bar/?q=**", + }, + "id": "M00000000", + "range": "(4..24]", + "type": "link", + }, + ], + "text": "**ahttp://foo.bar/?q=**", +} +`; + +exports[`Emphasis and strong emphasis **a + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..24]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://foo.bar/?q=**", + }, + "id": "M00000000", + "range": "(4..24]", + "type": "link", + }, + ], + "text": "**ahttp://foo.bar/?q=**", +} +`; + exports[`Emphasis and strong emphasis **a 1`] = ` { @@ -9842,7 +10324,7 @@ exports[`Emphasis and strong emphasis ___foo__ } `; -exports[`Emphasis and strong emphasis __a +exports[`Emphasis and strong emphasis __a 1`] = ` { "blocks": [ @@ -9850,7 +10332,7 @@ exports[`Emphasis and strong emphasis __a "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..25]", + "range": "(0..24]", "selfClosing": false, "type": "paragraph", }, @@ -9858,18 +10340,18 @@ exports[`Emphasis and strong emphasis __a "marks": [ { "attributes": { - "href": "https://foo.bar/?q=__", + "href": "http://foo.bar/?q=__", }, "id": "M00000000", - "range": "(4..25]", + "range": "(4..24]", "type": "link", }, ], - "text": "__ahttps://foo.bar/?q=__", + "text": "__ahttp://foo.bar/?q=__", } `; -exports[`Emphasis and strong emphasis __a +exports[`Emphasis and strong emphasis __a 2`] = ` { "blocks": [ @@ -9877,7 +10359,7 @@ exports[`Emphasis and strong emphasis __a "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..25]", + "range": "(0..24]", "selfClosing": false, "type": "paragraph", }, @@ -9885,18 +10367,18 @@ exports[`Emphasis and strong emphasis __a "marks": [ { "attributes": { - "href": "https://foo.bar/?q=__", + "href": "http://foo.bar/?q=__", }, "id": "M00000000", - "range": "(4..25]", + "range": "(4..24]", "type": "link", }, ], - "text": "__ahttps://foo.bar/?q=__", + "text": "__ahttp://foo.bar/?q=__", } `; -exports[`Emphasis and strong emphasis __foo __bar__ baz__ +exports[`Emphasis and strong emphasis __a 1`] = ` { "blocks": [ @@ -9904,31 +10386,54 @@ exports[`Emphasis and strong emphasis __foo __bar__ baz__ "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..12]", + "range": "(0..25]", "selfClosing": false, "type": "paragraph", }, ], "marks": [ { - "attributes": {}, + "attributes": { + "href": "https://foo.bar/?q=__", + }, "id": "M00000000", - "range": "(1..12]", - "type": "strong", + "range": "(4..25]", + "type": "link", }, + ], + "text": "__ahttps://foo.bar/?q=__", +} +`; + +exports[`Emphasis and strong emphasis __a + 2`] = ` +{ + "blocks": [ { "attributes": {}, - "id": "M00000001", - "range": "(5..8]", - "type": "strong", + "id": "B00000000", + "parents": [], + "range": "(0..25]", + "selfClosing": false, + "type": "paragraph", }, ], - "text": "foo bar baz", + "marks": [ + { + "attributes": { + "href": "https://foo.bar/?q=__", + }, + "id": "M00000000", + "range": "(4..25]", + "type": "link", + }, + ], + "text": "__ahttps://foo.bar/?q=__", } `; exports[`Emphasis and strong emphasis __foo __bar__ baz__ - 2`] = ` + 1`] = ` { "blocks": [ { @@ -9958,8 +10463,39 @@ exports[`Emphasis and strong emphasis __foo __bar__ baz__ } `; -exports[`Emphasis and strong emphasis __foo _bar_ baz__ - 1`] = ` +exports[`Emphasis and strong emphasis __foo __bar__ baz__ + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..12]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": {}, + "id": "M00000000", + "range": "(1..12]", + "type": "strong", + }, + { + "attributes": {}, + "id": "M00000001", + "range": "(5..8]", + "type": "strong", + }, + ], + "text": "foo bar baz", +} +`; + +exports[`Emphasis and strong emphasis __foo _bar_ baz__ + 1`] = ` { "blocks": [ { @@ -24244,6 +24780,118 @@ exports[`Links [foo*]: /url } `; +exports[`Links [foo + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..38]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://example.com/?search=%5D(uri)", + }, + "id": "M00000000", + "range": "(5..38]", + "type": "link", + }, + ], + "text": "[foohttp://example.com/?search=](uri)", +} +`; + +exports[`Links [foo + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..38]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://example.com/?search=%5D(uri)", + }, + "id": "M00000000", + "range": "(5..38]", + "type": "link", + }, + ], + "text": "[foohttp://example.com/?search=](uri)", +} +`; + +exports[`Links [foo + +[ref]: /uri + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..38]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://example.com/?search=%5D%5Bref%5D", + }, + "id": "M00000000", + "range": "(5..38]", + "type": "link", + }, + ], + "text": "[foohttp://example.com/?search=][ref]", +} +`; + +exports[`Links [foo + +[ref]: /uri + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..38]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "http://example.com/?search=%5D%5Bref%5D", + }, + "id": "M00000000", + "range": "(5..38]", + "type": "link", + }, + ], + "text": "[foohttp://example.com/?search=][ref]", +} +`; + exports[`Links [foo 1`] = ` { @@ -26254,6 +26902,132 @@ exports[`Links [link]("title") exports[`Links [link](#fragment) +[link](http://example.com#fragment) + +[link](http://example.com?foo=3#frag) + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..5]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [], + "range": "(5..10]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000002", + "parents": [], + "range": "(10..15]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "#fragment", + }, + "id": "M00000000", + "range": "(1..5]", + "type": "link", + }, + { + "attributes": { + "href": "http://example.com#fragment", + }, + "id": "M00000001", + "range": "(6..10]", + "type": "link", + }, + { + "attributes": { + "href": "http://example.com?foo=3#frag", + }, + "id": "M00000002", + "range": "(11..15]", + "type": "link", + }, + ], + "text": "linklinklink", +} +`; + +exports[`Links [link](#fragment) + +[link](http://example.com#fragment) + +[link](http://example.com?foo=3#frag) + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..5]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [], + "range": "(5..10]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000002", + "parents": [], + "range": "(10..15]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": { + "href": "#fragment", + }, + "id": "M00000000", + "range": "(1..5]", + "type": "link", + }, + { + "attributes": { + "href": "http://example.com#fragment", + }, + "id": "M00000001", + "range": "(6..10]", + "type": "link", + }, + { + "attributes": { + "href": "http://example.com?foo=3#frag", + }, + "id": "M00000002", + "range": "(11..15]", + "type": "link", + }, + ], + "text": "linklinklink", +} +`; + +exports[`Links [link](#fragment) + [link](https://example.com#fragment) [link](https://example.com?foo=3#frag) @@ -39780,6 +40554,96 @@ exports[`Raw HTML foo &<]]> } `; +exports[`Raw HTML foo + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..42]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "foo ", +} +`; + +exports[`Raw HTML foo + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..42]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "foo ", +} +`; + +exports[`Raw HTML foo + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..45]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": {}, + "id": "M00000000", + "range": "(5..45]", + "type": "html_inline", + }, + ], + "text": "foo ", +} +`; + +exports[`Raw HTML foo + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..45]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [ + { + "attributes": {}, + "id": "M00000000", + "range": "(5..45]", + "type": "html_inline", + }, + ], + "text": "foo ", +} +`; + exports[`Raw HTML foo 1`] = ` @@ -39836,6 +40700,62 @@ comment - with hyphens -->", exports[`Raw HTML foo foo --> +foo + 1`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..18]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [], + "range": "(18..35]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "foo foo -->foo ", +} +`; + +exports[`Raw HTML foo foo --> + +foo + 2`] = ` +{ + "blocks": [ + { + "attributes": {}, + "id": "B00000000", + "parents": [], + "range": "(0..18]", + "selfClosing": false, + "type": "paragraph", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [], + "range": "(18..35]", + "selfClosing": false, + "type": "paragraph", + }, + ], + "marks": [], + "text": "foo foo -->foo ", +} +`; + +exports[`Raw HTML foo foo --> + foo foo --> 1`] = ` { From 373938c24fa2370029b7698b94bdb12344c246de Mon Sep 17 00:00:00 2001 From: Bach Bui Date: Wed, 3 Jul 2024 12:25:02 -0400 Subject: [PATCH 09/12] chore: revert changes to commonmark spec snapshot --- .../commonmark-spec.test.ts.snap | 1018 +---------------- 1 file changed, 49 insertions(+), 969 deletions(-) diff --git a/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap b/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap index ce238b364..baa398c80 100644 --- a/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap +++ b/packages/@atjson/renderer-commonmark/test/__snapshots__/commonmark-spec.test.ts.snap @@ -1098,42 +1098,6 @@ exports[`ATX headings foo } `; -exports[`Autolinks < http://foo.bar > - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..19]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "< http://foo.bar >", -} -`; - -exports[`Autolinks < http://foo.bar > - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..19]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "< http://foo.bar >", -} -`; - exports[`Autolinks < https://foo.bar > 1`] = ` { @@ -1494,168 +1458,6 @@ exports[`Autolinks } `; -exports[`Autolinks - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..11]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://../", - }, - "id": "M00000000", - "range": "(1..11]", - "type": "link", - }, - ], - "text": "http://../", -} -`; - -exports[`Autolinks - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..11]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://../", - }, - "id": "M00000000", - "range": "(1..11]", - "type": "link", - }, - ], - "text": "http://../", -} -`; - -exports[`Autolinks - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..23]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://example.com/%5C%5B%5C", - }, - "id": "M00000000", - "range": "(1..23]", - "type": "link", - }, - ], - "text": "http://example.com/\\[\\", -} -`; - -exports[`Autolinks - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..23]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://example.com/%5C%5B%5C", - }, - "id": "M00000000", - "range": "(1..23]", - "type": "link", - }, - ], - "text": "http://example.com/\\[\\", -} -`; - -exports[`Autolinks - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..46]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://foo.bar.baz/test?q=hello&id=22&boolean", - }, - "id": "M00000000", - "range": "(1..46]", - "type": "link", - }, - ], - "text": "http://foo.bar.baz/test?q=hello&id=22&boolean", -} -`; - -exports[`Autolinks - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..46]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://foo.bar.baz/test?q=hello&id=22&boolean", - }, - "id": "M00000000", - "range": "(1..46]", - "type": "link", - }, - ], - "text": "http://foo.bar.baz/test?q=hello&id=22&boolean", -} -`; - exports[`Autolinks 1`] = ` { @@ -1710,42 +1512,6 @@ exports[`Autolinks } `; -exports[`Autolinks - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..25]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "", -} -`; - -exports[`Autolinks - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..25]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "", -} -`; - exports[`Autolinks 1`] = ` { @@ -2178,42 +1944,6 @@ exports[`Autolinks foo@bar.example.com } `; -exports[`Autolinks http://example.com - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..19]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "http://example.com", -} -`; - -exports[`Autolinks http://example.com - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..19]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "http://example.com", -} -`; - exports[`Autolinks https://example.com 1`] = ` { @@ -2326,7 +2056,7 @@ exports[`Backslash escapes } `; -exports[`Backslash escapes +exports[`Backslash escapes 1`] = ` { "blocks": [ @@ -2334,7 +2064,7 @@ exports[`Backslash escapes "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..27]", + "range": "(0..28]", "selfClosing": false, "type": "paragraph", }, @@ -2342,18 +2072,18 @@ exports[`Backslash escapes "marks": [ { "attributes": { - "href": "http://example.com?find=%5C*", + "href": "https://example.com?find=%5C*", }, "id": "M00000000", - "range": "(1..27]", + "range": "(1..28]", "type": "link", }, ], - "text": "http://example.com?find=\\*", + "text": "https://example.com?find=\\*", } `; -exports[`Backslash escapes +exports[`Backslash escapes 2`] = ` { "blocks": [ @@ -2361,7 +2091,7 @@ exports[`Backslash escapes "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..27]", + "range": "(0..28]", "selfClosing": false, "type": "paragraph", }, @@ -2369,18 +2099,20 @@ exports[`Backslash escapes "marks": [ { "attributes": { - "href": "http://example.com?find=%5C*", + "href": "https://example.com?find=%5C*", }, "id": "M00000000", - "range": "(1..27]", + "range": "(1..28]", "type": "link", }, ], - "text": "http://example.com?find=\\*", + "text": "https://example.com?find=\\*", } `; -exports[`Backslash escapes +exports[`Backslash escapes [foo] + +[foo]: /bar\\* "ti\\*tle" 1`] = ` { "blocks": [ @@ -2388,7 +2120,7 @@ exports[`Backslash escapes "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..28]", + "range": "(0..4]", "selfClosing": false, "type": "paragraph", }, @@ -2396,18 +2128,21 @@ exports[`Backslash escapes "marks": [ { "attributes": { - "href": "https://example.com?find=%5C*", + "href": "/bar*", + "title": "ti*tle", }, "id": "M00000000", - "range": "(1..28]", + "range": "(1..4]", "type": "link", }, ], - "text": "https://example.com?find=\\*", + "text": "foo", } `; -exports[`Backslash escapes +exports[`Backslash escapes [foo] + +[foo]: /bar\\* "ti\\*tle" 2`] = ` { "blocks": [ @@ -2415,7 +2150,7 @@ exports[`Backslash escapes "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..28]", + "range": "(0..4]", "selfClosing": false, "type": "paragraph", }, @@ -2423,78 +2158,19 @@ exports[`Backslash escapes "marks": [ { "attributes": { - "href": "https://example.com?find=%5C*", + "href": "/bar*", + "title": "ti*tle", }, "id": "M00000000", - "range": "(1..28]", + "range": "(1..4]", "type": "link", }, ], - "text": "https://example.com?find=\\*", + "text": "foo", } `; -exports[`Backslash escapes [foo] - -[foo]: /bar\\* "ti\\*tle" - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..4]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "/bar*", - "title": "ti*tle", - }, - "id": "M00000000", - "range": "(1..4]", - "type": "link", - }, - ], - "text": "foo", -} -`; - -exports[`Backslash escapes [foo] - -[foo]: /bar\\* "ti\\*tle" - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..4]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "/bar*", - "title": "ti*tle", - }, - "id": "M00000000", - "range": "(1..4]", - "type": "link", - }, - ], - "text": "foo", -} -`; - -exports[`Backslash escapes [foo](/bar\\* "ti\\*tle") +exports[`Backslash escapes [foo](/bar\\* "ti\\*tle") 1`] = ` { "blocks": [ @@ -5080,60 +4756,6 @@ exports[`Code spans \` } `; -exports[`Code spans \` - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..21]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://foo.bar.%60baz", - }, - "id": "M00000000", - "range": "(1..20]", - "type": "link", - }, - ], - "text": "http://foo.bar.\`baz\`", -} -`; - -exports[`Code spans \` - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..21]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://foo.bar.%60baz", - }, - "id": "M00000000", - "range": "(1..20]", - "type": "link", - }, - ], - "text": "http://foo.bar.\`baz\`", -} -`; - exports[`Code spans \` 1`] = ` { @@ -5438,56 +5060,6 @@ exports[`Code spans \`\` } `; -exports[`Code spans \`\` - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..22]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": {}, - "id": "M00000000", - "range": "(1..17]", - "type": "code_inline", - }, - ], - "text": "\`", -} -`; - -exports[`Code spans \`\` - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..22]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": {}, - "id": "M00000000", - "range": "(1..17]", - "type": "code_inline", - }, - ], - "text": "\`", -} -`; - exports[`Code spans \`\` 1`] = ` { @@ -7070,60 +6642,6 @@ Asclepias physocarpa)", } `; -exports[`Emphasis and strong emphasis **a - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..24]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://foo.bar/?q=**", - }, - "id": "M00000000", - "range": "(4..24]", - "type": "link", - }, - ], - "text": "**ahttp://foo.bar/?q=**", -} -`; - -exports[`Emphasis and strong emphasis **a - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..24]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://foo.bar/?q=**", - }, - "id": "M00000000", - "range": "(4..24]", - "type": "link", - }, - ], - "text": "**ahttp://foo.bar/?q=**", -} -`; - exports[`Emphasis and strong emphasis **a 1`] = ` { @@ -10324,7 +9842,7 @@ exports[`Emphasis and strong emphasis ___foo__ } `; -exports[`Emphasis and strong emphasis __a +exports[`Emphasis and strong emphasis __a 1`] = ` { "blocks": [ @@ -10332,34 +9850,7 @@ exports[`Emphasis and strong emphasis __a "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..24]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://foo.bar/?q=__", - }, - "id": "M00000000", - "range": "(4..24]", - "type": "link", - }, - ], - "text": "__ahttp://foo.bar/?q=__", -} -`; - -exports[`Emphasis and strong emphasis __a - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..24]", + "range": "(0..25]", "selfClosing": false, "type": "paragraph", }, @@ -10367,19 +9858,19 @@ exports[`Emphasis and strong emphasis __a "marks": [ { "attributes": { - "href": "http://foo.bar/?q=__", + "href": "https://foo.bar/?q=__", }, "id": "M00000000", - "range": "(4..24]", + "range": "(4..25]", "type": "link", }, ], - "text": "__ahttp://foo.bar/?q=__", + "text": "__ahttps://foo.bar/?q=__", } `; exports[`Emphasis and strong emphasis __a - 1`] = ` + 2`] = ` { "blocks": [ { @@ -10405,35 +9896,39 @@ exports[`Emphasis and strong emphasis __a } `; -exports[`Emphasis and strong emphasis __a - 2`] = ` +exports[`Emphasis and strong emphasis __foo __bar__ baz__ + 1`] = ` { "blocks": [ { "attributes": {}, "id": "B00000000", "parents": [], - "range": "(0..25]", + "range": "(0..12]", "selfClosing": false, "type": "paragraph", }, ], "marks": [ { - "attributes": { - "href": "https://foo.bar/?q=__", - }, + "attributes": {}, "id": "M00000000", - "range": "(4..25]", - "type": "link", + "range": "(1..12]", + "type": "strong", + }, + { + "attributes": {}, + "id": "M00000001", + "range": "(5..8]", + "type": "strong", }, ], - "text": "__ahttps://foo.bar/?q=__", + "text": "foo bar baz", } `; exports[`Emphasis and strong emphasis __foo __bar__ baz__ - 1`] = ` + 2`] = ` { "blocks": [ { @@ -10463,39 +9958,8 @@ exports[`Emphasis and strong emphasis __foo __bar__ baz__ } `; -exports[`Emphasis and strong emphasis __foo __bar__ baz__ - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..12]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": {}, - "id": "M00000000", - "range": "(1..12]", - "type": "strong", - }, - { - "attributes": {}, - "id": "M00000001", - "range": "(5..8]", - "type": "strong", - }, - ], - "text": "foo bar baz", -} -`; - -exports[`Emphasis and strong emphasis __foo _bar_ baz__ - 1`] = ` +exports[`Emphasis and strong emphasis __foo _bar_ baz__ + 1`] = ` { "blocks": [ { @@ -24780,118 +24244,6 @@ exports[`Links [foo*]: /url } `; -exports[`Links [foo - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..38]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://example.com/?search=%5D(uri)", - }, - "id": "M00000000", - "range": "(5..38]", - "type": "link", - }, - ], - "text": "[foohttp://example.com/?search=](uri)", -} -`; - -exports[`Links [foo - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..38]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://example.com/?search=%5D(uri)", - }, - "id": "M00000000", - "range": "(5..38]", - "type": "link", - }, - ], - "text": "[foohttp://example.com/?search=](uri)", -} -`; - -exports[`Links [foo - -[ref]: /uri - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..38]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://example.com/?search=%5D%5Bref%5D", - }, - "id": "M00000000", - "range": "(5..38]", - "type": "link", - }, - ], - "text": "[foohttp://example.com/?search=][ref]", -} -`; - -exports[`Links [foo - -[ref]: /uri - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..38]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "http://example.com/?search=%5D%5Bref%5D", - }, - "id": "M00000000", - "range": "(5..38]", - "type": "link", - }, - ], - "text": "[foohttp://example.com/?search=][ref]", -} -`; - exports[`Links [foo 1`] = ` { @@ -26902,132 +26254,6 @@ exports[`Links [link]("title") exports[`Links [link](#fragment) -[link](http://example.com#fragment) - -[link](http://example.com?foo=3#frag) - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..5]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000001", - "parents": [], - "range": "(5..10]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000002", - "parents": [], - "range": "(10..15]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "#fragment", - }, - "id": "M00000000", - "range": "(1..5]", - "type": "link", - }, - { - "attributes": { - "href": "http://example.com#fragment", - }, - "id": "M00000001", - "range": "(6..10]", - "type": "link", - }, - { - "attributes": { - "href": "http://example.com?foo=3#frag", - }, - "id": "M00000002", - "range": "(11..15]", - "type": "link", - }, - ], - "text": "linklinklink", -} -`; - -exports[`Links [link](#fragment) - -[link](http://example.com#fragment) - -[link](http://example.com?foo=3#frag) - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..5]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000001", - "parents": [], - "range": "(5..10]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000002", - "parents": [], - "range": "(10..15]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": { - "href": "#fragment", - }, - "id": "M00000000", - "range": "(1..5]", - "type": "link", - }, - { - "attributes": { - "href": "http://example.com#fragment", - }, - "id": "M00000001", - "range": "(6..10]", - "type": "link", - }, - { - "attributes": { - "href": "http://example.com?foo=3#frag", - }, - "id": "M00000002", - "range": "(11..15]", - "type": "link", - }, - ], - "text": "linklinklink", -} -`; - -exports[`Links [link](#fragment) - [link](https://example.com#fragment) [link](https://example.com?foo=3#frag) @@ -40554,96 +39780,6 @@ exports[`Raw HTML foo &<]]> } `; -exports[`Raw HTML foo - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..42]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "foo ", -} -`; - -exports[`Raw HTML foo - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..42]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "foo ", -} -`; - -exports[`Raw HTML foo - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..45]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": {}, - "id": "M00000000", - "range": "(5..45]", - "type": "html_inline", - }, - ], - "text": "foo ", -} -`; - -exports[`Raw HTML foo - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..45]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [ - { - "attributes": {}, - "id": "M00000000", - "range": "(5..45]", - "type": "html_inline", - }, - ], - "text": "foo ", -} -`; - exports[`Raw HTML foo 1`] = ` @@ -40700,62 +39836,6 @@ comment - with hyphens -->", exports[`Raw HTML foo foo --> -foo - 1`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..18]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000001", - "parents": [], - "range": "(18..35]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "foo foo -->foo ", -} -`; - -exports[`Raw HTML foo foo --> - -foo - 2`] = ` -{ - "blocks": [ - { - "attributes": {}, - "id": "B00000000", - "parents": [], - "range": "(0..18]", - "selfClosing": false, - "type": "paragraph", - }, - { - "attributes": {}, - "id": "B00000001", - "parents": [], - "range": "(18..35]", - "selfClosing": false, - "type": "paragraph", - }, - ], - "marks": [], - "text": "foo foo -->foo ", -} -`; - -exports[`Raw HTML foo foo --> - foo foo --> 1`] = ` { From adcc47b3de1a7c5e11aac1effdcb54d16c5e7710 Mon Sep 17 00:00:00 2001 From: Bach Bui Date: Wed, 3 Jul 2024 12:27:26 -0400 Subject: [PATCH 10/12] chore: hoist regex --- packages/@atjson/renderer-commonmark/src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/@atjson/renderer-commonmark/src/index.ts b/packages/@atjson/renderer-commonmark/src/index.ts index 3215a860a..25869edd9 100644 --- a/packages/@atjson/renderer-commonmark/src/index.ts +++ b/packages/@atjson/renderer-commonmark/src/index.ts @@ -27,6 +27,8 @@ import { } from "./lib/punctuation"; export * from "./lib/punctuation"; +const TERMINAL_LINEBREAKS = /(\\\n(\n*))+$/gs; + export function* splitDelimiterRuns( context: Context, options: { escapeHtmlEntities: boolean; ignoreInnerMark?: boolean } = { @@ -254,7 +256,7 @@ export default class CommonmarkRenderer extends Renderer { *root(): Iterator { let rawText = (yield).join(""); - return rawText.replace(/(\\\n(\n*))+$/gs, "$2"); + return rawText.replace(TERMINAL_LINEBREAKS, "$2"); } /** From 603bb37c1a028675239e7a88037be2e21677a1a8 Mon Sep 17 00:00:00 2001 From: Bach Bui Date: Wed, 3 Jul 2024 12:29:56 -0400 Subject: [PATCH 11/12] chore: add comments for regex --- packages/@atjson/renderer-commonmark/src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/@atjson/renderer-commonmark/src/index.ts b/packages/@atjson/renderer-commonmark/src/index.ts index 25869edd9..ba6b83af3 100644 --- a/packages/@atjson/renderer-commonmark/src/index.ts +++ b/packages/@atjson/renderer-commonmark/src/index.ts @@ -27,6 +27,8 @@ import { } from "./lib/punctuation"; export * from "./lib/punctuation"; +// match a backslash + one or more new lines at the very end of the output +// the second capture group allows us to preserve the extra new lines const TERMINAL_LINEBREAKS = /(\\\n(\n*))+$/gs; export function* splitDelimiterRuns( From 58285767bf30b307b8bc9dba4e31f83be557ae6a Mon Sep 17 00:00:00 2001 From: Bach Bui Date: Tue, 9 Jul 2024 12:49:52 -0400 Subject: [PATCH 12/12] chore: change linebreak md syntax and dont remove them Instead of suppressing the rendering of linebreaks when they terminate a block/document, we can change our linebreak md syntax to an alternative that doesn't break the parser. The alternative linebreak sequence is ` \n` instead of `\\\n`. When this appears at the end of a document, it is still parsed as a linebreak, so it is fine to always render it. --- .../@atjson/renderer-commonmark/src/index.ts | 15 +-- .../test/commonmark.test.ts | 16 ++-- .../test/line-break.test.ts | 94 +------------------ 3 files changed, 17 insertions(+), 108 deletions(-) diff --git a/packages/@atjson/renderer-commonmark/src/index.ts b/packages/@atjson/renderer-commonmark/src/index.ts index ba6b83af3..1f5350817 100644 --- a/packages/@atjson/renderer-commonmark/src/index.ts +++ b/packages/@atjson/renderer-commonmark/src/index.ts @@ -27,10 +27,6 @@ import { } from "./lib/punctuation"; export * from "./lib/punctuation"; -// match a backslash + one or more new lines at the very end of the output -// the second capture group allows us to preserve the extra new lines -const TERMINAL_LINEBREAKS = /(\\\n(\n*))+$/gs; - export function* splitDelimiterRuns( context: Context, options: { escapeHtmlEntities: boolean; ignoreInnerMark?: boolean } = { @@ -257,8 +253,8 @@ export default class CommonmarkRenderer extends Renderer { } *root(): Iterator { - let rawText = (yield).join(""); - return rawText.replace(TERMINAL_LINEBREAKS, "$2"); + let rawText = yield; + return rawText.join(""); } /** @@ -478,17 +474,14 @@ export default class CommonmarkRenderer extends Renderer { return ""; } - if (context.parent == null && context.next == null) { - return ""; - } - // MD code and html blocks cannot contain line breaks // https://spec.commonmark.org/0.29/#example-637 if (context.parent?.type === "code" || context.parent?.type === "html") { return "\n"; } - return "\\\n"; + // two spaces + newline is parsed as a line break + return " \n"; } /** diff --git a/packages/@atjson/renderer-commonmark/test/commonmark.test.ts b/packages/@atjson/renderer-commonmark/test/commonmark.test.ts index 60dca26ad..c92666e71 100644 --- a/packages/@atjson/renderer-commonmark/test/commonmark.test.ts +++ b/packages/@atjson/renderer-commonmark/test/commonmark.test.ts @@ -262,7 +262,7 @@ After all the lists ], }); - expect(CommonmarkRenderer.render(document)).toBe("1. A\\\n B\n2. C\n\n"); + expect(CommonmarkRenderer.render(document)).toBe("1. A \n B\n2. C\n\n"); }); test("preserve space between sentence-terminating italic + number.", () => { @@ -917,7 +917,7 @@ After all the lists }, ], }); - expect(CommonmarkRenderer.render(document)).toBe("**bold**\\\na"); + expect(CommonmarkRenderer.render(document)).toBe("**bold** \na"); }); test("delimiters with backslash in the inner boundary", () => { @@ -944,7 +944,7 @@ After all the lists }, ], }); - expect(CommonmarkRenderer.render(document)).toBe("**bold\\\\**\\\na"); + expect(CommonmarkRenderer.render(document)).toBe("**bold\\\\** \na"); }); test("delimiters with multiple backslash and newline in the inner boundary", () => { @@ -1803,7 +1803,7 @@ After all the lists ], }); - expect(CommonmarkRenderer.render(document)).toEqual("a\\\n\\\nb"); + expect(CommonmarkRenderer.render(document)).toEqual("a \n \nb"); }); test("Document with text and empty line break on next line.", () => { @@ -1908,7 +1908,7 @@ After all the lists }); expect(CommonmarkRenderer.render(document)).toBe( - "Testing\\\n\\\nOne Another" + "Testing \n \nOne Another \n" ); }); @@ -1988,10 +1988,10 @@ After all the lists ], }); - expect(CommonmarkRenderer.render(document)).toBe("Common\\\n\\\nMark"); + expect(CommonmarkRenderer.render(document)).toBe("Common \n \nMark"); }); - test("Empty Document", () => { + test("Document with all line breaks", () => { let document = new OffsetSource({ content: "<$root>", @@ -2092,7 +2092,7 @@ After all the lists ], }); - expect(CommonmarkRenderer.render(document)).toBe(""); + expect(CommonmarkRenderer.render(document)).toBe(" \n \n \n"); }); test.each([ diff --git a/packages/@atjson/renderer-commonmark/test/line-break.test.ts b/packages/@atjson/renderer-commonmark/test/line-break.test.ts index f53c95398..b8a44c11b 100644 --- a/packages/@atjson/renderer-commonmark/test/line-break.test.ts +++ b/packages/@atjson/renderer-commonmark/test/line-break.test.ts @@ -1,6 +1,6 @@ import CommonmarkRenderer from "../src"; -describe("terminal line breaks are removed", () => { +describe("terminal line breaks are rendered", () => { test("in text", () => { const document = { text: "\ufffctest\ufffc\ufffc", @@ -30,7 +30,7 @@ describe("terminal line breaks are removed", () => { marks: [], }; - expect(CommonmarkRenderer.render(document)).toBe("test"); + expect(CommonmarkRenderer.render(document)).toBe("test \n \n"); }); test("in text with interleaving new lines", () => { @@ -62,7 +62,7 @@ describe("terminal line breaks are removed", () => { marks: [], }; - expect(CommonmarkRenderer.render(document)).toBe("test\n"); + expect(CommonmarkRenderer.render(document)).toBe("test \n\n \n"); }); test("in text with preceding linebreaks", () => { @@ -94,7 +94,7 @@ describe("terminal line breaks are removed", () => { marks: [], }; - expect(CommonmarkRenderer.render(document)).toBe("test\\\ntest"); + expect(CommonmarkRenderer.render(document)).toBe("test \ntest \n"); }); test("in text terminating a mark", () => { @@ -126,7 +126,7 @@ describe("terminal line breaks are removed", () => { ], }; - expect(CommonmarkRenderer.render(document)).toBe("**test**"); + expect(CommonmarkRenderer.render(document)).toBe("**test** \n"); }); test("in paragraphs", () => { @@ -168,87 +168,3 @@ describe("terminal line breaks are removed", () => { expect(CommonmarkRenderer.render(document)).toBe("test\n\ntest\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: "B00000001", - type: "line-break", - parents: ["text"], - selfClosing: true, - attributes: {}, - }, - ], - marks: [], - }; - - expect(CommonmarkRenderer.render(document)).toBe("line 1\\\nline 2"); - }); - - test("in text terminating a mark", () => { - const document = { - text: "\ufffcline 1\ufffcline 2", - blocks: [ - { - id: "B00000000", - type: "text", - parents: [], - selfClosing: false, - attributes: {}, - }, - { - id: "B00000001", - type: "line-break", - parents: ["text"], - selfClosing: true, - attributes: {}, - }, - ], - marks: [ - { - id: "M00000000", - type: "bold", - range: "(1..8]" as const, - attributes: {}, - }, - ], - }; - - 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: "B00000001", - type: "line-break", - parents: ["paragraph"], - selfClosing: true, - attributes: {}, - }, - ], - marks: [], - }; - - expect(CommonmarkRenderer.render(document)).toBe("line 1\\\nline 2\n\n"); - }); -});