Skip to content

Commit 3487ad6

Browse files
committed
fix unified types
1 parent 1a3af05 commit 3487ad6

File tree

2 files changed

+45
-55
lines changed

2 files changed

+45
-55
lines changed

deno.jsonc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"imports": {
2323
"fs": "https://deno.land/[email protected]/fs/mod.ts",
2424
"type-mdast": "https://cdn.jsdelivr.net/npm/@types/[email protected]/index.d.ts",
25-
"unified": "https://esm.sh/unified@11",
26-
"unist-util-visit": "https://esm.sh/unist-util-visit@5",
25+
"unified": "https://esm.sh/unified@11.0.4",
26+
"unist-util-visit": "https://esm.sh/unist-util-visit@5.0.0",
2727
"remark-parse": "https://esm.sh/[email protected]",
2828
"remark-rehype": "https://esm.sh/[email protected]",
2929
"rehype-raw": "https://esm.sh/[email protected]",

src/util/remark/remark-github-alert.js

Lines changed: 43 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ const DEFAULT_GITHUB_ICONS = {
2626
/**
2727
* @typedef {import("type-mdast").Root} Root
2828
* @typedef {import("type-mdast").PhrasingContent} PhrasingContent
29-
* @typedef {import("unified").Plugin<RemarkGitHubAlertsOptions[], Root>} Plugin
29+
* @typedef {import("unified").Plugin<[RemarkGitHubAlertsOptions], Root>} Plugin
30+
* @typedef {import("unified").Transformer<Root, Root>} Transformer
3031
*/
3132

32-
/**
33-
* @param {RemarkGitHubAlertsOptions} [options = {}]
34-
* @returns {Plugin}
35-
*/
33+
/** @type {Plugin}*/
3634
const remarkGithubAlerts = (options = {}) => {
3735
const {
3836
markers = ['TIP', 'NOTE', 'IMPORTANT', 'WARNING', 'CAUTION'],
@@ -50,57 +48,49 @@ const remarkGithubAlerts = (options = {}) => {
5048
matchCaseSensitive ? '' : 'i',
5149
)
5250
return (tree) => {
53-
visit(
54-
tree,
55-
'blockquote',
56-
(
57-
/**@type {import("type-mdast").Node}*/ node,
58-
/**@type {Number}*/ _index,
59-
/**@type {import('type-mdast').Parent} */ _parent,
60-
) => {
61-
/**@type {PhrasingContent}*/
62-
const firstContent = node.children?.[0].children?.[0]
63-
if (!firstContent || firstContent.type !== 'text') return
64-
const match = firstContent.value.match(RE)
65-
if (!match) return
66-
/**@type {keyof typeof icons}*/
67-
const type = match[1].toLowerCase()
68-
const title = titles[type] ||
69-
type.charAt(0).toUpperCase() + type.slice(1)
70-
const icon = icons[type]
51+
visit(tree, 'blockquote', (node, _index, _parent) => {
52+
/**@type {PhrasingContent}*/
53+
const firstContent = node.children?.[0].children?.[0]
54+
if (!firstContent || firstContent.type !== 'text') return
55+
const match = firstContent.value.match(RE)
56+
if (!match) return
57+
/**@type {keyof typeof icons}*/
58+
const type = match[1].toLowerCase()
59+
const title = titles[type] ||
60+
type.charAt(0).toUpperCase() + type.slice(1)
61+
const icon = icons[type]
7162

72-
firstContent.value = firstContent.value.slice(match[0].length)
73-
.trimStart()
74-
node.data = {
75-
hName: 'div',
76-
hProperties: {
77-
class: `${classPrefix} ${classPrefix}-${type}`,
78-
},
79-
}
80-
node.children = [
81-
{
82-
type: 'paragraph',
83-
data: {
84-
hName: 'p',
85-
hProperties: {
86-
class: `${classPrefix}-title`,
87-
},
63+
firstContent.value = firstContent.value.slice(match[0].length)
64+
.trimStart()
65+
node.data = {
66+
hName: 'div',
67+
hProperties: {
68+
class: `${classPrefix} ${classPrefix}-${type}`,
69+
},
70+
}
71+
node.children = [
72+
{
73+
type: 'paragraph',
74+
data: {
75+
hName: 'p',
76+
hProperties: {
77+
class: `${classPrefix}-title`,
8878
},
89-
children: [
90-
{
91-
type: 'html',
92-
value: icon,
93-
},
94-
{
95-
type: 'text',
96-
value: title,
97-
},
98-
],
9979
},
100-
...node.children,
101-
]
102-
},
103-
)
80+
children: [
81+
{
82+
type: 'html',
83+
value: icon,
84+
},
85+
{
86+
type: 'text',
87+
value: title,
88+
},
89+
],
90+
},
91+
...node.children,
92+
]
93+
})
10494
return tree
10595
}
10696
}

0 commit comments

Comments
 (0)