-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9392 from weseek/imprv/callout-custom-label
imprv: GitHub Alert with directive syntax
- Loading branch information
Showing
7 changed files
with
189 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import type { ContainerDirective } from 'mdast-util-directive'; | ||
import remarkDirective from 'remark-directive'; | ||
import remarkParse from 'remark-parse'; | ||
import { unified } from 'unified'; | ||
import { visit } from 'unist-util-visit'; | ||
import { describe, it, expect } from 'vitest'; | ||
|
||
import * as callout from './callout'; | ||
|
||
describe('remarkPlugin', () => { | ||
it('should transform containerDirective to callout', () => { | ||
const processor = unified() | ||
.use(remarkParse) | ||
.use(remarkDirective) | ||
.use(callout.remarkPlugin); | ||
|
||
const markdown = ` | ||
:::info | ||
This is an info callout. | ||
::: | ||
`; | ||
|
||
const tree = processor.parse(markdown); | ||
processor.runSync(tree); | ||
|
||
let calloutNode; | ||
visit(tree, 'containerDirective', (node) => { | ||
calloutNode = node; | ||
}); | ||
|
||
expect(calloutNode).toBeDefined(); | ||
|
||
assert(calloutNode?.data?.hName != null); | ||
assert(calloutNode?.data?.hProperties != null); | ||
|
||
expect(calloutNode.data.hName).toBe('callout'); | ||
expect(calloutNode.data.hProperties.type).toBe('info'); | ||
expect(calloutNode.data.hProperties.label).toBe('info'); | ||
|
||
assert('children' in calloutNode.children[0]); | ||
assert('value' in calloutNode.children[0].children[0]); | ||
|
||
expect(calloutNode.children[0].children[0].value).toBe('This is an info callout.'); | ||
}); | ||
|
||
it('should transform containerDirective to callout with custom label', () => { | ||
const processor = unified() | ||
.use(remarkParse) | ||
.use(remarkDirective) | ||
.use(callout.remarkPlugin); | ||
|
||
const markdown = ` | ||
:::info[CUSTOM LABEL] | ||
This is an info callout. | ||
::: | ||
`; | ||
|
||
const tree = processor.parse(markdown); | ||
processor.runSync(tree); | ||
|
||
let calloutNode: ContainerDirective | undefined; | ||
visit(tree, 'containerDirective', (node) => { | ||
calloutNode = node; | ||
}); | ||
|
||
expect(calloutNode).toBeDefined(); | ||
|
||
assert(calloutNode?.data?.hName != null); | ||
assert(calloutNode?.data?.hProperties != null); | ||
|
||
expect(calloutNode.data.hName).toBe('callout'); | ||
expect(calloutNode.data.hProperties.type).toBe('info'); | ||
expect(calloutNode.data.hProperties.label).toBe('CUSTOM LABEL'); | ||
|
||
assert('children' in calloutNode.children[0]); | ||
assert('value' in calloutNode.children[0].children[0]); | ||
|
||
expect(calloutNode.children[0].children[0].value).toBe('This is an info callout.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters