Markdown.ToHeadingAnchor Method

Namespace
Kampute.DocToolkit.Support
Assembly
  • Kampute.DocToolkit.dll

Definition

Converts the specified heading text to the anchor that GitHub and GitLab generate for a Markdown heading.
public static string ToHeadingAnchor(string heading)

Parameters

heading string
The text of the heading.

Returns

string
The anchor of the heading, without the leading '#'.

Exceptions

ArgumentNullException
Thrown when heading is null.

Remarks

The anchor is generated by the following rules:
  • All characters are converted to lowercase.
  • All characters except letters, numbers, hyphens, underscores and spaces are removed.
  • Each space is converted to a hyphen.
For example, the heading Repeat<TResult>(TResult, int) has the anchor repeattresulttresult-int.
When a page has several headings with the same anchor, Markdown processors append a number to all but the first one. This method cannot account for that, because it sees one heading at a time.

See Also