1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

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
This commit is contained in:
epriestley 2016-05-04 18:24:59 -07:00
parent e422190eb5
commit 01289f3f48
8 changed files with 340 additions and 107 deletions

View file

@ -7,7 +7,7 @@
*/
return array(
'names' => array(
'core.pkg.css' => '5242a859',
'core.pkg.css' => 'b7b8d101',
'core.pkg.js' => '6972d365',
'darkconsole.pkg.js' => 'e7393ebb',
'differential.pkg.css' => '7ba78475',
@ -105,7 +105,7 @@ return array(
'rsrc/css/application/uiexample/example.css' => '528b19de',
'rsrc/css/core/core.css' => 'd0801452',
'rsrc/css/core/remarkup.css' => '787105d6',
'rsrc/css/core/syntax.css' => '9fd11da8',
'rsrc/css/core/syntax.css' => '5101175d',
'rsrc/css/core/z-index.css' => '5b6fcf3f',
'rsrc/css/diviner/diviner-shared.css' => 'aa3656aa',
'rsrc/css/font/font-aleo.css' => '8bdb2835',
@ -164,6 +164,7 @@ return array(
'rsrc/css/sprite-login.css' => '60e8560e',
'rsrc/css/sprite-menu.css' => '9dd65b92',
'rsrc/css/sprite-tokens.css' => '4f399012',
'rsrc/css/syntax/syntax-default.css' => '9923583c',
'rsrc/externals/d3/d3.min.js' => 'a11a5ff2',
'rsrc/externals/font/aleo/aleo-bold.eot' => 'd3d3bed7',
'rsrc/externals/font/aleo/aleo-bold.svg' => '45899c8e',
@ -877,7 +878,8 @@ return array(
'sprite-login-css' => '60e8560e',
'sprite-menu-css' => '9dd65b92',
'sprite-tokens-css' => '4f399012',
'syntax-highlighting-css' => '9fd11da8',
'syntax-default-css' => '9923583c',
'syntax-highlighting-css' => '5101175d',
'tokens-css' => '3d0f239e',
'typeahead-browse-css' => 'd8581d2c',
'unhandled-exception-css' => '4c96257a',
@ -1239,6 +1241,9 @@ return array(
'javelin-typeahead-source',
'javelin-util',
),
'5101175d' => array(
'syntax-default-css',
),
'519705ea' => array(
'javelin-install',
'javelin-dom',
@ -2192,6 +2197,7 @@ return array(
'aphront-list-filter-view-css',
'phabricator-remarkup-css',
'syntax-highlighting-css',
'syntax-default-css',
'phui-pager-css',
'aphront-tooltip-css',
'phabricator-flag-css',

View file

@ -97,6 +97,7 @@ return array(
'phabricator-remarkup-css',
'syntax-highlighting-css',
'syntax-default-css',
'phui-pager-css',
'aphront-tooltip-css',
'phabricator-flag-css',

View file

@ -226,6 +226,7 @@ phutil_register_library_map(array(
'CelerityHighContrastPostprocessor' => 'applications/celerity/postprocessor/CelerityHighContrastPostprocessor.php',
'CelerityLargeFontPostprocessor' => 'applications/celerity/postprocessor/CelerityLargeFontPostprocessor.php',
'CelerityManagementMapWorkflow' => 'applications/celerity/management/CelerityManagementMapWorkflow.php',
'CelerityManagementSyntaxWorkflow' => 'applications/celerity/management/CelerityManagementSyntaxWorkflow.php',
'CelerityManagementWorkflow' => 'applications/celerity/management/CelerityManagementWorkflow.php',
'CelerityPhabricatorResourceController' => 'applications/celerity/controller/CelerityPhabricatorResourceController.php',
'CelerityPhabricatorResources' => 'applications/celerity/resources/CelerityPhabricatorResources.php',
@ -2273,6 +2274,7 @@ phutil_register_library_map(array(
'PhabricatorDateTimeSettingsPanel' => 'applications/settings/panel/PhabricatorDateTimeSettingsPanel.php',
'PhabricatorDebugController' => 'applications/system/controller/PhabricatorDebugController.php',
'PhabricatorDefaultRequestExceptionHandler' => 'aphront/handler/PhabricatorDefaultRequestExceptionHandler.php',
'PhabricatorDefaultSyntaxStyle' => 'infrastructure/syntax/PhabricatorDefaultSyntaxStyle.php',
'PhabricatorDesktopNotificationsSettingsPanel' => 'applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php',
'PhabricatorDestructibleInterface' => 'applications/system/interface/PhabricatorDestructibleInterface.php',
'PhabricatorDestructionEngine' => 'applications/system/engine/PhabricatorDestructionEngine.php',
@ -3454,6 +3456,7 @@ phutil_register_library_map(array(
'PhabricatorSupportApplication' => 'applications/support/application/PhabricatorSupportApplication.php',
'PhabricatorSyntaxHighlighter' => 'infrastructure/markup/PhabricatorSyntaxHighlighter.php',
'PhabricatorSyntaxHighlightingConfigOptions' => 'applications/config/option/PhabricatorSyntaxHighlightingConfigOptions.php',
'PhabricatorSyntaxStyle' => 'infrastructure/syntax/PhabricatorSyntaxStyle.php',
'PhabricatorSystemAction' => 'applications/system/action/PhabricatorSystemAction.php',
'PhabricatorSystemActionEngine' => 'applications/system/engine/PhabricatorSystemActionEngine.php',
'PhabricatorSystemActionGarbageCollector' => 'applications/system/garbagecollector/PhabricatorSystemActionGarbageCollector.php',
@ -4397,6 +4400,7 @@ phutil_register_library_map(array(
'CelerityHighContrastPostprocessor' => 'CelerityPostprocessor',
'CelerityLargeFontPostprocessor' => 'CelerityPostprocessor',
'CelerityManagementMapWorkflow' => 'CelerityManagementWorkflow',
'CelerityManagementSyntaxWorkflow' => 'CelerityManagementWorkflow',
'CelerityManagementWorkflow' => 'PhabricatorManagementWorkflow',
'CelerityPhabricatorResourceController' => 'CelerityResourceController',
'CelerityPhabricatorResources' => 'CelerityResourcesOnDisk',
@ -6764,6 +6768,7 @@ phutil_register_library_map(array(
'PhabricatorDateTimeSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorDebugController' => 'PhabricatorController',
'PhabricatorDefaultRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler',
'PhabricatorDefaultSyntaxStyle' => 'PhabricatorSyntaxStyle',
'PhabricatorDesktopNotificationsSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorDestructionEngine' => 'Phobject',
'PhabricatorDestructionEngineExtension' => 'Phobject',
@ -8150,6 +8155,7 @@ phutil_register_library_map(array(
'PhabricatorSupportApplication' => 'PhabricatorApplication',
'PhabricatorSyntaxHighlighter' => 'Phobject',
'PhabricatorSyntaxHighlightingConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorSyntaxStyle' => 'Phobject',
'PhabricatorSystemAction' => 'Phobject',
'PhabricatorSystemActionEngine' => 'Phobject',
'PhabricatorSystemActionGarbageCollector' => 'PhabricatorGarbageCollector',

View file

@ -0,0 +1,67 @@
<?php
final class CelerityManagementSyntaxWorkflow
extends CelerityManagementWorkflow {
protected function didConstruct() {
$this
->setName('syntax')
->setExamples('**syntax** [options]')
->setSynopsis(pht('Rebuild syntax highlighting CSS.'))
->setArguments(
array());
}
public function execute(PhutilArgumentParser $args) {
$styles = PhabricatorSyntaxStyle::getAllStyles();
$root = dirname(phutil_get_library_root('phabricator'));
$root = $root.'/webroot/rsrc/css/syntax/';
foreach ($styles as $key => $style) {
$content = $this->generateCSS($style);
$path = $root.'/syntax-'.$key.'.css';
Filesystem::writeFile($path, $content);
echo tsprintf(
"%s\n",
pht(
'Rebuilt "%s" syntax CSS.',
basename($path)));
}
return 0;
}
private function generateCSS(PhabricatorSyntaxStyle $style) {
$key = $style->getSyntaxStyleKey();
$provides = "syntax-{$key}-css";
$generated = 'generated';
$header =
"/**\n".
" * @provides {$provides}\n".
" * @{$generated}\n".
" */\n\n";
$groups = array();
$map = $style->getStyleMap();
ksort($map);
foreach ($map as $key => $value) {
$groups[$value][] = $key;
}
$rules = array();
foreach ($groups as $body => $classes) {
$parts = array();
foreach ($classes as $class) {
$parts[] = ".remarkup-code .{$class}";
}
$rules[] = implode(",\n", $parts)." {\n {$body}\n}";
}
$rules = implode("\n\n", $rules);
return $header.$rules."\n";
}
}

View file

@ -0,0 +1,76 @@
<?php
final class PhabricatorDefaultSyntaxStyle
extends PhabricatorSyntaxStyle {
const STYLEKEY = 'default';
public function getStyleName() {
return pht('Default');
}
public function getStyleMap() {
return array(
'hll' => 'color: #ffffcc',
'c' => 'color: #74777d',
'cm' => 'color: #74777d',
'c1' => 'color: #74777d',
'cs' => 'color: #74777d',
'sd' => 'color: #000000',
'sh' => 'color: #000000',
's' => 'color: #766510',
'sb' => 'color: #766510',
'sc' => 'color: #766510',
's2' => 'color: #766510',
's1' => 'color: #766510',
'sx' => 'color: #766510',
'sr' => 'color: #bb6688',
'nv' => 'color: #001294',
'vi' => 'color: #001294',
'vg' => 'color: #001294',
'na' => 'color: #354bb3',
'kc' => 'color: #000a65',
'no' => 'color: #000a65',
'k' => 'color: #aa4000',
'kd' => 'color: #aa4000',
'kn' => 'color: #aa4000',
'kt' => 'color: #aa4000',
'cp' => 'color: #304a96',
'kp' => 'color: #304a96',
'kr' => 'color: #304a96',
'nb' => 'color: #304a96',
'bp' => 'color: #304a96',
'nc' => 'color: #00702a',
'nt' => 'color: #00702a',
'vc' => 'color: #00702a',
'nf' => 'color: #004012',
'nx' => 'color: #004012',
'o' => 'color: #aa2211',
'ss' => 'color: #aa2211',
'm' => 'color: #601200',
'mf' => 'color: #601200',
'mh' => 'color: #601200',
'mi' => 'color: #601200',
'mo' => 'color: #601200',
'il' => 'color: #601200',
'gd' => 'color: #a00000',
'gr' => 'color: #ff0000',
'gh' => 'color: #000080',
'gi' => 'color: #00a000',
'go' => 'color: #808080',
'gp' => 'color: #000080',
'gu' => 'color: #800080',
'gt' => 'color: #0040d0',
'nd' => 'color: #aa22ff',
'ni' => 'color: #92969d',
'ne' => 'color: #d2413a',
'nl' => 'color: #a0a000',
'nn' => 'color: #0000ff',
'ow' => 'color: #aa22ff',
'w' => 'color: #bbbbbb',
'se' => 'color: #bb6622',
'si' => 'color: #bb66bb',
);
}
}

View file

@ -0,0 +1,30 @@
<?php
abstract class PhabricatorSyntaxStyle extends Phobject {
abstract public function getStyleName();
abstract public function getStyleMap();
final public function getStyleOrder() {
return (string)id(new PhutilSortVector())
->addInt($this->isDefaultStyle() ? 0 : 1)
->addString($this->getStyleName());
}
final public function getSyntaxStyleKey() {
return $this->getPhobjectClassConstant('STYLEKEY');
}
final public function isDefaultStyle() {
return ($this->getSyntaxStyleKey() == 'default');
}
public static function getAllStyles() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getSyntaxStyleKey')
->setSortMethod('getStyleName')
->execute();
}
}

View file

@ -1,5 +1,6 @@
/**
* @provides syntax-highlighting-css
* @requires syntax-default-css
*/
.remarkup-code .uu { /* Forbidden Unicode */
color: #aa0066;
@ -19,110 +20,6 @@
border-bottom: 1px solid transparent;
}
.remarkup-code .hll {
background-color: #ffffcc;
}
.remarkup-code .c, /* Comment */
.remarkup-code .cm, /* Comment.Multiline */
.remarkup-code .c1, /* Comment.Single */
.remarkup-code .cs { /* Comment.Special */
color: {$greytext};
}
.remarkup-code .sd, /* Literal.String.Doc */
.remarkup-code .sh { /* Literal.String.Heredoc */
color: #000000;
}
.remarkup-code .s, /* Literal.String */
.remarkup-code .sb, /* Literal.String.Backtick */
.remarkup-code .sc, /* Literal.String.Char */
.remarkup-code .s2, /* Literal.String.Double */
.remarkup-code .s1, /* Literal.String.Single */
.remarkup-code .sx { /* Literal.String.Other */
color: #766510;
}
.remarkup-code .sr { /* Literal.String.Regex */
color: #BB6688;
}
.remarkup-code .nv, /* Name.Variable */
.remarkup-code .vi, /* Name.Variable.Instance */
.remarkup-code .vg { /* Name.Variable.Global */
color: #001294;
}
.remarkup-code .na { /* Name.Attribute */
color: #354BB3;
}
.remarkup-code .kc, /* Keyword.Constant */
.remarkup-code .no { /* Name.Constant */
color: #000A65;
}
.remarkup-code .k, /* Keyword */
.remarkup-code .kd, /* Keyword.Declaration */
.remarkup-code .kn, /* Keyword.Namespace */
.remarkup-code .kt { /* Keyword.Type */
color: #AA4000;
}
.remarkup-code .cp, /* Comment.Preproc */
.remarkup-code .kp, /* Keyword.Pseudo */
.remarkup-code .kr, /* Keyword.Reserved */
.remarkup-code .nb, /* Name.Builtin */
.remarkup-code .bp { /* Name.Builtin.Pseudo */
color: #304A96;
}
.remarkup-code .nc, /* Name.Class */
.remarkup-code .nt, /* Name.Tag */
.remarkup-code .vc { /* Name.Variable.Class */
color: #00702A;
}
.remarkup-code .nf, /* Name.Function */
.remarkup-code .nx { /* Name.Other */
color: #004012;
}
.remarkup-code .o, /* Operator */
.remarkup-code .ss { /* Literal.String.Symbol */
color: #AA2211;
}
.remarkup-code .m, /* Literal.Number */
.remarkup-code .mf, /* Literal.Number.Float */
.remarkup-code .mh, /* Literal.Number.Hex */
.remarkup-code .mi, /* Literal.Number.Integer */
.remarkup-code .mo, /* Literal.Number.Oct */
.remarkup-code .il { /* Literal.Number.Integer.Long */
color: #601200;
}
.remarkup-code .gd { color: #A00000 } /* Generic.Deleted */
.remarkup-code .ge { } /* Generic.Emph */
.remarkup-code .gr { color: #FF0000 } /* Generic.Error */
.remarkup-code .gh { color: #000080; } /* Generic.Heading */
.remarkup-code .gi { color: #00A000 } /* Generic.Inserted */
.remarkup-code .go { color: #808080 } /* Generic.Output */
.remarkup-code .gp { color: #000080 } /* Generic.Prompt */
.remarkup-code .gs { } /* Generic.Strong */
.remarkup-code .gu { color: #800080 } /* Generic.Subheading */
.remarkup-code .gt { color: #0040D0 } /* Generic.Traceback */
.remarkup-code .nd { color: #AA22FF } /* Name.Decorator */
.remarkup-code .ni { color: {$lightgreytext} } /* Name.Entity */
.remarkup-code .ne { color: #D2413A } /* Name.Exception */
.remarkup-code .nl { color: #A0A000 } /* Name.Label */
.remarkup-code .nn { color: #0000FF } /* Name.Namespace */
.remarkup-code .ow { color: #AA22FF } /* Operator.Word */
.remarkup-code .w { color: #bbbbbb } /* Text.Whitespace */
.remarkup-code .se { color: #BB6622 } /* Literal.String.Escape */
.remarkup-code .si { color: #BB6688 } /* Literal.String.Interpol */
.remarkup-code .rbw_r { color: red; }
.remarkup-code .rbw_o { color: orange; }
.remarkup-code .rbw_y { color: yellow; }

View file

@ -0,0 +1,150 @@
/**
* @provides syntax-default-css
* @generated
*/
.remarkup-code .bp,
.remarkup-code .cp,
.remarkup-code .kp,
.remarkup-code .kr,
.remarkup-code .nb {
color: #304a96
}
.remarkup-code .c,
.remarkup-code .c1,
.remarkup-code .cm,
.remarkup-code .cs {
color: #74777d
}
.remarkup-code .gd {
color: #a00000
}
.remarkup-code .gh,
.remarkup-code .gp {
color: #000080
}
.remarkup-code .gi {
color: #00a000
}
.remarkup-code .go {
color: #808080
}
.remarkup-code .gr {
color: #ff0000
}
.remarkup-code .gt {
color: #0040d0
}
.remarkup-code .gu {
color: #800080
}
.remarkup-code .hll {
color: #ffffcc
}
.remarkup-code .il,
.remarkup-code .m,
.remarkup-code .mf,
.remarkup-code .mh,
.remarkup-code .mi,
.remarkup-code .mo {
color: #601200
}
.remarkup-code .k,
.remarkup-code .kd,
.remarkup-code .kn,
.remarkup-code .kt {
color: #aa4000
}
.remarkup-code .kc,
.remarkup-code .no {
color: #000a65
}
.remarkup-code .na {
color: #354bb3
}
.remarkup-code .nc,
.remarkup-code .nt,
.remarkup-code .vc {
color: #00702a
}
.remarkup-code .nd,
.remarkup-code .ow {
color: #aa22ff
}
.remarkup-code .ne {
color: #d2413a
}
.remarkup-code .nf,
.remarkup-code .nx {
color: #004012
}
.remarkup-code .ni {
color: #92969d
}
.remarkup-code .nl {
color: #a0a000
}
.remarkup-code .nn {
color: #0000ff
}
.remarkup-code .nv,
.remarkup-code .vg,
.remarkup-code .vi {
color: #001294
}
.remarkup-code .o,
.remarkup-code .ss {
color: #aa2211
}
.remarkup-code .s,
.remarkup-code .s1,
.remarkup-code .s2,
.remarkup-code .sb,
.remarkup-code .sc,
.remarkup-code .sx {
color: #766510
}
.remarkup-code .sd,
.remarkup-code .sh {
color: #000000
}
.remarkup-code .se {
color: #bb6622
}
.remarkup-code .si {
color: #bb66bb
}
.remarkup-code .sr {
color: #bb6688
}
.remarkup-code .w {
color: #bbbbbb
}