From 51f4ca328c75278659e27de92f131ccac41261ba Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 22 Jun 2023 15:04:22 +0200 Subject: [PATCH 1/5] proof of multiline comment bug --- test/test.mjs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/test.mjs b/test/test.mjs index e2f9e82..c626d10 100644 --- a/test/test.mjs +++ b/test/test.mjs @@ -39,6 +39,10 @@ assert.equal( + + and a paragraph ` ), From 457a2f841516e9177f92979bfc5b23f103efdf9b Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 22 Jun 2023 16:23:22 +0200 Subject: [PATCH 2/5] fix multi-line comments edge case --- index.js | 4 ++++ package-lock.json | 4 ++-- test/test.mjs | 54 ++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 99f8217..99dd1b9 100644 --- a/index.js +++ b/index.js @@ -109,6 +109,10 @@ function tokenize(effects, ok, nok) { return nok(code) } + if (markdownLineEnding(code)) { + return atLineEnding(code); + } + effects.enter(types.data) if (code === codes.dash) { diff --git a/package-lock.json b/package-lock.json index 9e2c868..ef12c31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "remark-comment", - "version": "0.1.0", + "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "remark-comment", - "version": "0.1.0", + "version": "1.0.0", "license": "MIT", "dependencies": { "micromark-factory-space": "^1.0.0", diff --git a/test/test.mjs b/test/test.mjs index c626d10..6b754f1 100644 --- a/test/test.mjs +++ b/test/test.mjs @@ -43,6 +43,10 @@ assert.equal( has a multi-line comment --> + + and a paragraph ` ), @@ -56,12 +60,32 @@ assert.equal( + + + + and a paragraph `, { ast: true } ), - '# This document\n\n\n\nand a paragraph\n' -) + `# This document + + + + + + + +and a paragraph +`) // It renders to HTML via Rehype assert.equal( @@ -70,6 +94,14 @@ assert.equal( + + + + and a paragraph ` ), @@ -84,11 +116,19 @@ assert.equal( + + + + and a paragraph `, { ast: true } ), - '

This document

\n\n

and a paragraph

' + '

This document

\n\n\n\n

and a paragraph

' ) // It renders to HTML via Micromark @@ -98,6 +138,14 @@ assert.equal( + + + + and a paragraph ` ), From 5b69693783f9f2efabfcb6a2c8d1dc71b03cf017 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 22 Jun 2023 18:38:43 +0200 Subject: [PATCH 3/5] add "blank line" tests --- test/test.mjs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/test.mjs b/test/test.mjs index 6b754f1..2643bef 100644 --- a/test/test.mjs +++ b/test/test.mjs @@ -47,6 +47,10 @@ has a multi-line comment multi-line comment --> + + + + and a paragraph ` ), @@ -68,6 +72,10 @@ has a multi-line comment multi-line comment --> + + + + and a paragraph `, { ast: true } @@ -84,6 +92,10 @@ has a multi-line comment multi-line comment --> + + + + and a paragraph `) @@ -102,6 +114,10 @@ has a multi-line comment multi-line comment --> + + + + and a paragraph ` ), @@ -124,11 +140,15 @@ has a multi-line comment multi-line comment --> + + + + and a paragraph `, { ast: true } ), - '

This document

\n\n\n\n

and a paragraph

' + '

This document

\n\n\n\n\n\n

and a paragraph

' ) // It renders to HTML via Micromark From f496b9d500d9cafd684d0d458c93ad1be5fd930f Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Fri, 23 Jun 2023 18:59:55 +0200 Subject: [PATCH 4/5] Add recommended fix from Titus --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 99dd1b9..c70bd75 100644 --- a/index.js +++ b/index.js @@ -178,7 +178,9 @@ function tokenize(effects, ok, nok) { function end(code) { if (code === codes.greaterThan) { effects.exit(types.data) + effects.enter('commentEnd') // See https://github.com/leebyron/remark-comment/pull/3#discussion_r1239494357 effects.consume(code) + effects.exit('commentEnd') effects.exit('comment') return ok(code) } From 426dde74a26d9d9adfe1a649d602366c46027350 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Fri, 23 Jun 2023 19:03:04 +0200 Subject: [PATCH 5/5] test with dev assertions --- test/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/package.json b/test/package.json index 6323d26..ed61531 100644 --- a/test/package.json +++ b/test/package.json @@ -10,6 +10,6 @@ "unified": "^10.1.1" }, "scripts": { - "test": "node test.mjs" + "test": "node --conditions development test.mjs" } }