Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/markup/syntax/highlighter/PhutilInvisibleSyntaxHighlighter.php
12242 views
1
<?php
2
3
final class PhutilInvisibleSyntaxHighlighter extends Phobject {
4
5
private $config = array();
6
7
public function setConfig($key, $value) {
8
$this->config[$key] = $value;
9
return $this;
10
}
11
12
public function getHighlightFuture($source) {
13
$keys = array_map('chr', range(0x0, 0x1F));
14
$vals = array_map(
15
array($this, 'decimalToHtmlEntityDecoded'), range(0x2400, 0x241F));
16
17
$invisible = array_combine($keys, $vals);
18
19
$result = array();
20
foreach (str_split($source) as $character) {
21
if (isset($invisible[$character])) {
22
$result[] = phutil_tag(
23
'span',
24
array('class' => 'invisible'),
25
$invisible[$character]);
26
27
if ($character === "\n") {
28
$result[] = $character;
29
}
30
} else {
31
$result[] = $character;
32
}
33
}
34
35
$result = phutil_implode_html('', $result);
36
return new ImmediateFuture($result);
37
}
38
39
private function decimalToHtmlEntityDecoded($dec) {
40
return html_entity_decode("&#{$dec};");
41
}
42
43
}
44
45