UNPKG

remark-validate-links

Version:

remark plugin to validate links to headings and files

191 lines 5.29 kB
/** * Check that markdown links and images point to existing local files and * headings in a Git repo. * * > ⚠️ **Important**: The API in Node.js checks links to headings and files * > but does not check whether headings in other files exist. * > The API in browsers only checks links to headings in the same file. * > The CLI can check everything. * * @param {Readonly<Options> | null | undefined} [options] * Configuration (optional). * @param {FileSet | null | undefined} [fileSet] * File set (optional). * @returns * Transform. */ export default function remarkValidateLinks(options?: Readonly<Options> | null | undefined, fileSet?: FileSet | null | undefined): (tree: Root, file: VFile) => Promise<void>; /** * Landmarks. */ export type Landmarks = Map<string, Map<string, boolean>>; /** * Configuration. */ export type Options = { /** * URL to hosted Git (default: detected from Git remote); * if you’re not in a Git repository, you must pass `false`; * if the repository resolves to something npm understands as a Git host such * as GitHub, GitLab, or Bitbucket, full URLs to that host (say, * `https://github.com/remarkjs/remark-validate-links/readme.md#install`) are * checked. */ repository?: string | false | null | undefined; /** * Path to Git root folder (default: local Git folder); * if both `root` and `repository` are nullish, the Git root is detected; * if `root` is not given but `repository` is, `file.cwd` is used. */ root?: string | null | undefined; /** * List of patterns for *paths* that should be skipped; * each absolute local path + hash will be tested against each pattern and * will be ignored if `new RegExp(pattern).test(value) === true`; * example value are then `/Users/tilde/path/to/repo/readme.md#some-heading`. */ skipPathPatterns?: ReadonlyArray<RegExp | string> | null | undefined; /** * Config on how hosted Git works (default: detected from repo); * `github.com`, `gitlab.com`, or `bitbucket.org` work automatically; * otherwise, pass `urlConfig` manually. */ urlConfig?: Readonly<UrlConfig> | null | undefined; }; export type Propose = (value: string, dictionary: ReadonlyArray<string>, options?: Readonly<ProposeOptions> | null | undefined) => string | undefined; /** * Configuration for `propose`. */ export type ProposeOptions = { /** * Threshold. */ threshold?: number | null | undefined; }; /** * Reference to something. */ export type Reference = { /** * Path to file. */ filePath: string; /** * Hash. */ hash: string | undefined; }; /** * Info on a reference. */ export type ReferenceInfo = { /** * File. */ file: VFile; /** * Reference. */ reference: Readonly<Reference>; /** * Nodes that reference it. */ nodes: ReadonlyArray<Readonly<Resources>>; }; /** * Resources. */ export type Resources = Extract<Nodes, Resource>; /** * Info passed around. */ export type State = { /** * Folder of file. */ base: string; /** * Path to file. */ path: string; /** * Path to Git folder. */ root: string | null | undefined; /** * List of patterns for paths that should be skipped. */ skipPathPatterns: ReadonlyArray<RegExp>; /** * Configuration. */ urlConfig: Readonly<UrlConfig>; }; /** * Hosted Git info. * * ###### Notes * * For this repository (`remarkjs/remark-validate-links` on GitHub) * `urlConfig` looks as follows: * * ```js * { * // Domain of URLs: * hostname: 'github.com', * // Path prefix before files: * prefix: '/remarkjs/remark-validate-links/blob/', * // Prefix of headings: * headingPrefix: '#', * // Hash to top of markdown documents: * topAnchor: '#readme', * // Whether lines in files can be linked: * lines: true * } * ``` * * If this project were hosted on Bitbucket, it would be: * * ```js * { * hostname: 'bitbucket.org', * prefix: '/remarkjs/remark-validate-links/src/', * headingPrefix: '#markdown-header-', * lines: false * } * ``` */ export type UrlConfig = { /** * Prefix of headings (example: `'#'`, `'#markdown-header-'`). */ headingPrefix?: string | null | undefined; /** * Domain of URLs (example: `'github.com'`, `'bitbucket.org'`). */ hostname?: string | null | undefined; /** * Whether absolute paths (`/x/y/z.md`) resolve relative to a repo. */ resolveAbsolutePathsInRepo?: boolean | null | undefined; /** * Whether lines in files can be linked. */ lines?: boolean | null | undefined; /** * Path prefix before files (example: * `'/remarkjs/remark-validate-links/blob/'`, * `'/remarkjs/remark-validate-links/src/'`). */ prefix?: string | null | undefined; /** * Hash to top of readme (example: `#readme`). */ topAnchor?: string | null | undefined; }; import type { FileSet } from 'unified-engine'; import type { Root } from 'mdast'; import { VFile } from 'vfile'; import type { Nodes } from 'mdast'; import type { Resource } from 'mdast'; //# sourceMappingURL=index.d.ts.map