Skip to content

Commit 00691e9

Browse files
committed
Refactor types to use ConstructNameMap interface
1 parent c628864 commit 00691e9

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules/
44
*.d.ts
55
.DS_Store
66
yarn.lock
7+
!/index.d.ts

index.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export {
2+
gfmStrikethroughFromMarkdown,
3+
gfmStrikethroughToMarkdown
4+
} from './lib/index.js'
5+
6+
// Add custom data tracked to turn a syntax tree into markdown.
7+
declare module 'mdast-util-to-markdown' {
8+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
9+
interface ConstructNameMap {
10+
/**
11+
* Whole strikethrough.
12+
*
13+
* ```markdown
14+
* > | ~~a~~
15+
* ^^^^^
16+
* ```
17+
*/
18+
strikethrough: 'strikethrough'
19+
}
20+
}

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Note: extra types in `index.d.ts`.
12
export {
23
gfmStrikethroughFromMarkdown,
34
gfmStrikethroughToMarkdown

lib/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext
44
* @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension
55
* @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle
6+
* @typedef {import('mdast-util-to-markdown').ConstructName} ConstructName
67
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
78
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
89
*/
@@ -21,7 +22,9 @@ export const gfmStrikethroughFromMarkdown = {
2122
* List of constructs that occur in phrasing (paragraphs, headings), but cannot
2223
* contain strikethroughs. So they sort of cancel each other out.
2324
*
24-
* Note: keep in sync with: <https://github.com/syntax-tree/mdast-util-to-markdown/blob/c47743b/lib/unsafe.js#L11>
25+
* Note: keep in sync with: <https://github.com/syntax-tree/mdast-util-to-markdown/blob/8ce8dbf/lib/unsafe.js#L14>
26+
*
27+
* @type {Array<ConstructName>}
2528
*/
2629
const constructsWithoutStrikethrough = [
2730
'autolink',
@@ -38,7 +41,6 @@ export const gfmStrikethroughToMarkdown = {
3841
{
3942
character: '~',
4043
inConstruct: 'phrasing',
41-
// @ts-expect-error: register.
4244
notInConstruct: constructsWithoutStrikethrough
4345
}
4446
],
@@ -69,8 +71,7 @@ function exitStrikethrough(token) {
6971
*/
7072
function handleDelete(node, _, context, safeOptions) {
7173
const tracker = track(safeOptions)
72-
// To do: next major (?): use `delete` or `strikethrough`?
73-
const exit = context.enter('emphasis')
74+
const exit = context.enter('strikethrough')
7475
let value = tracker.move('~~')
7576
value += containerPhrasing(node, context, {
7677
...tracker.current(),

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["**/*.js"],
2+
"include": ["**/*.js", "index.d.ts"],
33
"exclude": ["coverage/", "node_modules/"],
44
"compilerOptions": {
55
"checkJs": true,

0 commit comments

Comments
 (0)