Skip to content

Commit

Permalink
Refactor examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jan 7, 2025
1 parent b89bb82 commit f9a5e87
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
20 changes: 10 additions & 10 deletions packages/remark-cli/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ npm install remark-cli
Add a table of contents with [`remark-toc`][remark-toc] to `readme.md`:

```sh
remark readme.md --output --use remark-toc
remark --output --use remark-toc readme.md
```

Lint all markdown files in the current directory according to the markdown style
guide with [`remark-preset-lint-markdown-style-guide`][markdown-style-guide].

```sh
remark . --use remark-preset-lint-markdown-style-guide
remark --use remark-preset-lint-markdown-style-guide .
```

## CLI
Expand Down Expand Up @@ -141,7 +141,7 @@ It assumes you’re in a Node.js package.
Install the CLI and plugins:

```sh
npm install remark-cli remark-preset-lint-consistent remark-preset-lint-recommended remark-toc --save-dev
npm install --save-dev remark-cli remark-preset-lint-consistent remark-preset-lint-recommended remark-toc
```

…then add an npm script in your `package.json`:
Expand Down Expand Up @@ -215,16 +215,16 @@ import remarkPresetLintRecommended from 'remark-preset-lint-recommended'
import remarkToc from 'remark-toc'

const remarkConfig = {
settings: {
bullet: '*', // Use `*` for list item bullets (default)
// See <https://github.com/remarkjs/remark/tree/main/packages/remark-stringify> for more options.
},
plugins: [
remarkPresetLintConsistent, // Check that markdown is consistent.
remarkPresetLintRecommended, // Few recommended rules.
// Generate a table of contents in `## Contents`
[remarkToc, {heading: 'contents'}]
]
],
settings: {
bullet: '*' // Use `*` for list item bullets (default)
// See <https://github.com/remarkjs/remark/tree/main/packages/remark-stringify> for more options.
}
}

export default remarkConfig
Expand All @@ -233,8 +233,6 @@ export default remarkConfig
This is the same configuration in YAML, which can be placed in `.remarkrc.yml`:

```yml
settings:
bullet: "*"
plugins:
# Check that markdown is consistent.
- remark-preset-lint-consistent
Expand All @@ -243,6 +241,8 @@ plugins:
# Generate a table of contents in `## Contents`
- - remark-toc
- heading: contents
settings:
bullet: "*"
```
When `remark-cli` is about to process a markdown file it’ll search the file
Expand Down
6 changes: 3 additions & 3 deletions packages/remark-parse/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'

const doc = `
const value = `
# Mercury
**Mercury** is the first planet from the [Sun](https://en.wikipedia.org/wiki/Sun)
Expand All @@ -106,7 +106,7 @@ const file = await unified()
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeStringify)
.process(doc)
.process(value)

console.log(String(file))
```
Expand Down Expand Up @@ -208,7 +208,7 @@ console.log(String(file))
Yields:

```roff
.TH "TITAN" "7" "September 2023" "" ""
.TH "TITAN" "7" "January 2025" "" ""
.SH "NAME"
\fBtitan\fR - largest moon of saturn
.P
Expand Down
4 changes: 2 additions & 2 deletions packages/remark-stringify/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import rehypeRemark from 'rehype-remark'
import remarkStringify from 'remark-stringify'
import {unified} from 'unified'

const doc = `
const value = `
<h1>Uranus</h1>
<p><b>Uranus</b> is the seventh
<a href="/wiki/Planet" title="Planet">planet</a> from the Sun and is a gaseous
Expand All @@ -103,7 +103,7 @@ const file = await unified()
.use(rehypeParse)
.use(rehypeRemark)
.use(remarkStringify)
.process(doc)
.process(value)

console.log(String(file))
```
Expand Down
21 changes: 10 additions & 11 deletions packages/remark/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Say we have the following module `example.js`:
import {remark} from 'remark'
import remarkToc from 'remark-toc'

const doc = `
const value = `
# Pluto
Pluto is a dwarf planet in the Kuiper belt.
Expand All @@ -109,9 +109,7 @@ Once Pluto was found, its faintness and lack of a viewable disc cast doubt…
Pluto's orbital period is about 248 years…
`

const file = await remark()
.use(remarkToc, {heading: 'contents', tight: true})
.process(doc)
const file = await remark().use(remarkToc, {tight: true}).process(value)

console.error(String(file))
```
Expand Down Expand Up @@ -187,12 +185,13 @@ console.error(reporter(file))
Yields:

```txt
warning Missing newline character at end of file final-newline remark-lint
1:1-1:35 warning Marker style should be `.` ordered-list-marker-style remark-lint
1:4 warning Incorrect list-item indent: add 1 space list-item-indent remark-lint
1:25-1:34 warning Emphasis should use `_` as a marker emphasis-marker remark-lint
1:2 warning Unexpected ordered list marker `)`, expected `.` ordered-list-marker-style remark-lint
1:25-1:34 warning Unexpected emphasis marker `*`, expected `_` emphasis-marker remark-lint
[cause]:
1:11-1:20 info Emphasis marker style `'_'` first defined for `'consistent'` here emphasis-marker remark-lint
1:35 warning Unexpected missing final newline character, expected line feed (`\n`) at end of file final-newline remark-lint
4 warnings
3 warnings
```

### Example: passing options to `remark-stringify`
Expand All @@ -205,7 +204,7 @@ To define options for `remark-stringify`, you can instead pass options to
```js
import {remark} from 'remark'

const doc = `
const value = `
# Moons of Neptune
1. Naiad
Expand All @@ -220,7 +219,7 @@ const file = await remark()
incrementListMarker: false,
setext: true
})
.process(doc)
.process(value)

console.log(String(file))
```
Expand Down
17 changes: 9 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'

const doc = `---
const value = `---
layout: solar-system
---
Expand All @@ -266,7 +266,7 @@ const file = await unified()
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeStringify)
.process(doc)
.process(value)

console.log(String(file))
```
Expand Down Expand Up @@ -299,12 +299,13 @@ console.error(reporter(file))
Yields:

```txt
warning Missing newline character at end of file final-newline remark-lint
1:1-1:35 warning Marker style should be `.` ordered-list-marker-style remark-lint
1:4 warning Incorrect list-item indent: add 1 space list-item-indent remark-lint
1:25-1:34 warning Emphasis should use `_` as a marker emphasis-marker remark-lint
1:2 warning Unexpected ordered list marker `)`, expected `.` ordered-list-marker-style remark-lint
1:25-1:34 warning Unexpected emphasis marker `*`, expected `_` emphasis-marker remark-lint
[cause]:
1:11-1:20 info Emphasis marker style `'_'` first defined for `'consistent'` here emphasis-marker remark-lint
1:35 warning Unexpected missing final newline character, expected line feed (`\n`) at end of file final-newline remark-lint
4 warnings
3 warnings
```

### Example: checking and formatting markdown on the CLI
Expand All @@ -316,7 +317,7 @@ This example assumes you’re in a Node.js package.
First, install the CLI and plugins:

```sh
npm install remark-cli remark-preset-lint-consistent remark-preset-lint-recommended remark-toc --save-dev
npm install --save-dev remark-cli remark-preset-lint-consistent remark-preset-lint-recommended remark-toc
```

…then add an npm script in your `package.json`:
Expand Down

0 comments on commit f9a5e87

Please sign in to comment.