From cc13db7942fb4ecb10637d1de45800d9f1edd319 Mon Sep 17 00:00:00 2001 From: myl7 Date: Mon, 19 Feb 2024 22:14:47 +0800 Subject: [PATCH] Update comment for the reason --- src/index.ts | 9 +++++---- test/index.spec.ts | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 22039af..d80e5c7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,12 +55,13 @@ const handleNode = // So we just need to addtionally check if the following one is a block. // The legacy title variant is not affected since it checks an inline and does not case the newline. - // No addtional inlines can exist in this paragraph for the title + // No addtional inlines can exist in this paragraph for the title... if (paragraph.children.length > 1) { - // Carriage returns are allowed by GitHub flavored Markdown. - // It makes a more coherent rendering in environments were admonitions aren't supported. - // When they are, we must strip the unnecessary `
` prepended in the first `

`. + // Unless it is an inline break, which can be transformed to from 2 spaces with a newline. if (paragraph.children.at(1)?.type == 'break') { + // When it is, we actually have already found the line break required by GitHub. + // So we just strip the additional `
` element. + // The title element will be removed later. paragraph.children.splice(1, 1) } else { return diff --git a/test/index.spec.ts b/test/index.spec.ts index 1148377..7e9041f 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -166,6 +166,7 @@ describe('GitHub beta blockquote-based admonitions with titles like [!NOTE]', fu '# Admonitions\n' + // So that the title isn't put inline with the forecoming text, // when no GFM admonitions are available. + // These 2 spaces with the newline are transformed into an inline break. // ----------vv '> [!WARNING] \n' + '> Critical content demanding immediate user attention due to potential risks.\n',