Skip to content

Commit 4806d91

Browse files
authored
Fix Usage as a remark plugin without Gatsby example code (#229)
* Fix Usage as a remark plugin without Gatsby example code The example in the Usage as a remark plugin without Gatsby does not compile as is: - Top-level await only available in ES Modules but used here with require() – decided to go with the former and use imports - Backticks not escaped in template string - Incorrect module name (`remarkParse` should be `remark-parse`) - Incorrect property reference in result returned from processor (`contents` should be `value`) I also added the npm install line required and a suggestion of the file name to use (including _.mjs_ extension) to make it easier to follow and avoid possible trip-ups. * Remove log statement
1 parent 827997f commit 4806d91

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

Diff for: README.md

+19-11
Original file line numberDiff line numberDiff line change
@@ -557,24 +557,32 @@ Line numbers and ranges aren’t the only things you can pass as options on your
557557

558558
### Usage as a remark plugin without Gatsby
559559

560-
This package exports a `remarkPlugin` property that accepts the same [options](#options-reference) as the main Gatsby plugin and is usable as a [remark](https://github.com/remarkjs/remark) plugin in any [unifiedjs](https://github.com/unifiedjs/unified) processing pipeline:
560+
This package exports a `remarkPlugin` property that accepts the same [options](#options-reference) as the main Gatsby plugin and is usable as a [remark](https://github.com/remarkjs/remark) plugin in any [unifiedjs](https://github.com/unifiedjs/unified) processing pipeline.
561+
562+
First, install the required dependencies:
563+
564+
```shell
565+
npm install unified remark-parse gatsby-remark-vscode remark-rehype rehype-raw rehype-stringify
566+
```
567+
568+
Then, in an ES Module file, e.g., index.mjs:
561569

562570
````js
563-
const unified = require('unified');
564-
const remarkParse = require('remarkParse');
565-
const remarkVscode = require('gatsby-remark-vscode');
566-
const remarkToRehype = require('remark-rehype');
567-
const rehypeRaw = require('rehype-raw');
568-
const rehypeStringify = require('rehype-stringify');
571+
import { unified } from 'unified'
572+
import remarkParse from 'remark-parse'
573+
import remarkVscode from 'gatsby-remark-vscode'
574+
import remarkToRehype from 'remark-rehype'
575+
import rehypeRaw from 'rehype-raw'
576+
import rehypeStringify from 'rehype-stringify'
569577

570578
const markdownSource = `
571579
# Code example with awesome syntax highlighting
572580
573-
```ts {numberLines}
581+
\`\`\`ts {numberLines}
574582
export function sum(a: number, b: number): number {
575583
return a + b;
576584
}
577-
```
585+
\`\`\`
578586
579587
This is a paragraph after the code example.
580588
`
@@ -597,7 +605,7 @@ const processor = unified()
597605
});
598606

599607
const vfile = await processor.process(markdownSource);
600-
console.log(vfile.contents); // logs resulting HTML
608+
console.log(vfile.value); // logs resulting HTML
601609
````
602610

603611
## Options reference
@@ -716,4 +724,4 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for development instructions.
716724
[line-numbering-with-code-fence-info]: https://user-images.githubusercontent.com/3277153/87122757-5ea53b00-c23a-11ea-8fbc-c85917433345.png
717725
[line-numbering-with-both]: https://user-images.githubusercontent.com/3277153/87122755-5ea53b00-c23a-11ea-8fe8-144aea7aa952.png
718726
[line-numbering-starting-line]: https://user-images.githubusercontent.com/3277153/87122747-5c42e100-c23a-11ea-9a06-923c699c0a0b.png
719-
[diff-highlighting]: https://user-images.githubusercontent.com/3277153/87123984-aa58e400-c23c-11ea-87b3-3f66afcd795d.png
727+
[diff-highlighting]: https://user-images.githubusercontent.com/3277153/87123984-aa58e400-c23c-11ea-87b3-3f66afcd795d.png

0 commit comments

Comments
 (0)