Skip to content

Commit 36198e8

Browse files
committed
docs: api
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 2065353 commit 36198e8

File tree

3 files changed

+65
-17
lines changed

3 files changed

+65
-17
lines changed

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
- [Install](#install)
2020
- [Use](#use)
2121
- [API](#api)
22+
- [`fromDocs(value[, options])`](#fromdocsvalue-options)
23+
- [`Options`](#options)
24+
- [`Transform`](#transform)
2225
- [Syntax](#syntax)
2326
- [Docblock](#docblock)
2427
- [Markdown](#markdown)
@@ -306,7 +309,47 @@ root[9]
306309

307310
## API
308311

309-
**TODO**: api
312+
This package exports the identifier [`fromDocs`](#fromdocsvalue-options). There is no default export.
313+
314+
### `fromDocs(value[, options])`
315+
316+
Turn docblocks into a syntax tree.
317+
318+
#### Parameters
319+
320+
- `value` ([`VFile`][vfile] | `string`) &mdash; source document or file containing docblocks to parse
321+
- `options` ([`Options`](#options), optional) &mdash; configuration options
322+
323+
#### Returns
324+
325+
docast tree ([`Root`][docast-tree])
326+
327+
### `Options`
328+
329+
Configuration options (TypeScript type).
330+
331+
#### Properties
332+
333+
- `codeblocks` (`OneOrMany<RegExp | string>`, optional) &mdash; block tag node names and tags, or regular
334+
expressions, matching block tags that should have their text converted to [`Code`][mdast-code] when parsed as markdown
335+
- **default**: `'example'`
336+
- `mdastExtensions` ([`MdastExtension[]`][mdast-util-extension], optional) &mdash; markdown extensions to change how
337+
micromark tokens are converted to nodes
338+
- `micromarkExtensions` ([`MicromarkExtension[]`][micromark-extension], optional) &mdash; micromark extensions to change
339+
how markdown is parsed
340+
- `transforms` ([`Transform[]`](#transform), optional) &mdash; tree transforms
341+
342+
### `Transform`
343+
344+
Change the AST after parsing is complete (TypeScript type).
345+
346+
#### Parameters
347+
348+
- `tree` ([`Root`][docast-tree]) &mdash; tree to transform
349+
350+
#### Returns
351+
352+
Nothing
310353

311354
## Syntax
312355

@@ -333,10 +376,15 @@ This package is fully typed with [TypeScript][typescript].
333376
See [`CONTRIBUTING.md`](CONTRIBUTING.md).
334377

335378
[docast-parse]: https://github.com/flex-development/docast-parse
379+
[docast-tree]: https://github.com/flex-development/docast#root
336380
[docast]: https://github.com/flex-development/docast
337381
[docblock]: https://github.com/flex-development/docast#docblock-comment
338382
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
383+
[mdast-code]: https://github.com/syntax-tree/mdast#code
384+
[mdast-util-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension
339385
[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
386+
[micromark-extension]: https://github.com/micromark/micromark#extensions
340387
[micromark]: https://github.com/micromark/micromark
341388
[typescript]: https://www.typescriptlang.org
342389
[unified]: https://github.com/unifiedjs/unified
390+
[vfile]: https://github.com/vfile/vfile#api

src/interfaces/__tests__/options.spec-d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import type { Transform } from '#src/types'
77
import type { Nilable, OneOrMany } from '@flex-development/tutils'
8-
import type * as mdast from 'mdast-util-from-markdown'
9-
import type * as micromark from 'micromark-util-types'
8+
import type { Extension as MdastExtension } from 'mdast-util-from-markdown'
9+
import type { Extension as MicromarkExtension } from 'micromark-util-types'
1010
import type TestSubject from '../options'
1111

1212
describe('unit-d:interfaces/Options', () => {
@@ -16,16 +16,16 @@ describe('unit-d:interfaces/Options', () => {
1616
.toEqualTypeOf<Nilable<OneOrMany<RegExp | string>>>()
1717
})
1818

19-
it('should match [mdastExtensions?: Nilable<mdast.Extension[]>]', () => {
19+
it('should match [mdastExtensions?: Nilable<MdastExtension[]>]', () => {
2020
expectTypeOf<TestSubject>()
2121
.toHaveProperty('mdastExtensions')
22-
.toEqualTypeOf<Nilable<mdast.Extension[]>>()
22+
.toEqualTypeOf<Nilable<MdastExtension[]>>()
2323
})
2424

25-
it('should match [micromarkExtensions?: Nilable<micromark.Extension[]>]', () => {
25+
it('should match [micromarkExtensions?: Nilable<MicromarkExtension[]>]', () => {
2626
expectTypeOf<TestSubject>()
2727
.toHaveProperty('micromarkExtensions')
28-
.toEqualTypeOf<Nilable<micromark.Extension[]>>()
28+
.toEqualTypeOf<Nilable<MicromarkExtension[]>>()
2929
})
3030

3131
it('should match [transforms?: Nilable<Transform[]>]', () => {

src/interfaces/options.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import type { Transform } from '#src/types'
77
import type { Nilable, OneOrMany } from '@flex-development/tutils'
88
import type { Code } from 'mdast'
9-
import type * as mdast from 'mdast-util-from-markdown'
10-
import type * as micromark from 'micromark-util-types'
9+
import type { Extension as MdastExtension } from 'mdast-util-from-markdown'
10+
import type { Extension as MicromarkExtension } from 'micromark-util-types'
1111

1212
/**
13-
* Parser options.
13+
* Configuration options.
1414
*/
1515
interface Options {
1616
/**
@@ -23,20 +23,20 @@ interface Options {
2323
codeblocks?: Nilable<OneOrMany<RegExp | string>>
2424

2525
/**
26-
* Extensions to change how mdast tokens are converted to syntax tree nodes.
26+
* Markdown extensions to change how micromark tokens are converted to nodes.
2727
*
28-
* @see {@linkcode mdast.Extension}
29-
* @see https://github.com/syntax-tree/mdast-util-from-markdown
28+
* @see {@linkcode MdastExtension}
29+
* @see https://github.com/syntax-tree/mdast-util-from-markdown#list-of-extensions
3030
*/
31-
mdastExtensions?: Nilable<mdast.Extension[]>
31+
mdastExtensions?: Nilable<MdastExtension[]>
3232

3333
/**
34-
* Markdown syntax extensions.
34+
* Micromark extensions to change how markdown is parsed.
3535
*
36-
* @see {@linkcode micromark.Extension}
36+
* @see {@linkcode MicromarkExtension}
3737
* @see https://github.com/micromark/micromark#extensions
3838
*/
39-
micromarkExtensions?: Nilable<micromark.Extension[]>
39+
micromarkExtensions?: Nilable<MicromarkExtension[]>
4040

4141
/**
4242
* Tree transforms.

0 commit comments

Comments
 (0)