Skip to content

Commit ca8e240

Browse files
committed
Add remark-api to dev-dependencies
1 parent 671e5ff commit ca8e240

7 files changed

+75
-49
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ node_modules/
66
.DS_Store
77
yarn.lock
88

9+
!/index.d.ts
910
!/test-types.d.ts

index.d.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type {Nodes} from 'hast'
2+
import type {VFile} from 'vfile'
3+
4+
export {raw} from './lib/index.js'
5+
6+
/**
7+
* Configuration.
8+
*/
9+
export interface Options {
10+
/**
11+
* Corresponding virtual file representing the input document (optional).
12+
*/
13+
file?: VFile | null | undefined
14+
15+
/**
16+
* List of custom hast node types to pass through (as in, keep) (optional).
17+
*
18+
* If the passed through nodes have children, those children are expected to
19+
* be hast again and will be handled.
20+
*/
21+
passThrough?: Array<string> | null | undefined
22+
}

index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
/**
2-
* @typedef {import('./lib/index.js').Options} Options
3-
*/
4-
1+
// Note: types exposed from `index.d.ts`.
52
export {raw} from './lib/index.js'

lib/index.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @typedef {import('hast').RootContent} RootContent
88
* @typedef {import('hast').Text} Text
99
*
10+
* @typedef {import('hast-util-raw').Options} Options
11+
*
1012
* @typedef {import('mdast-util-to-hast').Raw} Raw
1113
*
1214
* @typedef {import('parse5').DefaultTreeAdapterMap} DefaultTreeAdapterMap
@@ -18,21 +20,9 @@
1820
* @typedef {import('parse5').Token.TagToken} TagToken
1921
*
2022
* @typedef {import('unist').Point} Point
21-
*
22-
* @typedef {import('vfile').VFile} VFile
2323
*/
2424

2525
/**
26-
* @typedef Options
27-
* Configuration.
28-
* @property {VFile | null | undefined} [file]
29-
* Corresponding virtual file representing the input document (optional).
30-
* @property {Array<Nodes['type']> | null | undefined} [passThrough]
31-
* List of custom hast node types to pass through (as in, keep) (optional).
32-
*
33-
* If the passed through nodes have children, those children are expected to
34-
* be hast again and will be handled.
35-
*
3626
* @typedef State
3727
* Info passed around about the current state.
3828
* @property {(node: Nodes) => undefined} handle
@@ -43,10 +33,16 @@
4333
* Current parser.
4434
* @property {boolean} stitches
4535
* Whether there are stitches.
46-
*
47-
* @typedef {{type: 'comment', value: {stitch: Nodes}}} Stitch
36+
*/
37+
38+
/**
39+
* @typedef Stitch
4840
* Custom comment-like value we pass through parse5, which contains a
4941
* replacement node that we’ll swap back in afterwards.
42+
* @property {'comment'} type
43+
* Node type.
44+
* @property {{stitch: Nodes}} value
45+
* Replacement value.
5046
*/
5147

5248
import structuredClone from '@ungap/structured-clone'

package.json

+19-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"hastscript": "^9.0.0",
5757
"mdast-util-from-markdown": "^2.0.0",
5858
"prettier": "^3.0.0",
59+
"remark-api": "^1.0.0",
5960
"remark-cli": "^12.0.0",
6061
"remark-preset-wooorm": "^10.0.0",
6162
"type-coverage": "^2.0.0",
@@ -81,7 +82,8 @@
8182
},
8283
"remarkConfig": {
8384
"plugins": [
84-
"remark-preset-wooorm"
85+
"remark-preset-wooorm",
86+
"remark-api"
8587
]
8688
},
8789
"typeCoverage": {
@@ -97,7 +99,22 @@
9799
"**/*.ts"
98100
],
99101
"rules": {
100-
"@typescript-eslint/consistent-type-definitions": "off"
102+
"@typescript-eslint/array-type": [
103+
"error",
104+
{
105+
"default": "generic"
106+
}
107+
],
108+
"@typescript-eslint/ban-types": [
109+
"error",
110+
{
111+
"extendDefaults": true
112+
}
113+
],
114+
"@typescript-eslint/consistent-type-definitions": [
115+
"error",
116+
"interface"
117+
]
101118
}
102119
}
103120
],

readme.md

+21-28
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ HTML) again, keeping positional info okay.
1818
* [Install](#install)
1919
* [Use](#use)
2020
* [API](#api)
21-
* [`raw(tree[, options])`](#rawtree-options)
2221
* [`Options`](#options)
22+
* [`raw(tree, options)`](#rawtree-options)
2323
* [Types](#types)
2424
* [Compatibility](#compatibility)
2525
* [Security](#security)
@@ -117,37 +117,36 @@ Yields:
117117

118118
## API
119119

120-
This package exports the identifier [`raw`][api-raw].
121-
There is no default export.
120+
### `Options`
122121

123-
### `raw(tree[, options])`
122+
Configuration.
124123

125-
Pass a hast tree through an HTML parser, which will fix nesting, and turn raw
126-
nodes into actual nodes.
124+
###### Fields
127125

128-
###### Parameters
126+
* `file?` (`VFile | null | undefined`)
127+
— corresponding virtual file representing the input document (optional)
128+
* `passThrough?` (`Array<string> | null | undefined`)
129129

130-
* `tree` ([`Node`][node])
131-
— original hast tree to transform
132-
* `options` ([`Options`][api-options], optional)
133-
— configuration
130+
List of custom hast node types to pass through (as in, keep) (optional).
134131

135-
###### Returns
132+
If the passed through nodes have children, those children are expected to
133+
be hast again and will be handled.
136134

137-
Parsed again tree ([`Node`][node]).
135+
### `raw(tree, options)`
138136

139-
### `Options`
137+
Pass a hast tree through an HTML parser, which will fix nesting, and turn
138+
raw nodes into actual nodes.
139+
140+
###### Parameters
140141

141-
Configuration (TypeScript type).
142+
* `tree` (`Root | RootContent`)
143+
— original hast tree to transform
144+
* `options?` (`Options | null | undefined`)
145+
— configuration (optional)
142146

143-
###### Fields
147+
###### Returns
144148

145-
* `passThrough` (`Array<string>`, optional)
146-
— list of custom hast node types to pass through (keep).
147-
If the passed through nodes have children, those children are expected to be
148-
hast and will be handled by this utility
149-
* `file` ([`VFile`][vfile], optional)
150-
— corresponding virtual file representing the input document
149+
Parsed again tree (`Root | RootContent`).
151150

152151
## Types
153152

@@ -260,18 +259,12 @@ abide by its terms.
260259

261260
[hast]: https://github.com/syntax-tree/hast
262261

263-
[node]: https://github.com/syntax-tree/hast#nodes
264-
265262
[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast
266263

267264
[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize
268265

269-
[vfile]: https://github.com/vfile/vfile
270-
271266
[rehype-raw]: https://github.com/rehypejs/rehype-raw
272267

273268
[parse5]: https://github.com/inikulin/parse5
274269

275-
[api-raw]: #rawtree-options
276-
277270
[api-options]: #options

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
"target": "es2022"
1313
},
1414
"exclude": ["coverage/", "node_modules/"],
15-
"include": ["**/**.js", "test-types.d.ts"]
15+
"include": ["**/**.js", "index.d.ts", "test-types.d.ts"]
1616
}

0 commit comments

Comments
 (0)