Main¶
Top-level package exports: Config,
MarkdownPath,
MarkdownURL,
MarkdownLinkBase, main, and
__version__. Documented canonically under Models, CLI,
and Checker; shown here without indexing to avoid duplicate targets.
markdown-checker - a markdown link validation reporting tool.
- class markdown_checker.Config(skip_domains=<factory>, skip_urls_containing=<factory>, tracking_domains=<factory>, timeout=20, retries=3, retry_on_429=True, fallback_retry_delay=30, max_workers=10, per_host_delay=0.5, max_pending=200, output_mode='local')
Holds all runtime configuration for a check run.
- Parameters:
- skip_domains: list[str]
Hostnames to exclude from URL checks (substring match against the URL’s hostname). Used by
check_broken_urlsandcheck_urls_locale.
- skip_urls_containing: list[str]
Substrings to exclude from URL checks (matched anywhere in the full URL). Used by the same checks as
skip_domains.
- tracking_domains: list[str]
Hostnames that must carry a
wt.mc_idtracking parameter. Only used bycheck_urls_tracking; URLs on other hosts are ignored by that check.
- timeout: int
Per-request timeout in seconds for URL checks.
- retries: int
Number of attempts for a URL before it is reported as
broken. Does not apply to rate-limit/auth responses, which return immediately (seeMarkdownURL.check).
- retry_on_429: bool
When True, honour a
Retry-Afterheader (or a bare 429) instead of the exponential backoff normally used for hard failures.
- fallback_retry_delay: int
Seconds reported as
retry_afterwhen a 429 response carries noRetry-Afterheader.
- max_workers: int
Maximum number of concurrent URL-check worker threads shared across the whole run.
- per_host_delay: float
Minimum delay in seconds enforced between two requests to the same host.
- max_pending: int
Maximum number of in-flight (submitted but not yet resolved) URL checks before new submissions block; bounds memory use on very large runs.
- output_mode: Literal['ci', 'local']
"ci"switches CLI output to GitHub Actions::error/::warningannotations;"local"uses plain coloured console output.
- class markdown_checker.MarkdownLinkBase(link, line_number, file_path, issue='', issue_level='error')
Base class for a single link found in a markdown file.
- Parameters:
- link: str
The raw link destination as written in the file (e.g.
"https://example.com"or"../img.png").
- line_number: int
1-based line number where the link was found.
- file_path: Path
Path to the markdown file the link was found in.
- issue: str
Human-readable description set by a check when this link fails it (e.g.
"is broken"); empty when no issue was found.
- issue_level: Literal['error', 'warning']
Severity of
issueonce set."error"fails the CLI run (exit code 1);"warning"is reported but never fails it.
- has_locale()
Check if the link has a locale
- Returns:
True if the link has a locale, False otherwise
- Return type:
- has_tracking()
Check if the link has a tracking ID
- Returns:
True if the link has a tracking ID, False otherwise
- Return type:
- class markdown_checker.MarkdownPath(link, line_number, file_path, issue='', issue_level='error')
A relative (or root-relative) file path extracted from a markdown link.
“Fragment” below always means the trailing
?queryand/or#anchorpart of the link, e.g. indocs/usage.md#section?wt.mc_id=xthe fragment is#section?wt.mc_id=xand the path isdocs/usage.md.- Parameters:
- property path_without_fragments: Path
The link as a
Path, with any query/anchor fragment stripped. Equivalent toPath(self.remove_fragments()).
- remove_fragments()
Strip the tracking query string and any trailing
?query/#anchorfragment from the link, leaving just the file path portion.- Returns:
The link with its fragment removed, as a string.
- Return type:
- get_full_path()
Resolve the link (with its fragment stripped) to an absolute path, relative to the current working directory.
This is used for links that are themselves absolute (e.g.
/docs/usage.md) or otherwise resolvable without knowing which file the link appeared in. If resolution fails (e.g. on an unusual path), falls back toget_full_path_relative().- Returns:
The resolved absolute path.
- Return type:
- get_full_path_relative()
Resolve the link (with its fragment stripped) relative to the directory of the markdown file it was found in (
self.file_path), e.g. a link../img.pngfound indocs/usage.mdresolves againstdocs/.- Returns:
The resolved path, as a normalized string.
- Return type:
- exists()
Check whether the link’s target file exists on disk.
Tries resolution relative to the containing markdown file first (see
get_full_path_relative()), then as an absolute/CWD-relative path (seeget_full_path()). Used bycheck_broken_pathsto flag links whose target is missing.- Returns:
True if the path exists, False otherwise
- Return type:
- class markdown_checker.MarkdownURL(link, line_number, file_path, issue='', issue_level='error')
A single web URL extracted from a markdown file, plus the ability to check it.
- Parameters:
- property parsed_url: ParseResult
Parse the URL and return the result
- Returns:
ParseResult – The parsed URL
- host_name()
Return the URL’s hostname (netloc), including any port but not the scheme, e.g.
"example.com"for"https://example.com/path".- Return type:
- check(timeout=20, retries=3, client=None, retry_on_429=True, fallback_retry_delay=30)
Check whether the URL is reachable and return a typed outcome.
Rate-limit signals (429, or any non-success response carrying a Retry-After header) and auth errors (401/403) are returned immediately without sleeping or retrying: retrying them wastes traffic against hosts that are already blocking or throttling us. Callers that want to wait out a rate limit (e.g. a host-level circuit breaker) should do so themselves using
retry_after.- Parameters:
timeout (int) – Timeout for the request in seconds.
retries (int) – Number of retries if the request fails.
client (httpx2.Client | None) – Optional shared client for connection pooling.
retry_on_429 (bool) – When True, honour Retry-After headers on 429 responses.
fallback_retry_delay (int) – Seconds to wait when a 429 carries no Retry-After header.
- Returns:
URLCheckResult with status one of –
alive,broken,rate_limited,unverifiable, ortransient_error.- Return type: