From 52126c54794ce8eec3e028295d13f3b09fcb66bb Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 24 Jan 2011 17:39:14 -0800 Subject: [PATCH] Add proper syntax highlighting with Phutil. --- .../changeset/DifferentialChangesetParser.php | 23 +++- .../standard/PhabricatorStandardPageView.php | 3 +- webroot/rsrc/css/base.css | 11 ++ webroot/rsrc/css/syntax.css | 119 ++++++++++++++++++ 4 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 webroot/rsrc/css/syntax.css diff --git a/src/applications/differential/parser/changeset/DifferentialChangesetParser.php b/src/applications/differential/parser/changeset/DifferentialChangesetParser.php index 605803b212..1c71ce87c4 100644 --- a/src/applications/differential/parser/changeset/DifferentialChangesetParser.php +++ b/src/applications/differential/parser/changeset/DifferentialChangesetParser.php @@ -311,8 +311,16 @@ class DifferentialChangesetParser { $min_length = min(count($this->old), count($this->new)); for ($ii = 0; $ii < $min_length; $ii++) { if ($this->old[$ii] || $this->new[$ii]) { - $otext = idx($this->old[$ii], 'text', ''); - $ntext = idx($this->new[$ii], 'text', ''); + if (isset($this->old[$ii]['text'])) { + $otext = $this->old[$ii]['text']; + } else { + $otext = ''; + } + if (isset($this->new[$ii]['text'])) { + $ntext = $this->new[$ii]['text']; + } else { + $ntext = ''; + } if ($otext != $ntext && empty($skip_intra[$ii])) { $this->intra[$ii] = ArcanistDiffUtils::generateIntralineDiff( $otext, @@ -560,9 +568,10 @@ class DifferentialChangesetParser { } protected function sourceHighlight($data, $corpus) { -// $result = highlight_code($corpus, $this->filetype); - $result = phutil_escape_html($corpus); - + $result = $this->highlightEngine->highlightSource( + $this->filetype, + $corpus); + $result_lines = explode("\n", $result); foreach ($data as $key => $info) { if (!$info) { @@ -655,6 +664,8 @@ EOSYNTHETIC; $range_len = null, $mask_force = array()) { + $this->highlightEngine = new PhutilDefaultSyntaxHighlighterEngine(); + $this->tryCacheStuff(); $changeset_id = $this->changesetID; @@ -1157,7 +1168,7 @@ EOSYNTHETIC; $table = null; if ($contents) { $table = - ''. + '
'. $contents. '
'; } diff --git a/src/view/page/standard/PhabricatorStandardPageView.php b/src/view/page/standard/PhabricatorStandardPageView.php index a0679d92fc..d5376d2fa6 100755 --- a/src/view/page/standard/PhabricatorStandardPageView.php +++ b/src/view/page/standard/PhabricatorStandardPageView.php @@ -54,7 +54,8 @@ class PhabricatorStandardPageView extends AphrontPageView { protected function getHead() { return - ''; + ''. + ''; } public function setGlyph($glyph) { diff --git a/webroot/rsrc/css/base.css b/webroot/rsrc/css/base.css index dbbe105740..dedfd4699e 100644 --- a/webroot/rsrc/css/base.css +++ b/webroot/rsrc/css/base.css @@ -747,3 +747,14 @@ th.aphront-side-nav-navigation a.aphront-side-nav-selected:hover { margin: 0 40px; max-width: 1162px; } + +/************* meta notice ************************************************ */ + +.differential-meta-notice { + border: 1px solid #ffdd99; + background: #ffeeaa; + font-family: "Verdana"; + font-size: 11px; + padding: 1em; + margin: 0 0 6px 0; +} diff --git a/webroot/rsrc/css/syntax.css b/webroot/rsrc/css/syntax.css new file mode 100644 index 0000000000..706a864d0f --- /dev/null +++ b/webroot/rsrc/css/syntax.css @@ -0,0 +1,119 @@ +.remarkup-code .uu { /* Forbidden Unicode */ + color: #aa0066; +} + +.remarkup-code .over-the-line { + color: #aa0066; + margin-right: 1px; +} + +.remarkup-code td span { + padding: 1px 0 3px; +} + + +.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: #666666; +} + +.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: #999999 } /* 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 */ + +