Skip to content

Commit d056940

Browse files
committed
Refactor docs
1 parent 08ead9e commit d056940

File tree

4 files changed

+296
-180
lines changed

4 files changed

+296
-180
lines changed

index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/**
2-
* @typedef {import('hast-util-to-jsx-runtime').Components} Components
32
* @typedef {import('hast-util-to-jsx-runtime').ExtraProps} ExtraProps
3+
* @typedef {import('./lib/index.js').AllowElement} AllowElement
4+
* @typedef {import('./lib/index.js').Components} Components
45
* @typedef {import('./lib/index.js').Options} Options
6+
* @typedef {import('./lib/index.js').UrlTransform} UrlTransform
57
*/
68

79
export {Markdown as default, defaultUrlTransform} from './lib/index.js'

lib/index.js

+20-18
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
* @typedef {import('hast').Nodes} Nodes
88
* @typedef {import('hast').Parents} Parents
99
* @typedef {import('hast').Root} Root
10-
* @typedef {import('hast-util-to-jsx-runtime').Components} Components
10+
* @typedef {import('hast-util-to-jsx-runtime').Components} JsxRuntimeComponents
1111
* @typedef {import('remark-rehype').Options} RemarkRehypeOptions
1212
* @typedef {import('unist-util-visit').BuildVisitor<Root>} Visitor
1313
* @typedef {import('unified').PluggableList} PluggableList
1414
*/
1515

1616
/**
1717
* @callback AllowElement
18-
* Decide if `element` should be allowed.
18+
* Filter elements.
1919
* @param {Readonly<Element>} element
2020
* Element to check.
2121
* @param {number} index
@@ -25,6 +25,9 @@
2525
* @returns {boolean | null | undefined}
2626
* Whether to allow `element` (default: `false`).
2727
*
28+
* @typedef {Partial<JsxRuntimeComponents>} Components
29+
* Map tag names to components.
30+
*
2831
* @typedef Deprecation
2932
* Deprecation.
3033
* @property {string} from
@@ -37,20 +40,20 @@
3740
* @typedef Options
3841
* Configuration.
3942
* @property {AllowElement | null | undefined} [allowElement]
40-
* Function called to check if an element is allowed (when truthy) or not,
41-
* `allowedElements` or `disallowedElements` is used first!
43+
* Filter elements (optional);
44+
* `allowedElements` / `disallowedElements` is used first.
4245
* @property {ReadonlyArray<string> | null | undefined} [allowedElements]
43-
* Tag names to allow (cannot combine w/ `disallowedElements`), all tag names
44-
* are allowed by default.
46+
* Tag names to allow (default: all tag names);
47+
* cannot combine w/ `disallowedElements`.
4548
* @property {string | null | undefined} [children]
46-
* Markdown to parse.
49+
* Markdown.
4750
* @property {string | null | undefined} [className]
48-
* Wrap the markdown in a `div` with this class name.
49-
* @property {Partial<Components> | null | undefined} [components]
50-
* Map tag names to React components.
51+
* Wrap in a `div` with this class name.
52+
* @property {Components | null | undefined} [components]
53+
* Map tag names to components.
5154
* @property {ReadonlyArray<string> | null | undefined} [disallowedElements]
52-
* Tag names to disallow (cannot combine w/ `allowedElements`), all tag names
53-
* are allowed by default.
55+
* Tag names to disallow (default: `[]`);
56+
* cannot combine w/ `allowedElements`.
5457
* @property {PluggableList | null | undefined} [rehypePlugins]
5558
* List of rehype plugins to use.
5659
* @property {PluggableList | null | undefined} [remarkPlugins]
@@ -60,16 +63,16 @@
6063
* @property {boolean | null | undefined} [skipHtml=false]
6164
* Ignore HTML in markdown completely (default: `false`).
6265
* @property {boolean | null | undefined} [unwrapDisallowed=false]
63-
* Extract (unwrap) the children of not allowed elements (default: `false`);
64-
* normally when say `strong` is disallowed, it and it’s children are dropped,
66+
* Extract (unwrap) what’s in disallowed elements (default: `false`);
67+
* normally when say `strong` is not allowed, it and it’s children are dropped,
6568
* with `unwrapDisallowed` the element itself is replaced by its children.
6669
* @property {UrlTransform | null | undefined} [urlTransform]
6770
* Change URLs (default: `defaultUrlTransform`)
6871
*
6972
* @callback UrlTransform
70-
* Transform URLs.
73+
* Transform all URLs.
7174
* @param {string} url
72-
* URL to transform.
75+
* URL.
7376
* @param {string} key
7477
* Property name (example: `'href'`).
7578
* @param {Readonly<Element>} node
@@ -139,8 +142,7 @@ const deprecations = [
139142
* Component to render markdown.
140143
*
141144
* @param {Readonly<Options>} options
142-
* Configuration (required).
143-
* Note: React types require that props are passed.
145+
* Props.
144146
* @returns {JSX.Element}
145147
* React element.
146148
*/

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"hast-util-to-jsx-runtime": "^2.0.0",
8383
"html-url-attributes": "^3.0.0",
8484
"mdast-util-to-hast": "^13.0.0",
85+
"micromark-util-sanitize-uri": "^2.0.0",
8586
"remark-parse": "^11.0.0",
8687
"remark-rehype": "^11.0.0",
8788
"unified": "^11.0.0",

0 commit comments

Comments
 (0)