Skip to main content

slugify_heading

Function slugify_heading 

Source
pub fn slugify_heading(text: &str) -> String
Expand description

Convert a markdown heading line (“## 1. Tree-sitter, core”) into the GitHub-style slug (“1-tree-sitter-core”) used for intra-doc anchor links. Algorithm:

  1. Strip the leading #s + any whitespace.
  2. Lowercase.
  3. Drop any non-alphanumeric / non-hyphen / non-space character (punctuation, fences, parens, periods, etc.).
  4. Collapse whitespace runs to a single hyphen; collapse hyphen runs to a single hyphen.
  5. Trim leading / trailing hyphens.

Matches the slugs GitHub renders for # Heading blocks so links authored against rendered docs work in-editor too.