Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/markup/markuprule/PhutilRemarkupHighlightRule.php
12241 views
1
<?php
2
3
final class PhutilRemarkupHighlightRule extends PhutilRemarkupRule {
4
5
public function getPriority() {
6
return 1000.0;
7
}
8
9
public function apply($text) {
10
if ($this->getEngine()->isTextMode()) {
11
return $text;
12
}
13
14
return $this->replaceHTML(
15
'@!!(.+?)(!{2,})@',
16
array($this, 'applyCallback'),
17
$text);
18
}
19
20
protected function applyCallback(array $matches) {
21
// Remove the two exclamation points that represent syntax.
22
$excitement = substr($matches[2], 2);
23
24
// If the internal content consists of ONLY exclamation points, leave it
25
// untouched so "!!!!!" is five exclamation points instead of one
26
// highlighted exclamation point.
27
if (preg_match('/^!+\z/', $matches[1])) {
28
return $matches[0];
29
}
30
31
// $excitement now has two fewer !'s than we started with.
32
return hsprintf('<span class="remarkup-highlight">%s%s</span>',
33
$matches[1], $excitement);
34
35
}
36
37
}
38
39