remark-lint-media-style
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

remark-lint-media-style

Build Coverage Downloads Size Sponsors Backers Chat

remark-lint rule to warn when the style of specifying the URL of images and links is incorrect.

Contents

What is this?

This package checks for media (image and link) style: whether references or resources are used.

When should I use this?

You can use this package to check that the style of specifying the URL of images and links is correct.

Presets

This plugin is not included in presets maintained here.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install remark-lint-media-style

In Deno with esm.sh:

import remarkLintMediaStyle from 'https://esm.sh/remark-lint-media-style@1'

In browsers with esm.sh:

<script type="module">
  import remarkLintMediaStyle from 'https://esm.sh/remark-lint-media-style@1?bundle'
</script>

Use

On the API:

import remarkLint from 'remark-lint'
import remarkLintMediaStyle from 'remark-lint-media-style'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import {read} from 'to-vfile'
import {unified} from 'unified'
import {reporter} from 'vfile-reporter'

const file = await read('example.md')

await unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintMediaStyle)
  .use(remarkStringify)
  .process(file)

console.error(reporter(file))

On the CLI:

remark --frail --use remark-lint --use remark-lint-media-style .

On the CLI in a config file (here a package.json):

 …
 "remarkConfig": {
   "plugins": [
     …
     "remark-lint",
+    "remark-lint-media-style",
     …
   ]
 }
 …

API

This package exports no identifiers. It exports the TypeScript types Options and Style. The default export is remarkLintMediaStyle.

unified().use(remarkLintMediaStyle[, options])

Warn when the style of specifying the URL of images and links is incorrect.

Parameters
  • options (Options, default: 'consistent') — preferred style or whether to detect the first style and warn for further differences
Returns

Transform (Transformer from unified).

Options

Configuration (TypeScript type).

  • 'consistent' — detect the first used style and warn when further rules differ; “reference-reuse” cannot be detected
  • Style — style to prefer

Style

Style (TypeScript type).

  • 'reference' — prefer references
  • 'reference-reuse' — allow resources when used once, prefer references otherwise
  • 'resource' — prefer resources

Examples

ok-consistent-reference.md
In
[Mercury][] and [Venus][].

[mercury]: https://example.com/mercury/
[venus]: https://example.com/venus/
Out

No messages.

ok-consistent-resource.md
In
[Mercury](https://example.com/mercury/) and
[Venus](https://example.com/venus/).
Out

No messages.

ok-reference-reuse.md

When configured with 'reference-reuse'.

In
[Mercury](https://example.com/mercury/),
[Venus][], and [Earth][].

**[Venus][]** is the second planet from the Sun.

[venus]: https://example.com/venus/
[earth]: https://example.com/earth/
Out

No messages.

nok-reference.md

When configured with 'reference'.

In
[Mercury](https://example.com/mercury/),
[Venus](https://example.com/venus/), and
[Earth][].

[earth]: https://example.com/earth/
Out
1:1-1:40: Unexpected resource for url `https://example.com/mercury/`, expected a definition and a reference to it
2:1-2:36: Unexpected resource for url `https://example.com/venus/`, expected a definition and a reference to it
nok-resource.md

When configured with 'resource'.

In
[Mercury](https://example.com/mercury/),
[Venus](https://example.com/venus/), and
[Earth][].

[earth]: https://example.com/earth/
Out
3:1-3:10: Unexpected reference for url `https://example.com/earth/`, expected resource
nok-reference-reuse.md

When configured with 'reference-reuse'.

In
[Mercury](https://example.com/mercury/),
[Venus](https://example.com/venus/), and [Earth][].

**[Venus](https://example.com/venus/)** is the second planet from the Sun.

[earth]: https://example.com/earth/
Out
2:1-2:36: Unexpected resource for reused url `https://example.com/venus/`, expected a definition and a reference to it
4:3-4:38: Unexpected resource for reused url `https://example.com/venus/`, expected a definition and a reference to it
reference-reuse-defined.md

When configured with 'reference-reuse'.

In
[Mercury](https://example.com/mercury/).

[mercury]: https://example.com/mercury/
Out
1:1-1:40: Unexpected resource for reused url `https://example.com/mercury/`, expected a reference to `mercury`
not-ok.md

When configured with '🌍'.

Out
1:1: Unexpected value `🌍` for `options`, expected `'reference-reuse'`, `'reference'`, `'resource'`, or `'consistent'`
definitions.md
In
[mercury]: https://example.com/mercury/
[venus]: https://example.com/venus/
Out

No messages.

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, remark-lint-media-style@1, compatible with Node.js 16.

Contribute

See contributing.md in remarkjs/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

Package Sidebar

Install

npm i remark-lint-media-style

Weekly Downloads

340

Version

1.0.1

License

MIT

Unpacked Size

19.7 kB

Total Files

5

Last publish

Collaborators

  • wooorm