scanner

Primitives partagées de scan de fichiers Markdown OKF.

Shared Markdown file scanning primitives for OKF.

class okflint.scanner.Header(level, text, line)[source]

Bases: object

Represents an H1 or H2 heading in a file.

level: int
line: int
text: str

Bases: object

Represents a markdown link [text](url) in a file.

broken: bool
is_external: bool
target: str
text: str

Bases: object

Represents an Obsidian wikilink [[…]] in a file.

alias: str | None
ambiguous: bool
broken: bool
raw: str
resolved_path: str | None
section: str | None
target: str
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.

Parameters:

content (str) – Raw file body (after frontmatter).

Return type:

str

Returns:

Content with code blocks masked by spaces.

okflint.scanner.build_file_index(roots, exclude_patterns=None)[source]

Index all .md files under a list of roots for wikilink resolution.

Parameters:
  • roots (list[Path]) – List of roots to index.

  • exclude_patterns (dict[Path, list[str]] | None) – Optional per-root exclusion globs. Files matching any pattern for their root are omitted from the index.

Return type:

dict[str, list[str]]

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.

Parameters:

content (str) – File body with code blocks masked.

Return type:

list[Header]

Returns:

List of Header (levels 1 and 2 only).

Extract [text](target) markdown links and verify internal links.

External URLs (http:// / https://) are not checked.

Parameters:
  • content (str) – Markdown file body.

  • file_path (Path) – Absolute path of the current file.

  • bundle_path (Path) – Bundle root (for resolving absolute paths).

Return type:

list[MarkdownLink]

Returns:

List of MarkdownLink.

Extract and resolve [[…]] wikilinks in the content.

Parameters:
  • content (str) – Markdown file body.

  • vault_index (dict[str, list[str]]) – Vault index (stem → relative paths).

Return type:

list[WikiLink]

Returns:

List of WikiLink with broken/ambiguous status.

okflint.scanner.parse_frontmatter(content)[source]

Extract the YAML frontmatter from a markdown file.

Parameters:

content (str) – Full file content.

Return type:

tuple[dict[str, Any] | None, str]

Returns:

Tuple (frontmatter_dict, body) or (None, content) if absent or invalid.