Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F147321
CustomInlineCodeRule.php
All Users
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
epriestley
Apr 24 2014, 8:16 PM
2014-04-24 20:16:06 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
CustomInlineCodeRule.php
View Options
<?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
Details
Attached
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)
Attached To
Mode
P1129 CustomInlineCodeRule.php
Attached
Detach File
Event Timeline
Log In to Comment