remark-lint-media-style

raw JSON →
1.0.1 verified Fri May 01 auth: no javascript

Remark-lint rule to enforce consistent style for image and link URLs, either references (defined elsewhere) or resources (inline URLs). Current stable version is 1.0.1, part of the remark-lint monorepo. It supports three modes: 'consistent' (auto-detect first usage), 'reference', 'resource', and 'reference-reuse' (allow resources if used once). Only ESM, requires Node.js 16+. TypeScript types exported.

error TypeError: remarkLintMediaStyle is not a function
cause Attempting to use require() or import incorrectly due to ESM-only.
fix
Use import remarkLintMediaStyle from 'remark-lint-media-style' in an ESM context.
error SyntaxError: Unexpected token 'export'
cause Running CommonJS environment with ESM-only package.
fix
Set "type": "module" in package.json or use .mjs extension.
gotcha The 'consistent' option cannot detect 'reference-reuse' style; the first style used will be enforced.
fix Manually set the style to 'reference-reuse' if that behavior is desired.
breaking Package is ESM-only and cannot be required() with CommonJS.
fix Use dynamic import() or switch to ESM.
deprecated This rule does not automatically detect reference reuse; 'reference-reuse' option was added explicitly.
fix Use 'reference-reuse' instead of expecting automatic detection.
npm install remark-lint-media-style
yarn add remark-lint-media-style
pnpm add remark-lint-media-style

Shows ESM usage with unified, remark-lint, and the media-style rule configured to prefer resource-style URLs.

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

const file = await read('example.md');
await unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintMediaStyle, {style: 'resource'})
  .use(remarkStringify)
  .process(file);
console.error(reporter(file));