import { statSync } from "node:fs"; import { resolve } from "node:path"; import { formatEditorUrl, type SupportedScheme } from "./editor-url"; /** Characters that can trail a prose file reference without being part of it. */ const TRAILING_REFERENCE_PUNCTUATION = new Set([".", ",", ";", ")", "]", "}"]); /** Parses optional line, line range, and column suffixes after a file path. */ const REFERENCE_SUFFIX_REGEX = /^(?.+?):(?[1-9]\d*)(?:(?::(?[1-9]\d*))|-(?[1-9]\d*))?$/u; /** Detects absolute Windows drive paths independent of the host OS. */ const WINDOWS_DRIVE_ABSOLUTE_REGEX = /^[A-Za-z]:[\\/]/u; /** Detects one ASCII letter before checking for Windows drive prefixes. */ const ASCII_LETTER_REGEX = /^[A-Za-z]$/u; /** Detects token boundaries before possible file references. */ const REFERENCE_BOUNDARY_REGEX = /[\s([{<"']/u; /** Detects characters allowed at the start of relative file paths. */ const RELATIVE_PATH_START_CHARACTER_REGEX = /^[\p{L}\p{N}_@+-]$/u; /** Delimiter that starts or ends text that must not be modified. */ const TRIPLE_BACKTICK_DELIMITER = "```"; /** Detects existing Markdown links and images that must not be modified. */ const MARKDOWN_LINK_OR_IMAGE_REGEX = /!?\[(?:[^[\]]|\[[^\]]*\]\([^)]*\))*\]\([^)]*\)/gu; /** Detects existing Markdown links and images with parseable label and target spans. */ const MARKDOWN_LINK_OR_IMAGE_PARSE_REGEX = /(?!)?\[(?