From 335f66373f648a93b2e6746fc226b6ee82331c83 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Mon, 31 May 2021 17:44:30 +0800 Subject: [PATCH] fix: Fix mark verification error. --- __tests__/index.test.ts | 5 +++++ src/utils.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index e30d3d0..06b4f00 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -195,6 +195,11 @@ describe('rehype-attr test case', () => { markdown: '\n```js\nconsole.log("")\n```', expected: '\n
console.log("")\n
', }, + { + title: 'options="attr" - not config 8', + markdown: 'test\n', + expected: '

test

\n', + }, { title: 'options="attr" - Code', markdown: '\n```js\nconsole.log("")\n```', diff --git a/src/utils.ts b/src/utils.ts index 6372be0..1e4108f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -21,7 +21,7 @@ export const prevChild = (data: Content[] = [], index: number): CommentData | un i--; if (!data[i]) return if ((data[i] && data[i].value && (data[i].value as string).replace(/(\n|\s)/g, '') !== '') || data[i].type !== 'text') { - if (!/rehype:/.test(data[i].value as string) && (data[i].type as string) !== 'comment') return; + if (!/^rehype:/.test(data[i].value as string) && (data[i].type as string) !== 'comment') return; return data[i] as unknown as CommentData; } } @@ -40,7 +40,7 @@ export const nextChild = (data: Content[] = [], index: number, tagName?: string) } else { if (!data[i] || (data[i].type !== 'text' && (data[i].type as string) !== 'comment') || (data[i].type == 'text' && (data[i].value as string).replace(/(\n|\s)/g, '') !== '')) return if ((data[i].type as string) === 'comment') { - if (!/rehype:/.test(data[i].value as string)) return; + if (!/^rehype:/.test(data[i].value as string)) return; const nextNode = nextChild(data, i, 'pre') if (nextNode) return; return data[i] as unknown as CommentData;