Skip to content

Commit

Permalink
Add types, docs for options
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jan 22, 2025
1 parent 7ca8974 commit b685b00
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
coverage/
node_modules/
yarn.lock
!/index.d.ts
15 changes: 15 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type {ToMarkdownOptions} from 'mdast-util-directive'

export {default} from './lib/index.js'

/**
* Configuration for `remark-directive`.
*
* Currently supports
* `collapseEmptyAttributes`,
* `preferShortcut`,
* `preferUnquoted`,
* `quoteSmart`,
* and `quote` as serialization options.
*/
export interface Options extends ToMarkdownOptions {}
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// Note: types exposed from `index.d.ts`.
export {default} from './lib/index.js'
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@
"version": "3.0.0",
"xo": {
"overrides": [
{
"files": [
"**/*.d.ts"
],
"rules": {
"@typescript-eslint/array-type": [
"error",
{
"default": "generic"
}
],
"@typescript-eslint/ban-types": [
"error",
{
"extendDefaults": true
}
],
"@typescript-eslint/consistent-type-definitions": [
"error",
"interface"
]
}
},
{
"files": [
"test/**/*.js"
Expand Down
37 changes: 33 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ proposal][commonmark-prop] (`:cite[smith04]`,
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`unified().use(remarkDirective)`](#unifieduseremarkdirective)
* [`unified().use(remarkDirective[, options])`](#unifieduseremarkdirective-options)
* [`Options`](#options)
* [Examples](#examples)
* [Example: YouTube](#example-youtube)
* [Example: Styled blocks](#example-styled-blocks)
Expand Down Expand Up @@ -174,13 +175,14 @@ function myRemarkPlugin() {
This package exports no identifiers.
The default export is [`remarkDirective`][api-remark-directive].

### `unified().use(remarkDirective)`
### `unified().use(remarkDirective[, options])`

Add support for generic directives.

###### Parameters

There are no parameters.
* `options` ([`Options`][api-options], optional)
— configuration

###### Returns

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

### `Options`

Configuration (TypeScript type).

###### Fields

* `collapseEmptyAttributes`
(`boolean`, default: `true`)
— collapse empty attributes: get `title` instead of `title=""`
* `preferShortcut`
(`boolean`, default: `true`)
— prefer `#` and `.` shortcuts for `id` and `class`
* `preferUnquoted`
(`boolean`, default: `false`)
— leave attributes unquoted if that results in less bytes
* `quoteSmart`
(`boolean`, default: `false`)
— use the other quote if that results in less bytes
* `quote`
(`'"'` or `"'"`,
default: the [`quote`][quote] used by `remark-stringify` for titles)
— preferred quote to use around attribute values

## Examples

### Example: YouTube
Expand Down Expand Up @@ -500,6 +525,8 @@ abide by its terms.

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

[quote]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options

[rehype]: https://github.com/rehypejs/rehype

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

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

[api-remark-directive]: #unifieduseremarkdirective
[api-remark-directive]: #unifieduseremarkdirective-options

[api-options]: #options
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"target": "es2022"
},
"exclude": ["coverage/", "node_modules/"],
"include": ["**/*.js"]
"include": ["**/*.js", "index.d.ts"]
}

0 comments on commit b685b00

Please sign in to comment.