@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
1<?php
2
3final 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}