Skip to content

Commit b685b00

Browse files
committed
Add types, docs for options
1 parent 7ca8974 commit b685b00

File tree

6 files changed

+74
-5
lines changed

6 files changed

+74
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
coverage/
77
node_modules/
88
yarn.lock
9+
!/index.d.ts

index.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type {ToMarkdownOptions} from 'mdast-util-directive'
2+
3+
export {default} from './lib/index.js'
4+
5+
/**
6+
* Configuration for `remark-directive`.
7+
*
8+
* Currently supports
9+
* `collapseEmptyAttributes`,
10+
* `preferShortcut`,
11+
* `preferUnquoted`,
12+
* `quoteSmart`,
13+
* and `quote` as serialization options.
14+
*/
15+
export interface Options extends ToMarkdownOptions {}

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// Note: types exposed from `index.d.ts`.
12
export {default} from './lib/index.js'

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,29 @@
7878
"version": "3.0.0",
7979
"xo": {
8080
"overrides": [
81+
{
82+
"files": [
83+
"**/*.d.ts"
84+
],
85+
"rules": {
86+
"@typescript-eslint/array-type": [
87+
"error",
88+
{
89+
"default": "generic"
90+
}
91+
],
92+
"@typescript-eslint/ban-types": [
93+
"error",
94+
{
95+
"extendDefaults": true
96+
}
97+
],
98+
"@typescript-eslint/consistent-type-definitions": [
99+
"error",
100+
"interface"
101+
]
102+
}
103+
},
81104
{
82105
"files": [
83106
"test/**/*.js"

readme.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ proposal][commonmark-prop] (`:cite[smith04]`,
1919
* [Install](#install)
2020
* [Use](#use)
2121
* [API](#api)
22-
* [`unified().use(remarkDirective)`](#unifieduseremarkdirective)
22+
* [`unified().use(remarkDirective[, options])`](#unifieduseremarkdirective-options)
23+
* [`Options`](#options)
2324
* [Examples](#examples)
2425
* [Example: YouTube](#example-youtube)
2526
* [Example: Styled blocks](#example-styled-blocks)
@@ -174,13 +175,14 @@ function myRemarkPlugin() {
174175
This package exports no identifiers.
175176
The default export is [`remarkDirective`][api-remark-directive].
176177

177-
### `unified().use(remarkDirective)`
178+
### `unified().use(remarkDirective[, options])`
178179

179180
Add support for generic directives.
180181

181182
###### Parameters
182183

183-
There are no parameters.
184+
* `options` ([`Options`][api-options], optional)
185+
— configuration
184186

185187
###### Returns
186188

@@ -191,6 +193,29 @@ Nothing (`undefined`).
191193
Doesn’t handle the directives:
192194
[create your own plugin][unified-create-plugin] to do that.
193195

196+
### `Options`
197+
198+
Configuration (TypeScript type).
199+
200+
###### Fields
201+
202+
* `collapseEmptyAttributes`
203+
(`boolean`, default: `true`)
204+
— collapse empty attributes: get `title` instead of `title=""`
205+
* `preferShortcut`
206+
(`boolean`, default: `true`)
207+
— prefer `#` and `.` shortcuts for `id` and `class`
208+
* `preferUnquoted`
209+
(`boolean`, default: `false`)
210+
— leave attributes unquoted if that results in less bytes
211+
* `quoteSmart`
212+
(`boolean`, default: `false`)
213+
— use the other quote if that results in less bytes
214+
* `quote`
215+
(`'"'` or `"'"`,
216+
default: the [`quote`][quote] used by `remark-stringify` for titles)
217+
— preferred quote to use around attribute values
218+
194219
## Examples
195220

196221
### Example: YouTube
@@ -500,6 +525,8 @@ abide by its terms.
500525

501526
[micromark-extending-markdown]: https://github.com/micromark/micromark#extending-markdown
502527

528+
[quote]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options
529+
503530
[rehype]: https://github.com/rehypejs/rehype
504531

505532
[remark]: https://github.com/remarkjs/remark
@@ -512,4 +539,6 @@ abide by its terms.
512539

513540
[wiki-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
514541

515-
[api-remark-directive]: #unifieduseremarkdirective
542+
[api-remark-directive]: #unifieduseremarkdirective-options
543+
544+
[api-options]: #options

tsconfig.json

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

0 commit comments

Comments
 (0)