Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P1129
CustomInlineCodeRule.php
Active
Public
Actions
Authored by
epriestley
on Apr 24 2014, 8:16 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F147321: CustomInlineCodeRule.php
Apr 24 2014, 8:16 PM
2014-04-24 20:16:06 (UTC+0)
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
);
}
}
Event Timeline
epriestley
edited the content of this paste.
(Show Details)
Apr 24 2014, 8:16 PM
2014-04-24 20:16:06 (UTC+0)
epriestley
changed the title of this paste from untitled to
CustomInlineCodeRule.php
.
epriestley
updated the paste's language from
autodetect
to
autodetect
.
bougyman
mentioned this in
P1271 Bare img tag support in remarkup, like P1129
.
Oct 2 2014, 7:13 PM
2014-10-02 19:13:20 (UTC+0)
•
quazie_dbx
mentioned this in
T10234: When using a PhabricatorRemarkupCustomInlineRule with caching disabled, custom rules may end up with incorrect engines
.
Jan 28 2016, 2:49 AM
2016-01-28 02:49:58 (UTC+0)
epriestley
mentioned this in
D15501: Fix unusual use of Remarkup in Maniphest
.
Mar 21 2016, 6:21 PM
2016-03-21 18:21:57 (UTC+0)
epriestley
mentioned this in
rP66946c09968c: Fix unusual use of Remarkup in Maniphest
.
Mar 21 2016, 6:24 PM
2016-03-21 18:24:26 (UTC+0)
cspeckmim
mentioned this in
T12299: Linking Maniphest Tasks to external Bugtrackers
.
Feb 20 2017, 5:29 PM
2017-02-20 17:29:56 (UTC+0)
Log In to Comment