Skip to main content

Module markdown

Module markdown 

Source
Expand description

Markdown scanning, link rewriting, heading extraction, and anchor slugs.

OKF documents use Markdown with YAML frontmatter. This module provides pure-Rust Markdown utilities for inspecting and transforming Markdown content:

  • heading_slug: Generates kebab-case URL anchor slugs matching GitHub/CommonMark conventions.
  • extract_headings: Extracts all headings in document order, skipping fenced code blocks.
  • rewrite_markdown_links: Rewrites inline links while ignoring code blocks and inline code.

Structs§

MarkdownHeading
A parsed markdown heading.

Enums§

LinkRewriteAction
Action to perform on a detected markdown link during rewrite.

Functions§

blank_inline_code
Replaces inline code spans (backtick-delimited) with spaces so links/footnotes inside them are not extracted.
clean_destination
Normalizes a raw link destination.
code_free_lines
Returns the body’s lines, as (1-based line number, text), with fenced code blocks removed and inline code spans blanked out.
extract_headings
Extracts all markdown headings in document order, ignoring headings inside fenced code blocks.
extract_title_suffix
Extracts the title suffix part (e.g. "My Title") from a destination string.
heading_slug
Derives a standard Markdown anchor slug from a heading text.
is_escaped
Whether the character at index is preceded by an odd number of backslashes, and is therefore escaped in Markdown.
matches_heading
Checks whether a heading text matches a search query by title, slug, or normalized spacing.
parse_heading_line
Parses a single line as an ATX heading (# through ###### ).
parse_inline_link
Attempts to parse [text](dest) starting at start (the [). Returns the text, destination, and index just past the closing ).
rewrite_markdown_links
Rewrites inline markdown links in a document body using a callback function.
strip_title
Removes an optional "title" (or 'title') suffix from a link destination.