okflint.scanner module
Shared Markdown file scanning primitives for OKF.
- class okflint.scanner.Header(level, text, line)[source]
Bases:
objectRepresents an H1 or H2 heading in a file.
- class okflint.scanner.MarkdownLink(text, target, is_external, broken)[source]
Bases:
objectRepresents a markdown link [text](url) in a file.
- class okflint.scanner.WikiLink(raw, target, alias, section, resolved_path, broken, ambiguous)[source]
Bases:
objectRepresents an Obsidian wikilink [[…]] in a file.
- okflint.scanner.blank_code_spans(content)[source]
Blank out fenced code blocks and inline code spans.
Allows link extraction without false positives inside code zones. Replaces code zone content with spaces while preserving character positions (line numbers unchanged). An unclosed fence at end of file is treated as open until EOF.
- okflint.scanner.build_file_index(roots, exclude_patterns=None)[source]
Index all .md files under a list of roots for wikilink resolution.
- Parameters:
- Return type:
- Returns:
Dictionary stem → list of paths relative to the first root.
- okflint.scanner.extract_headers(content)[source]
Extract H1 and H2 headings with their line number in the body.
Must receive content pre-blanked via blank_code_spans to ignore # characters inside code blocks.
- okflint.scanner.extract_markdown_links(content, file_path, bundle_path, other_roots=None)[source]
Extract [text](target) markdown links and verify internal links.
Targets carrying a URI scheme (RFC 3986), e.g. http://, mailto:, tel:, obsidian://, are absolute URIs and are not checked.
- Parameters:
content (
str) – Markdown file body.file_path (
Path) – Absolute path of the current file.bundle_path (
Path) – Root owning the current file (tried first for absolute paths).other_roots (
list[Path] |None) – Remaining roots of a multi-root base. An absolute path not found underbundle_pathis tried against each of these, in order, before being reported broken.
- Return type:
- Returns:
List of MarkdownLink.