@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

Generate syntax highlighting CSS from a reusable map

Summary:
Ref T9790. This prepares the syntax color rules to be reused in mail.

This goes about halfway toward T5701 by sort-of supporting different styles but not really.

Test Plan:
- Ran `bin/celerity syntax` to regenerate syntax map.
- Viewed some highlighted code, didn't see any differences.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9790

Differential Revision: https://secure.phabricator.com/D15846

+340 -107
+9 -3
resources/celerity/map.php
··· 7 7 */ 8 8 return array( 9 9 'names' => array( 10 - 'core.pkg.css' => '5242a859', 10 + 'core.pkg.css' => 'b7b8d101', 11 11 'core.pkg.js' => '6972d365', 12 12 'darkconsole.pkg.js' => 'e7393ebb', 13 13 'differential.pkg.css' => '7ba78475', ··· 105 105 'rsrc/css/application/uiexample/example.css' => '528b19de', 106 106 'rsrc/css/core/core.css' => 'd0801452', 107 107 'rsrc/css/core/remarkup.css' => '787105d6', 108 - 'rsrc/css/core/syntax.css' => '9fd11da8', 108 + 'rsrc/css/core/syntax.css' => '5101175d', 109 109 'rsrc/css/core/z-index.css' => '5b6fcf3f', 110 110 'rsrc/css/diviner/diviner-shared.css' => 'aa3656aa', 111 111 'rsrc/css/font/font-aleo.css' => '8bdb2835', ··· 164 164 'rsrc/css/sprite-login.css' => '60e8560e', 165 165 'rsrc/css/sprite-menu.css' => '9dd65b92', 166 166 'rsrc/css/sprite-tokens.css' => '4f399012', 167 + 'rsrc/css/syntax/syntax-default.css' => '9923583c', 167 168 'rsrc/externals/d3/d3.min.js' => 'a11a5ff2', 168 169 'rsrc/externals/font/aleo/aleo-bold.eot' => 'd3d3bed7', 169 170 'rsrc/externals/font/aleo/aleo-bold.svg' => '45899c8e', ··· 877 878 'sprite-login-css' => '60e8560e', 878 879 'sprite-menu-css' => '9dd65b92', 879 880 'sprite-tokens-css' => '4f399012', 880 - 'syntax-highlighting-css' => '9fd11da8', 881 + 'syntax-default-css' => '9923583c', 882 + 'syntax-highlighting-css' => '5101175d', 881 883 'tokens-css' => '3d0f239e', 882 884 'typeahead-browse-css' => 'd8581d2c', 883 885 'unhandled-exception-css' => '4c96257a', ··· 1238 1240 'javelin-install', 1239 1241 'javelin-typeahead-source', 1240 1242 'javelin-util', 1243 + ), 1244 + '5101175d' => array( 1245 + 'syntax-default-css', 1241 1246 ), 1242 1247 '519705ea' => array( 1243 1248 'javelin-install', ··· 2192 2197 'aphront-list-filter-view-css', 2193 2198 'phabricator-remarkup-css', 2194 2199 'syntax-highlighting-css', 2200 + 'syntax-default-css', 2195 2201 'phui-pager-css', 2196 2202 'aphront-tooltip-css', 2197 2203 'phabricator-flag-css',
+1
resources/celerity/packages.php
··· 97 97 98 98 'phabricator-remarkup-css', 99 99 'syntax-highlighting-css', 100 + 'syntax-default-css', 100 101 'phui-pager-css', 101 102 'aphront-tooltip-css', 102 103 'phabricator-flag-css',
+6
src/__phutil_library_map__.php
··· 226 226 'CelerityHighContrastPostprocessor' => 'applications/celerity/postprocessor/CelerityHighContrastPostprocessor.php', 227 227 'CelerityLargeFontPostprocessor' => 'applications/celerity/postprocessor/CelerityLargeFontPostprocessor.php', 228 228 'CelerityManagementMapWorkflow' => 'applications/celerity/management/CelerityManagementMapWorkflow.php', 229 + 'CelerityManagementSyntaxWorkflow' => 'applications/celerity/management/CelerityManagementSyntaxWorkflow.php', 229 230 'CelerityManagementWorkflow' => 'applications/celerity/management/CelerityManagementWorkflow.php', 230 231 'CelerityPhabricatorResourceController' => 'applications/celerity/controller/CelerityPhabricatorResourceController.php', 231 232 'CelerityPhabricatorResources' => 'applications/celerity/resources/CelerityPhabricatorResources.php', ··· 2273 2274 'PhabricatorDateTimeSettingsPanel' => 'applications/settings/panel/PhabricatorDateTimeSettingsPanel.php', 2274 2275 'PhabricatorDebugController' => 'applications/system/controller/PhabricatorDebugController.php', 2275 2276 'PhabricatorDefaultRequestExceptionHandler' => 'aphront/handler/PhabricatorDefaultRequestExceptionHandler.php', 2277 + 'PhabricatorDefaultSyntaxStyle' => 'infrastructure/syntax/PhabricatorDefaultSyntaxStyle.php', 2276 2278 'PhabricatorDesktopNotificationsSettingsPanel' => 'applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php', 2277 2279 'PhabricatorDestructibleInterface' => 'applications/system/interface/PhabricatorDestructibleInterface.php', 2278 2280 'PhabricatorDestructionEngine' => 'applications/system/engine/PhabricatorDestructionEngine.php', ··· 3454 3456 'PhabricatorSupportApplication' => 'applications/support/application/PhabricatorSupportApplication.php', 3455 3457 'PhabricatorSyntaxHighlighter' => 'infrastructure/markup/PhabricatorSyntaxHighlighter.php', 3456 3458 'PhabricatorSyntaxHighlightingConfigOptions' => 'applications/config/option/PhabricatorSyntaxHighlightingConfigOptions.php', 3459 + 'PhabricatorSyntaxStyle' => 'infrastructure/syntax/PhabricatorSyntaxStyle.php', 3457 3460 'PhabricatorSystemAction' => 'applications/system/action/PhabricatorSystemAction.php', 3458 3461 'PhabricatorSystemActionEngine' => 'applications/system/engine/PhabricatorSystemActionEngine.php', 3459 3462 'PhabricatorSystemActionGarbageCollector' => 'applications/system/garbagecollector/PhabricatorSystemActionGarbageCollector.php', ··· 4397 4400 'CelerityHighContrastPostprocessor' => 'CelerityPostprocessor', 4398 4401 'CelerityLargeFontPostprocessor' => 'CelerityPostprocessor', 4399 4402 'CelerityManagementMapWorkflow' => 'CelerityManagementWorkflow', 4403 + 'CelerityManagementSyntaxWorkflow' => 'CelerityManagementWorkflow', 4400 4404 'CelerityManagementWorkflow' => 'PhabricatorManagementWorkflow', 4401 4405 'CelerityPhabricatorResourceController' => 'CelerityResourceController', 4402 4406 'CelerityPhabricatorResources' => 'CelerityResourcesOnDisk', ··· 6764 6768 'PhabricatorDateTimeSettingsPanel' => 'PhabricatorSettingsPanel', 6765 6769 'PhabricatorDebugController' => 'PhabricatorController', 6766 6770 'PhabricatorDefaultRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler', 6771 + 'PhabricatorDefaultSyntaxStyle' => 'PhabricatorSyntaxStyle', 6767 6772 'PhabricatorDesktopNotificationsSettingsPanel' => 'PhabricatorSettingsPanel', 6768 6773 'PhabricatorDestructionEngine' => 'Phobject', 6769 6774 'PhabricatorDestructionEngineExtension' => 'Phobject', ··· 8150 8155 'PhabricatorSupportApplication' => 'PhabricatorApplication', 8151 8156 'PhabricatorSyntaxHighlighter' => 'Phobject', 8152 8157 'PhabricatorSyntaxHighlightingConfigOptions' => 'PhabricatorApplicationConfigOptions', 8158 + 'PhabricatorSyntaxStyle' => 'Phobject', 8153 8159 'PhabricatorSystemAction' => 'Phobject', 8154 8160 'PhabricatorSystemActionEngine' => 'Phobject', 8155 8161 'PhabricatorSystemActionGarbageCollector' => 'PhabricatorGarbageCollector',
+67
src/applications/celerity/management/CelerityManagementSyntaxWorkflow.php
··· 1 + <?php 2 + 3 + final 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 + }
+76
src/infrastructure/syntax/PhabricatorDefaultSyntaxStyle.php
··· 1 + <?php 2 + 3 + final class PhabricatorDefaultSyntaxStyle 4 + extends PhabricatorSyntaxStyle { 5 + 6 + const STYLEKEY = 'default'; 7 + 8 + public function getStyleName() { 9 + return pht('Default'); 10 + } 11 + 12 + public function getStyleMap() { 13 + return array( 14 + 'hll' => 'color: #ffffcc', 15 + 'c' => 'color: #74777d', 16 + 'cm' => 'color: #74777d', 17 + 'c1' => 'color: #74777d', 18 + 'cs' => 'color: #74777d', 19 + 'sd' => 'color: #000000', 20 + 'sh' => 'color: #000000', 21 + 's' => 'color: #766510', 22 + 'sb' => 'color: #766510', 23 + 'sc' => 'color: #766510', 24 + 's2' => 'color: #766510', 25 + 's1' => 'color: #766510', 26 + 'sx' => 'color: #766510', 27 + 'sr' => 'color: #bb6688', 28 + 'nv' => 'color: #001294', 29 + 'vi' => 'color: #001294', 30 + 'vg' => 'color: #001294', 31 + 'na' => 'color: #354bb3', 32 + 'kc' => 'color: #000a65', 33 + 'no' => 'color: #000a65', 34 + 'k' => 'color: #aa4000', 35 + 'kd' => 'color: #aa4000', 36 + 'kn' => 'color: #aa4000', 37 + 'kt' => 'color: #aa4000', 38 + 'cp' => 'color: #304a96', 39 + 'kp' => 'color: #304a96', 40 + 'kr' => 'color: #304a96', 41 + 'nb' => 'color: #304a96', 42 + 'bp' => 'color: #304a96', 43 + 'nc' => 'color: #00702a', 44 + 'nt' => 'color: #00702a', 45 + 'vc' => 'color: #00702a', 46 + 'nf' => 'color: #004012', 47 + 'nx' => 'color: #004012', 48 + 'o' => 'color: #aa2211', 49 + 'ss' => 'color: #aa2211', 50 + 'm' => 'color: #601200', 51 + 'mf' => 'color: #601200', 52 + 'mh' => 'color: #601200', 53 + 'mi' => 'color: #601200', 54 + 'mo' => 'color: #601200', 55 + 'il' => 'color: #601200', 56 + 'gd' => 'color: #a00000', 57 + 'gr' => 'color: #ff0000', 58 + 'gh' => 'color: #000080', 59 + 'gi' => 'color: #00a000', 60 + 'go' => 'color: #808080', 61 + 'gp' => 'color: #000080', 62 + 'gu' => 'color: #800080', 63 + 'gt' => 'color: #0040d0', 64 + 'nd' => 'color: #aa22ff', 65 + 'ni' => 'color: #92969d', 66 + 'ne' => 'color: #d2413a', 67 + 'nl' => 'color: #a0a000', 68 + 'nn' => 'color: #0000ff', 69 + 'ow' => 'color: #aa22ff', 70 + 'w' => 'color: #bbbbbb', 71 + 'se' => 'color: #bb6622', 72 + 'si' => 'color: #bb66bb', 73 + ); 74 + } 75 + 76 + }
+30
src/infrastructure/syntax/PhabricatorSyntaxStyle.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorSyntaxStyle extends Phobject { 4 + 5 + abstract public function getStyleName(); 6 + abstract public function getStyleMap(); 7 + 8 + final public function getStyleOrder() { 9 + return (string)id(new PhutilSortVector()) 10 + ->addInt($this->isDefaultStyle() ? 0 : 1) 11 + ->addString($this->getStyleName()); 12 + } 13 + 14 + final public function getSyntaxStyleKey() { 15 + return $this->getPhobjectClassConstant('STYLEKEY'); 16 + } 17 + 18 + final public function isDefaultStyle() { 19 + return ($this->getSyntaxStyleKey() == 'default'); 20 + } 21 + 22 + public static function getAllStyles() { 23 + return id(new PhutilClassMapQuery()) 24 + ->setAncestorClass(__CLASS__) 25 + ->setUniqueMethod('getSyntaxStyleKey') 26 + ->setSortMethod('getStyleName') 27 + ->execute(); 28 + } 29 + 30 + }
+1 -104
webroot/rsrc/css/core/syntax.css
··· 1 1 /** 2 2 * @provides syntax-highlighting-css 3 + * @requires syntax-default-css 3 4 */ 4 5 .remarkup-code .uu { /* Forbidden Unicode */ 5 6 color: #aa0066; ··· 18 19 .remarkup-code span.bright { 19 20 border-bottom: 1px solid transparent; 20 21 } 21 - 22 - .remarkup-code .hll { 23 - background-color: #ffffcc; 24 - } 25 - 26 - .remarkup-code .c, /* Comment */ 27 - .remarkup-code .cm, /* Comment.Multiline */ 28 - .remarkup-code .c1, /* Comment.Single */ 29 - .remarkup-code .cs { /* Comment.Special */ 30 - color: {$greytext}; 31 - } 32 - 33 - .remarkup-code .sd, /* Literal.String.Doc */ 34 - .remarkup-code .sh { /* Literal.String.Heredoc */ 35 - color: #000000; 36 - } 37 - 38 - .remarkup-code .s, /* Literal.String */ 39 - .remarkup-code .sb, /* Literal.String.Backtick */ 40 - .remarkup-code .sc, /* Literal.String.Char */ 41 - .remarkup-code .s2, /* Literal.String.Double */ 42 - .remarkup-code .s1, /* Literal.String.Single */ 43 - .remarkup-code .sx { /* Literal.String.Other */ 44 - color: #766510; 45 - } 46 - 47 - .remarkup-code .sr { /* Literal.String.Regex */ 48 - color: #BB6688; 49 - } 50 - 51 - .remarkup-code .nv, /* Name.Variable */ 52 - .remarkup-code .vi, /* Name.Variable.Instance */ 53 - .remarkup-code .vg { /* Name.Variable.Global */ 54 - color: #001294; 55 - } 56 - 57 - .remarkup-code .na { /* Name.Attribute */ 58 - color: #354BB3; 59 - } 60 - 61 - .remarkup-code .kc, /* Keyword.Constant */ 62 - .remarkup-code .no { /* Name.Constant */ 63 - color: #000A65; 64 - } 65 - 66 - .remarkup-code .k, /* Keyword */ 67 - .remarkup-code .kd, /* Keyword.Declaration */ 68 - .remarkup-code .kn, /* Keyword.Namespace */ 69 - .remarkup-code .kt { /* Keyword.Type */ 70 - color: #AA4000; 71 - } 72 - 73 - .remarkup-code .cp, /* Comment.Preproc */ 74 - .remarkup-code .kp, /* Keyword.Pseudo */ 75 - .remarkup-code .kr, /* Keyword.Reserved */ 76 - .remarkup-code .nb, /* Name.Builtin */ 77 - .remarkup-code .bp { /* Name.Builtin.Pseudo */ 78 - color: #304A96; 79 - } 80 - 81 - .remarkup-code .nc, /* Name.Class */ 82 - .remarkup-code .nt, /* Name.Tag */ 83 - .remarkup-code .vc { /* Name.Variable.Class */ 84 - color: #00702A; 85 - } 86 - 87 - .remarkup-code .nf, /* Name.Function */ 88 - .remarkup-code .nx { /* Name.Other */ 89 - color: #004012; 90 - } 91 - 92 - .remarkup-code .o, /* Operator */ 93 - .remarkup-code .ss { /* Literal.String.Symbol */ 94 - color: #AA2211; 95 - } 96 - 97 - .remarkup-code .m, /* Literal.Number */ 98 - .remarkup-code .mf, /* Literal.Number.Float */ 99 - .remarkup-code .mh, /* Literal.Number.Hex */ 100 - .remarkup-code .mi, /* Literal.Number.Integer */ 101 - .remarkup-code .mo, /* Literal.Number.Oct */ 102 - .remarkup-code .il { /* Literal.Number.Integer.Long */ 103 - color: #601200; 104 - } 105 - 106 - .remarkup-code .gd { color: #A00000 } /* Generic.Deleted */ 107 - .remarkup-code .ge { } /* Generic.Emph */ 108 - .remarkup-code .gr { color: #FF0000 } /* Generic.Error */ 109 - .remarkup-code .gh { color: #000080; } /* Generic.Heading */ 110 - .remarkup-code .gi { color: #00A000 } /* Generic.Inserted */ 111 - .remarkup-code .go { color: #808080 } /* Generic.Output */ 112 - .remarkup-code .gp { color: #000080 } /* Generic.Prompt */ 113 - .remarkup-code .gs { } /* Generic.Strong */ 114 - .remarkup-code .gu { color: #800080 } /* Generic.Subheading */ 115 - .remarkup-code .gt { color: #0040D0 } /* Generic.Traceback */ 116 - .remarkup-code .nd { color: #AA22FF } /* Name.Decorator */ 117 - .remarkup-code .ni { color: {$lightgreytext} } /* Name.Entity */ 118 - .remarkup-code .ne { color: #D2413A } /* Name.Exception */ 119 - .remarkup-code .nl { color: #A0A000 } /* Name.Label */ 120 - .remarkup-code .nn { color: #0000FF } /* Name.Namespace */ 121 - .remarkup-code .ow { color: #AA22FF } /* Operator.Word */ 122 - .remarkup-code .w { color: #bbbbbb } /* Text.Whitespace */ 123 - .remarkup-code .se { color: #BB6622 } /* Literal.String.Escape */ 124 - .remarkup-code .si { color: #BB6688 } /* Literal.String.Interpol */ 125 22 126 23 .remarkup-code .rbw_r { color: red; } 127 24 .remarkup-code .rbw_o { color: orange; }
+150
webroot/rsrc/css/syntax/syntax-default.css
··· 1 + /** 2 + * @provides syntax-default-css 3 + * @generated 4 + */ 5 + 6 + .remarkup-code .bp, 7 + .remarkup-code .cp, 8 + .remarkup-code .kp, 9 + .remarkup-code .kr, 10 + .remarkup-code .nb { 11 + color: #304a96 12 + } 13 + 14 + .remarkup-code .c, 15 + .remarkup-code .c1, 16 + .remarkup-code .cm, 17 + .remarkup-code .cs { 18 + color: #74777d 19 + } 20 + 21 + .remarkup-code .gd { 22 + color: #a00000 23 + } 24 + 25 + .remarkup-code .gh, 26 + .remarkup-code .gp { 27 + color: #000080 28 + } 29 + 30 + .remarkup-code .gi { 31 + color: #00a000 32 + } 33 + 34 + .remarkup-code .go { 35 + color: #808080 36 + } 37 + 38 + .remarkup-code .gr { 39 + color: #ff0000 40 + } 41 + 42 + .remarkup-code .gt { 43 + color: #0040d0 44 + } 45 + 46 + .remarkup-code .gu { 47 + color: #800080 48 + } 49 + 50 + .remarkup-code .hll { 51 + color: #ffffcc 52 + } 53 + 54 + .remarkup-code .il, 55 + .remarkup-code .m, 56 + .remarkup-code .mf, 57 + .remarkup-code .mh, 58 + .remarkup-code .mi, 59 + .remarkup-code .mo { 60 + color: #601200 61 + } 62 + 63 + .remarkup-code .k, 64 + .remarkup-code .kd, 65 + .remarkup-code .kn, 66 + .remarkup-code .kt { 67 + color: #aa4000 68 + } 69 + 70 + .remarkup-code .kc, 71 + .remarkup-code .no { 72 + color: #000a65 73 + } 74 + 75 + .remarkup-code .na { 76 + color: #354bb3 77 + } 78 + 79 + .remarkup-code .nc, 80 + .remarkup-code .nt, 81 + .remarkup-code .vc { 82 + color: #00702a 83 + } 84 + 85 + .remarkup-code .nd, 86 + .remarkup-code .ow { 87 + color: #aa22ff 88 + } 89 + 90 + .remarkup-code .ne { 91 + color: #d2413a 92 + } 93 + 94 + .remarkup-code .nf, 95 + .remarkup-code .nx { 96 + color: #004012 97 + } 98 + 99 + .remarkup-code .ni { 100 + color: #92969d 101 + } 102 + 103 + .remarkup-code .nl { 104 + color: #a0a000 105 + } 106 + 107 + .remarkup-code .nn { 108 + color: #0000ff 109 + } 110 + 111 + .remarkup-code .nv, 112 + .remarkup-code .vg, 113 + .remarkup-code .vi { 114 + color: #001294 115 + } 116 + 117 + .remarkup-code .o, 118 + .remarkup-code .ss { 119 + color: #aa2211 120 + } 121 + 122 + .remarkup-code .s, 123 + .remarkup-code .s1, 124 + .remarkup-code .s2, 125 + .remarkup-code .sb, 126 + .remarkup-code .sc, 127 + .remarkup-code .sx { 128 + color: #766510 129 + } 130 + 131 + .remarkup-code .sd, 132 + .remarkup-code .sh { 133 + color: #000000 134 + } 135 + 136 + .remarkup-code .se { 137 + color: #bb6622 138 + } 139 + 140 + .remarkup-code .si { 141 + color: #bb66bb 142 + } 143 + 144 + .remarkup-code .sr { 145 + color: #bb6688 146 + } 147 + 148 + .remarkup-code .w { 149 + color: #bbbbbb 150 + }