src/Parser.php
/**
     * Generates an anchor name based on a given heading.
     *
     * @param string $heading
     * @return string The generated anchor name.
     */
Generates an anchor name based on a given heading.
@param string $heading
@return string The generated anchor name.
Generates an anchor name based on a given heading . @param string $heading @return string The generated anchor name .
public function generateAnchorName($heading): string
    {
        $heading = preg_replace('/<(.*?)>/', '', $heading);
        $heading = preg_replace('/\(.*?\)/', '', $heading);
        $heading = preg_replace('/[\'"‘’“”]/u', '', $heading);
        $heading = str_replace(['&nbsp;', ' '], ' ', $heading);
        preg_match_all('/[\p{L}\p{N}]+/u', $heading, $words);
        $words = ArrayHelper::filterEmptyStringsFromArray($words[0]);
        foreach ($words as $i => $word) {
            if (strtoupper($word) === $word) {
                $words[$i] = strtolower($word);
            } else {
                $words[$i] = lcfirst($word);
            }
        }
        return implode('-', $words);
    }
public function generateAnchorName ( $ heading ) : string { $ heading = preg_replace ( '/<(.*?)>/' , '' , $ heading ) ; $ heading = preg_replace ( '/\(.*?\)/' , '' , $ heading ) ; $ heading = preg_replace ( '/[\'"‘’“”]/u', '', $h e di n ) ; $ heading = str_replace ( [ '&nbsp;' , ' '] ,  ', h eading) ; preg_match_all ( '/[\p{L}\p{N}]+/u' , $ heading , $ words ) ; $ words = ArrayHelper :: filterEmptyStringsFromArray ( $ words [ 0 ] ) ; foreach ( $ words as $ i => $ word ) { if ( strtoupper ( $ word ) === $ word ) { $ words [ $ i ] = strtolower ( $ word ) ; } else { $ words [ $ i ] = lcfirst ( $ word ) ; } } return implode ( '-' , $ words ) ; }
Generates an anchor name based on a given heading.
Generates an anchor name based on a given heading .
// Remove HTML tags // Remove parentheses // Remove inner-word punctuation // Convert non-breaking spaces to spaces // Get the "words". This will search for any unicode "letters" or "numbers" // Turn them into camelCase // Special case if the whole word is capitalized // Put them together as the anchor name