UNPKG

rehype-smart-links

Version:

A rehype plugin for Astro that adds different styling for internal and external links

39 lines (36 loc) 1.49 kB
import { Root, Element } from 'hast'; import { VFile } from 'vfile'; interface RehypeSmartLinksOptions { content?: { type: string; value: string; }; internalLinkClass?: string; externalLinkClass?: string; brokenLinkClass?: string; contentClass?: string; target?: string; rel?: string; publicDir?: string; routesFile?: string; includeFileExtensions?: string[]; includeAllFiles?: boolean; wrapperTemplate?: (node: Element, type: "internal" | "external" | "broken", className?: string) => Element; customInternalLinkTransform?: (node: Element) => void; customExternalLinkTransform?: (node: Element) => void; customBrokenLinkTransform?: (node: Element) => void; } /** * Generates a routes file by scanning a build directory * @param buildDir The build output directory to scan * @param routesFilePath Path to save the routes file * @param options Additional scan options */ declare function generateRoutesFile(buildDir?: string, routesFilePath?: string, options?: RehypeSmartLinksOptions): void; /** * Rehype plugin to add different styling to internal and external links. * For external links, it adds an arrow icon and sets target="_blank". * For internal links, it checks if the path exists and styles broken links differently. */ declare function rehypeSmartLinks(options?: RehypeSmartLinksOptions): (tree: Root, file: VFile) => void; export { rehypeSmartLinks as default, generateRoutesFile };