Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97554951
PhutilInvisibleSyntaxHighlighter.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
Sun, Jan 5, 05:46
Size
1 KB
Mime Type
text/x-php
Expires
Tue, Jan 7, 05:46 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23425590
Attached To
rPHU libphutil
PhutilInvisibleSyntaxHighlighter.php
View Options
<?php
/**
* @group markup
*/
final
class
PhutilInvisibleSyntaxHighlighter
{
private
$config
=
array
();
public
function
setConfig
(
$key
,
$value
)
{
$this
->
config
[
$key
]
=
$value
;
return
$this
;
}
public
function
getHighlightFuture
(
$source
)
{
$keys
=
array_map
(
'chr'
,
range
(
0x0
,
0x1F
));
$vals
=
array_map
(
array
(
$this
,
'decimalToHtmlEntityDecoded'
),
range
(
0x2400
,
0x241F
));
$invisible
=
array_combine
(
$keys
,
$vals
);
$result
=
array
();
foreach
(
str_split
(
$source
)
as
$character
)
{
if
(
isset
(
$invisible
[
$character
]))
{
$result
[]
=
phutil_tag
(
'span'
,
array
(
'class'
=>
'invisible'
),
$invisible
[
$character
]);
if
(
$character
===
"
\n
"
)
{
$result
[]
=
$character
;
}
}
else
{
$result
[]
=
$character
;
}
}
$result
=
phutil_implode_html
(
''
,
$result
);
return
new
ImmediateFuture
(
$result
);
}
private
function
decimalToHtmlEntityDecoded
(
$dec
)
{
return
html_entity_decode
(
"&#{$dec};"
);
}
}
Event Timeline
Log In to Comment