@@ -7,6 +7,7 @@ export type {
77 Compiler ,
88 CompilerClass ,
99 CompilerFunction ,
10+ // `Data` is typed and exposed below.
1011 Pluggable ,
1112 PluggableList ,
1213 Plugin ,
@@ -18,6 +19,7 @@ export type {
1819 ProcessCallback ,
1920 Processor ,
2021 RunCallback ,
22+ // `Settings` is typed and exposed below.
2123 TransformCallback ,
2224 Transformer
2325} from './lib/index.js'
@@ -40,6 +42,8 @@ export {unified} from './lib/index.js'
4042 * ReactNode: ReactNode
4143 * }
4244 * }
45+ *
46+ * export {} // You may not need this, but it makes sure the file is a module.
4347 * ```
4448 *
4549 * Use {@link CompileResults `CompileResults`} to access the values.
@@ -49,3 +53,54 @@ export interface CompileResultMap {
4953 Uint8Array : Uint8Array
5054 string : string
5155}
56+
57+ /**
58+ * Interface of known data that can be supported by all plugins.
59+ *
60+ * Typically, options can be given to a specific plugin, but sometimes it makes
61+ * sense to have information shared with several plugins.
62+ * For example, a list of HTML elements that are self-closing, which is needed
63+ * during all phases.
64+ *
65+ * To type this, do something like:
66+ *
67+ * ```ts
68+ * declare module 'unified' {
69+ * interface Data {
70+ * htmlVoidElements?: Array<string> | undefined
71+ * }
72+ * }
73+ *
74+ * export {} // You may not need this, but it makes sure the file is a module.
75+ * ```
76+ */
77+ export interface Data {
78+ settings ?: Settings | undefined
79+ }
80+
81+ /**
82+ * Interface of known extra options, that can be supported by parser and
83+ * compilers.
84+ *
85+ * This exists so that users can use packages such as `remark`, which configure
86+ * both parsers and compilers (in this case `remark-parse` and
87+ * `remark-stringify`), and still provide options for them.
88+ *
89+ * When you make parsers or compilers, that could be packaged up together,
90+ * you should support `this.data('settings')` as input and merge it with
91+ * explicitly passed `options`.
92+ * Then, to type it, using `remark-stringify` as an example, do something like:
93+ *
94+ * ```ts
95+ * declare module 'unified' {
96+ * interface Settings {
97+ * bullet: '*' | '+' | '-'
98+ * // …
99+ * }
100+ * }
101+ *
102+ * export {} // You may not need this, but it makes sure the file is a module.
103+ * ```
104+ */
105+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
106+ export interface Settings { }
0 commit comments