@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 CelerityManagementSyntaxWorkflow
4 extends CelerityManagementWorkflow {
5
6 protected function didConstruct() {
7 $this
8 ->setName('syntax')
9 ->setExamples('**syntax** [options]')
10 ->setSynopsis(pht('Rebuild syntax highlighting CSS.'))
11 ->setArguments(
12 array());
13 }
14
15 public function execute(PhutilArgumentParser $args) {
16 $styles = PhabricatorSyntaxStyle::getAllStyles();
17
18 $root = dirname(phutil_get_library_root('phabricator'));
19 $root = $root.'/webroot/rsrc/css/syntax/';
20
21 foreach ($styles as $key => $style) {
22 $content = $this->generateCSS($style);
23 $path = $root.'/syntax-'.$key.'.css';
24 Filesystem::writeFile($path, $content);
25
26 echo tsprintf(
27 "%s\n",
28 pht(
29 'Rebuilt "%s" syntax CSS.',
30 basename($path)));
31 }
32
33 return 0;
34 }
35
36 private function generateCSS(PhabricatorSyntaxStyle $style) {
37 $key = $style->getSyntaxStyleKey();
38 $provides = "syntax-{$key}-css";
39 $generated = 'generated';
40
41 $header =
42 "/**\n".
43 " * @provides {$provides}\n".
44 " * @{$generated}\n".
45 " */\n\n";
46
47 $groups = array();
48 $map = $style->getStyleMap();
49 ksort($map);
50 foreach ($map as $key => $value) {
51 $groups[$value][] = $key;
52 }
53
54 $rules = array();
55 foreach ($groups as $body => $classes) {
56 $parts = array();
57 foreach ($classes as $class) {
58 $parts[] = ".remarkup-code .{$class}";
59 }
60 $rules[] = implode(",\n", $parts)." {\n {$body}\n}";
61 }
62 $rules = implode("\n\n", $rules);
63
64 return $header.$rules."\n";
65 }
66
67}