@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 46 lines 993 B view raw
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 */ 7final 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}