Differential D20825 Diff 49655 src/infrastructure/markup/blockrule/PhutilRemarkupHeaderBlockRule.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/markup/blockrule/PhutilRemarkupHeaderBlockRule.php
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | while ($depth > 0) { | ||||
$depth--; | $depth--; | ||||
} | } | ||||
return phutil_implode_html("\n", $toc); | return phutil_implode_html("\n", $toc); | ||||
} | } | ||||
public static function getAnchorNameFromHeaderText($text) { | public static function getAnchorNameFromHeaderText($text) { | ||||
$anchor = phutil_utf8_strtolower($text); | $anchor = phutil_utf8_strtolower($text); | ||||
$anchor = PhutilRemarkupAnchorRule::normalizeAnchor($anchor); | |||||
// Replace all latin characters which are not "a-z" or "0-9" with "-". | |||||
// Preserve other characters, since non-latin letters and emoji work | |||||
// fine in anchors. | |||||
$anchor = preg_replace('/[\x00-\x2F\x3A-\x60\x7B-\x7F]+/', '-', $anchor); | |||||
$anchor = trim($anchor, '-'); | |||||
// Truncate the fragment to something reasonable. | // Truncate the fragment to something reasonable. | ||||
$anchor = id(new PhutilUTF8StringTruncator()) | $anchor = id(new PhutilUTF8StringTruncator()) | ||||
->setMaximumGlyphs(32) | ->setMaximumGlyphs(32) | ||||
->setTerminator('') | ->setTerminator('') | ||||
->truncateString($anchor); | ->truncateString($anchor); | ||||
// If the fragment is terminated by a word which "The U.S. Government | // If the fragment is terminated by a word which "The U.S. Government | ||||
Show All 12 Lines |