Path: blob/master/src/infrastructure/markup/markuprule/PhutilRemarkupMonospaceRule.php
12241 views
<?php12final class PhutilRemarkupMonospaceRule extends PhutilRemarkupRule {34public function getPriority() {5return 100.0;6}78public function apply($text) {9// NOTE: We don't require a trailing non-boundary on the backtick syntax,10// to permit the use case of naming and pluralizing a class, like11// "Load all the `PhutilArray`s and then iterate over them." In theory, the12// required \B on the leading backtick should protect us from most13// collateral damage.1415return preg_replace_callback(16'@##([\s\S]+?)##|\B`(.+?)`@',17array($this, 'markupMonospacedText'),18$text);19}2021protected function markupMonospacedText(array $matches) {22if ($this->getEngine()->isTextMode()) {23$result = $matches[0];2425} else26if ($this->getEngine()->isHTMLMailMode()) {27$match = isset($matches[2]) ? $matches[2] : $matches[1];28$result = phutil_tag(29'tt',30array(31'style' => 'background: #ebebeb; font-size: 13px;',32),33$match);3435} else {36$match = isset($matches[2]) ? $matches[2] : $matches[1];37$result = phutil_tag(38'tt',39array(40'class' => 'remarkup-monospaced',41),42$match);43}4445return $this->getEngine()->storeText($result);46}4748}495051