Skip to content

Commit bbabb4a

Browse files
committed
Refactor docs
1 parent ebc5cf9 commit bbabb4a

File tree

4 files changed

+144
-35
lines changed

4 files changed

+144
-35
lines changed

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
2+
* @typedef {import('./lib/index.js').Handler} Handler
23
* @typedef {import('./lib/index.js').Options} Options
34
*/
45

lib/index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Transform a node.
1717
* @param {any} node
1818
* Node.
19-
* @returns {Array<Nodes> | Nodes | undefined}
19+
* @returns {Array<Nodes> | Nodes | null | undefined}
2020
* Result.
2121
*
2222
* @typedef {Partial<Record<Nodes['type'], Handler>>} Handlers
@@ -73,6 +73,11 @@ const emptyTypes = []
7373
/**
7474
* Remove markdown formatting.
7575
*
76+
* * remove `code`, `html`, `horizontalRule`, `table`, `toml`, `yaml`, and
77+
* their content
78+
* * render everything else as simple paragraphs without formatting
79+
* * uses `alt` text for images
80+
*
7681
* @param {Readonly<Options> | null | undefined} [options]
7782
* Configuration (optional).
7883
* @returns
@@ -153,9 +158,9 @@ export default function stripMarkdown(options) {
153158
/** @type {Array<Nodes> | Nodes | undefined} */
154159
let result = node
155160

