Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/markup/markuprule/PhutilRemarkupMonospaceRule.php
12241 views
1
<?php
2
3
final class PhutilRemarkupMonospaceRule extends PhutilRemarkupRule {
4
5
public function getPriority() {
6
return 100.0;
7
}
8
9
public function apply($text) {
10
// NOTE: We don't require a trailing non-boundary on the backtick syntax,
11
// to permit the use case of naming and pluralizing a class, like
12
// "Load all the `PhutilArray`s and then iterate over them." In theory, the
13
// required \B on the leading backtick should protect us from most
14
// collateral damage.
15
16
return preg_replace_callback(
17
'@##([\s\S]+?)##|\B`(.+?)`@',
18
array($this, 'markupMonospacedText'),
19
$text);
20
}
21
22
protected function markupMonospacedText(array $matches) {
23
if ($this->getEngine()->isTextMode()) {
24
$result = $matches[0];
25
26
} else
27
if ($this->getEngine()->isHTMLMailMode()) {
28
$match = isset($matches[2]) ? $matches[2] : $matches[1];
29
$result = phutil_tag(
30
'tt',
31
array(
32
'style' => 'background: #ebebeb; font-size: 13px;',
33
),
34
$match);
35
36
} else {
37
$match = isset($matches[2]) ? $matches[2] : $matches[1];
38
$result = phutil_tag(
39
'tt',
40
array(
41
'class' => 'remarkup-monospaced',
42
),
43
$match);
44
}
45
46
return $this->getEngine()->storeText($result);
47
}
48
49
}
50
51