Page MenuHomePhabricator

CustomInlineCodeRule.php

Authored By
epriestley
Apr 24 2014, 8:16 PM
Size
1 KB
Referenced Files
None
Subscribers
None

CustomInlineCodeRule.php

<?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);
}
}

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/d4/xk/zycahjljoa5lj4eb
Default Alt Text
CustomInlineCodeRule.php (1 KB)

Event Timeline