Skip to content

Commit debc4d9

Browse files
committed
Add notes about compilers and non-string results
Related to GH-53. Closes GH-47.
1 parent dbb1fc5 commit debc4d9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

readme.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ Compile a syntax tree to text.
464464

465465
###### Returns
466466

467-
`string` — String representation of the syntax tree file.
467+
`string` (see notes) — String representation of the syntax tree file.
468468

469469
###### Note
470470

@@ -473,6 +473,11 @@ Compile a syntax tree to text.
473473
`stringify` does not apply [transformers from the run phase][description]
474474
to the [syntax tree][node].
475475

476+
Be aware that [compiler][]s typically, but not always, return strings.
477+
Some compilers, such as [`rehype-react`][rehype-react], define other values (in
478+
this case, a React tree).
479+
Be aware of this, and when using TypeScript, cast the value on your side.
480+
476481
###### Example
477482

478483
The below example shows how the `stringify` function can be used to generate a
@@ -614,11 +619,18 @@ The process calls `parse`, `run`, and `stringify` internally.
614619

615620
[`Promise`][promise] if `done` is not given.
616621
Rejected with an error or resolved with the resulting file.
622+
The parsed, transformed, and stringified value is exposed on `file.contents`.
617623

618624
###### Note
619625

620626
`process` [freezes][freeze] the processor if not already frozen.
621627

628+
Be aware that [compiler][]s typically, but not always, return strings.
629+
Some compilers, such as [`rehype-react`][rehype-react], define other values (in
630+
this case, a React tree).
631+
Be aware that `file.contents` is not always a string, and when using TypeScript,
632+
cast the value on your side.
633+
622634
###### Example
623635

624636
The below example shows how the `process` function can be used to process a
@@ -1308,3 +1320,5 @@ work on [`ware`][ware], as it was a huge initial inspiration.
13081320
[opensource.guide]: https://opensource.guide
13091321

13101322
[github]: https://github.com
1323+
1324+
[rehype-react]: https://github.com/rhysd/rehype-react

0 commit comments

Comments
 (0)