anchorFor function
Reproduces the heading id that package:markdown's HeaderWithIdSyntax
generates, so a search result can deep-link to #anchor.
It hashes the raw inline text — before backticks, links and emphasis
are parsed — so ## The `@App()` annotation becomes
the-app-annotation, not the-annotation. Matching that exactly is the
whole point: get it wrong and search results deep-link to nothing.
Implementation
String anchorFor(String rawHeading) => rawHeading
.toLowerCase()
.trim()
.replaceAll(RegExp('[^a-z0-9 _-]'), '')
.replaceAll(RegExp(r'\s'), '-');