Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14402209
PhutilDefaultSyntaxHighlighterEngine.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
PhutilDefaultSyntaxHighlighterEngine.php
View Options
<?php
/**
* @group markup
*/
final
class
PhutilDefaultSyntaxHighlighterEngine
extends
PhutilSyntaxHighlighterEngine
{
private
$config
=
array
();
public
function
setConfig
(
$key
,
$value
)
{
$this
->
config
[
$key
]
=
$value
;
return
$this
;
}
public
function
getLanguageFromFilename
(
$filename
)
{
static
$default_map
=
array
(
// All files which have file extensions that we haven't already matched
// map to their extensions.
'@
\\
.([^./]+)$@'
=>
1
,
);
$maps
=
array
();
if
(!
empty
(
$this
->
config
[
'filename.map'
]))
{
$maps
[]
=
$this
->
config
[
'filename.map'
];
}
$maps
[]
=
$default_map
;
foreach
(
$maps
as
$map
)
{
foreach
(
$map
as
$regexp
=>
$lang
)
{
$matches
=
null
;
if
(
preg_match
(
$regexp
,
$filename
,
$matches
))
{
if
(
is_numeric
(
$lang
))
{
return
idx
(
$matches
,
$lang
);
}
else
{
return
$lang
;
}
}
}
}
return
null
;
}
public
function
getHighlightFuture
(
$language
,
$source
)
{
if
(
$language
===
null
)
{
$language
=
PhutilLanguageGuesser
::
guessLanguage
(
$source
);
}
$have_pygments
=
!
empty
(
$this
->
config
[
'pygments.enabled'
]);
if
(
$language
==
'php'
&&
xhpast_is_available
())
{
return
id
(
new
PhutilXHPASTSyntaxHighlighter
())
->
getHighlightFuture
(
$source
);
}
if
(
$language
==
'console'
)
{
return
id
(
new
PhutilConsoleSyntaxHighlighter
())
->
getHighlightFuture
(
$source
);
}
if
(
$language
==
'diviner'
||
$language
==
'remarkup'
)
{
return
id
(
new
PhutilDivinerSyntaxHighlighter
())
->
getHighlightFuture
(
$source
);
}
if
(
$language
==
'rainbow'
)
{
return
id
(
new
PhutilRainbowSyntaxHighlighter
())
->
getHighlightFuture
(
$source
);
}
if
(
$language
==
'php'
)
{
return
id
(
new
PhutilLexerSyntaxHighlighter
())
->
setConfig
(
'lexer'
,
new
PhutilPHPFragmentLexer
())
->
setConfig
(
'language'
,
'php'
)
->
getHighlightFuture
(
$source
);
}
if
(
$have_pygments
)
{
return
id
(
new
PhutilPygmentsSyntaxHighlighter
())
->
setConfig
(
'language'
,
$language
)
->
getHighlightFuture
(
$source
);
}
return
id
(
new
PhutilDefaultSyntaxHighlighter
())
->
getHighlightFuture
(
$source
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Dec 24, 11:56 PM (1 d, 18 h)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6902610
Default Alt Text
PhutilDefaultSyntaxHighlighterEngine.php (2 KB)
Attached To
Mode
rPHU libphutil
Attached
Detach File
Event Timeline
Log In to Comment