156-
if (type in map) {
161+
if (Object.hasOwn(map, type)) {
157162
const handler = map[type]
158-
if (handler) result = handler(result)
163+
if (handler) result = handler(result) || undefined
159164
}
160165

161166
result = Array.isArray(result) ? all(result) : result

package.json

+12-4
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@
3535
"index.js"
3636
],
3737
"dependencies": {
38-
"@types/mdast": "^4.0.0",
39-
"unified": "^11.0.0"
38+
"@types/mdast": "^4.0.0"
4039
},
4140
"devDependencies": {
4241
"@types/node": "^20.0.0",
4342
"@types/unist": "^3.0.0",
4443
"c8": "^8.0.0",
4544
"prettier": "^3.0.0",
4645
"remark": "^15.0.0",
47-
"remark-cli": "^11.0.0",
46+
"remark-cli": "^12.0.0",
4847
"remark-directive": "^3.0.0",
4948
"remark-gfm": "^4.0.0",
5049
"remark-preset-wooorm": "^9.0.0",
@@ -70,7 +69,16 @@
7069
},
7170
"remarkConfig": {
7271
"plugins": [
73-
"remark-preset-wooorm"
72+
"remark-preset-wooorm",
73+
[
74+
"remark-lint-list-item-indent",
75+
"space"
76+
],
77+
[
78+
"remark-preset-wooorm/node_modules/remark-gfm/index.js",
79+
false
80+
],
81+
"remark-gfm"
7482
]
7583
},
7684
"typeCoverage": {

readme.md

+123-28
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,60 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
[**remark**][remark] plugin remove markdown formatting.
12-
This essentially removes everything but paragraphs and text nodes.
11+
**[remark][]** plugin to remove markdown formatting.
12+
This essentially removes everything but paragraphs and text.
1313

1414
> This is one of the first remark plugins, before prefixing with `remark-` got
1515
> cool.
1616
17-
## Note!
17+
## Contents
1818

19-
This plugin is ready for the new parser in remark
20-
([`remarkjs/remark#536`](https://github.com/remarkjs/remark/pull/536)).
21-
No change is needed: it works exactly the same now as it did before!
19+
* [What is this?](#what-is-this)
20+
* [When should I use this?](#when-should-i-use-this)
21+
* [Install](#install)
22+
* [Use](#use)
23+
* [API](#api)
24+
* [`unified().use(stripMarkdown[, options])`](#unifiedusestripmarkdown-options)
25+
* [`Handler`](#handler)
26+
* [`Options`](#options)
27+
* [Types](#types)
28+
* [Compatibility](#compatibility)
29+
* [Security](#security)
30+
* [Contribute](#contribute)
31+
* [License](#license)
2232

23-
## Install
33+
## What is this?
34+
35+
This package is a [unified][] ([remark][]) plugin to remove most nodes so as to
36+
just leave text.
37+
38+
## When should I use this?
2439

25-
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
26-
Node 16+ is needed to use it and it must be `import`ed instead of `require`d.
40+
You can use this if you want to ignore the syntax of markdown.
2741

28-
[npm][]:
42+
## Install
43+
44+
This package is [ESM only][esm].
45+
In Node.js (version 16+), install with [npm][]:
2946

3047
```sh
3148
npm install strip-markdown
3249
```
3350

51+
In Deno with [`esm.sh`][esmsh]:
52+
53+
```js
54+
import stripMarkdown from 'https://esm.sh/strip-markdown@5'
55+
```
56+
57+
In browsers with [`esm.sh`][esmsh]:
58+
59+
```html
60+
<script type="module">
61+
import stripMarkdown from 'https://esm.sh/strip-markdown@5?bundle'
62+
</script>
63+
```
64+
3465
## Use
3566

3667
```js
@@ -53,22 +84,70 @@ Some emphasis, importance, and code.
5384
## API
5485

5586
This package exports no identifiers.
56-
The default export is `stripMarkdown`.
87+
The default export is [`stripMarkdown`][api-strip-markdown].
5788

5889
### `unified().use(stripMarkdown[, options])`
5990

60-
Plugin to remove markdown formatting.
91+
Remove markdown formatting.
92+
93+
* remove `code`, `html`, `horizontalRule`, `table`, `toml`, `yaml`, and
94+
their content
95+
* render everything else as simple paragraphs without formatting
96+
* uses `alt` text for images
97+
98+
###### Parameters
99+
100+
* `option` ([`Options`][api-options], optional)
101+
— configuration
102+
103+
###### Returns
104+
105+
Transform ([`Transformer`][unified-transformer]).
106+
107+
### `Handler`
108+
109+
Transform a node (TypeScript type).
110+
111+
###### Parameters
112+
113+
* `node` ([`Node`][mdast-node])
114+
— node
115+
116+
###### Returns
117+
118+
Result (`Array<Node>` or `Node`).
61119

62-
* Removes `html` ([*note*][gh-19]), `code`, `horizontalRule`, `table`, `yaml`,
63-
`toml`, and their content
64-
* Render everything else as simple paragraphs without formatting
65-
* Uses `alt` text for images
120+
### `Options`
121+
122+
Configuration (TypeScript type).
123+
124+
###### Fields
125+
126+
* `keep` (`Array<string>`, optional)
127+
— list of node types to leave unchanged
128+
* `remove` (`Array<[string, Handler] | string>`, optional)
129+
— list of node types to remove (or replace, with handlers)
130+
131+
## Types
132+
133+
This package is fully typed with [TypeScript][].
134+
It exports the additional types [`Handler`][api-handler] and
135+
[`Options`][api-options].
136+
137+
## Compatibility
138+
139+
Projects maintained by the unified collective are compatible with maintained
140+
versions of Node.js.
141+
142+
When we cut a new major release, we drop support for unmaintained versions of
143+
Node.
144+
This means we try to keep the current release line, `strip-markdown@5`,
145+
compatible with Node.js 12.
66146

67147
## Security
68148

69-
Use of `strip-markdown` does not involve [**rehype**][rehype] ([**hast**][hast])
70-
or user content so there are no openings for [cross-site scripting (XSS)][xss]
71-
attacks.
149+
Use of `strip-markdown` does not involve **[rehype][]** (**[hast][]**) or user
150+
content so there are no openings for [cross-site scripting (XSS)][xss] attacks.
72151

73152
## Contribute
74153

@@ -98,9 +177,9 @@ abide by its terms.
98177

99178
[downloads]: https://www.npmjs.com/package/strip-markdown
100179

101-
[size-badge]: https://img.shields.io/bundlephobia/minzip/strip-markdown.svg
180+
[size-badge]: https://img.shields.io/bundlejs/size/strip-markdown
102181

103-
[size]: https://bundlephobia.com/result?p=strip-markdown
182+
[size]: https://bundlejs.com/?q=strip-markdown
104183

105184
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
106185

@@ -114,24 +193,40 @@ abide by its terms.
114193

115194
[npm]: https://docs.npmjs.com/cli/install
116195

196+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
197+
198+
[esmsh]: https://esm.sh
199+
117200
[health]: https://github.com/remarkjs/.github
118201

119-
[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md
202+
[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
203+
204+
[support]: https://github.com/remarkjs/.github/blob/main/support.md
120205

121-
[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md
206+
[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md
122207

123-
[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md
208+
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
124209

125210
[license]: license
126211

127212
[author]: https://wooorm.com
128213

129-
[remark]: https://github.com/remarkjs/remark
214+
[hast]: https://github.com/syntax-tree/hast
130215

131-
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
216+
[mdast-node]: https://github.com/syntax-tree/mdast#nodes
132217

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

135-
[hast]: https://github.com/syntax-tree/hast
220+
[remark]: https://github.com/remarkjs/remark
221+
222+
[typescript]: https://www.typescriptlang.org
223+
224+
[unified]: https://github.com/unifiedjs/unified
225+
226+
[unified-transformer]: https://github.com/unifiedjs/unified#transformer
227+
228+
[api-handler]: #handler
229+
230+
[api-options]: #options
136231

137-
[gh-19]: https://github.com/remarkjs/strip-markdown/issues/19
232+
[api-strip-markdown]: #unifiedusestripmarkdown-options

0 commit comments

Comments
 (0)