Skip to content

Commit

Permalink
fix: Fix mark verification error.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed May 31, 2021
1 parent d9d6633 commit 335f663
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions __tests__/index.test.ts
Expand Up @@ -195,6 +195,11 @@ describe('rehype-attr test case', () => {
markdown: '<!--rehype:-->\n```js\nconsole.log("")\n```',
expected: '<!--rehype:-->\n<pre><code class="language-js">console.log("")\n</code></pre>',
},
{
title: 'options="attr" - not config 8',
markdown: 'test\n<!--23rehype:a=1&-->',
expected: '<p>test</p>\n<!--23rehype:a=1&-->',
},
{
title: 'options="attr" - Code',
markdown: '<!--rehype:title=Rehype Attrs-->\n```js\nconsole.log("")\n```',
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Expand Up @@ -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;
}
}
Expand All @@ -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;
Expand Down

0 comments on commit 335f663

Please sign in to comment.