Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/markup/syntax/highlighter/PhutilRainbowSyntaxHighlighter.php
12242 views
1
<?php
2
3
/**
4
* Highlights source code with a rainbow of colors, regardless of the language.
5
* This highlighter is useless, absurd, and extremely slow.
6
*/
7
final class PhutilRainbowSyntaxHighlighter extends Phobject {
8
9
private $config = array();
10
11
public function setConfig($key, $value) {
12
$this->config[$key] = $value;
13
return $this;
14
}
15
16
public function getHighlightFuture($source) {
17
18
$color = 0;
19
$colors = array(
20
'rbw_r',
21
'rbw_o',
22
'rbw_y',
23
'rbw_g',
24
'rbw_b',
25
'rbw_i',
26
'rbw_v',
27
);
28
29
$result = array();
30
foreach (phutil_utf8v($source) as $character) {
31
if ($character == ' ' || $character == "\n") {
32
$result[] = $character;
33
continue;
34
}
35
$result[] = phutil_tag(
36
'span',
37
array('class' => $colors[$color]),
38
$character);
39
$color = ($color + 1) % count($colors);
40
}
41
42
$result = phutil_implode_html('', $result);
43
return new ImmediateFuture($result);
44
}
45
46
}
47
48