Page MenuHomePhabricator
Paste P1129

CustomInlineCodeRule.php
ActivePublic

Authored by epriestley on Apr 24 2014, 8:16 PM.
Tags
None
Referenced Files
F147321: CustomInlineCodeRule.php
Apr 24 2014, 8:16 PM
Subscribers
None
<?php
final class CustomInlineCodeRule extends PhabricatorRemarkupCustomInlineRule {
public function apply($text) {
return preg_replace_callback(
'(<code>(.*?)</code>)s',
array($this, 'markupInlineCodeBlock'),
$text);
}
public function markupInlineCodeBlock($matches) {
$engine = $this->getEngine();
$text = $matches[1];
$highlighter = new PhutilDefaultSyntaxHighlighterEngine();
$highlighter->setConfig(
'pygments.enabled',
$engine->getConfig('pygments.enabled'));
$lang = PhutilLanguageGuesser::guessLanguage($text);
if (!$lang) {
$lang = nonempty(
$engine->getConfig('phutil.codeblock.language-default'),
'php');
}
$source_body = phutil_tag(
'span',
array(
'class' => 'remarkup-code PhabricatorMonospaced',
'style' => 'white-space: pre-wrap; background: #fdfae7;',
),
PhutilSafeHTML::applyFunction(
'rtrim',
$highlighter->highlightSource($lang, $text)));
return $engine->storeText($source_body);
}
}