Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92594490
PhutilRainbowSyntaxHighlighter.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Nov 21, 19:56
Size
998 B
Mime Type
text/x-php
Expires
Sat, Nov 23, 19:56 (1 d, 19 h)
Engine
blob
Format
Raw Data
Handle
22466087
Attached To
rPHU libphutil
PhutilRainbowSyntaxHighlighter.php
View Options
<?php
/**
* Highlights source code with a rainbow of colors, regardless of the language.
* This highlighter is useless, absurd, and extremely slow.
*
* @group markup
*/
final
class
PhutilRainbowSyntaxHighlighter
{
private
$config
=
array
();
public
function
setConfig
(
$key
,
$value
)
{
$this
->
config
[
$key
]
=
$value
;
return
$this
;
}
public
function
getHighlightFuture
(
$source
)
{
$color
=
0
;
$colors
=
array
(
'rbw_r'
,
'rbw_o'
,
'rbw_y'
,
'rbw_g'
,
'rbw_b'
,
'rbw_i'
,
'rbw_v'
,
);
$result
=
array
();
foreach
(
phutil_utf8v
(
$source
)
as
$character
)
{
if
(
$character
==
' '
||
$character
==
"
\n
"
)
{
$result
[]
=
$character
;
continue
;
}
$result
[]
=
'<span class="'
.
$colors
[
$color
].
'">'
.
phutil_escape_html
(
$character
).
'</span>'
;
$color
=
(
$color
+
1
)
%
count
(
$colors
);
}
$result
=
implode
(
''
,
$result
);
return
new
ImmediateFuture
(
$result
);
}
}
Event Timeline
Log In to Comment