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

Embed pastes now support highlight

Summary:
- Added support for highlighting to PhabricatorSourceCodeView
- Added support for highlighting to embed pastes

Test Plan: {F35975}

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T1770

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

authored by

Lauri-Henrik Jalonen and committed by
epriestley
30a17c20 2f9c9817

+61 -10
+28
src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php
··· 26 26 ->setPaste($object) 27 27 ->setHandle($handle); 28 28 29 + if (strlen($options)) { 30 + $parser = new PhutilSimpleOptions(); 31 + $opts = $parser->parse(substr($options, 1)); 32 + 33 + foreach ($opts as $key => $value) { 34 + if ($key == 'lines') { 35 + // placeholder for now 36 + } else if ($key == 'highlight') { 37 + $highlights = explode('&', preg_replace('/\s+/', '', $value)); 38 + 39 + $to_highlight = array(); 40 + foreach ($highlights as $highlight) { 41 + $highlight = explode('-', $highlight); 42 + 43 + if (!empty($highlight)) { 44 + sort($highlight); 45 + $to_highlight = array_merge( 46 + $to_highlight, 47 + range(head($highlight), last($highlight))); 48 + } 49 + } 50 + 51 + $embed_paste->setHighlights(array_unique($to_highlight)); 52 + } 53 + } 54 + 55 + } 56 + 29 57 return $embed_paste->render(); 30 58 31 59 }
+8 -1
src/applications/paste/view/PasteEmbedView.php
··· 4 4 5 5 private $paste; 6 6 private $handle; 7 + private $highlights = array(); 7 8 8 9 public function setPaste(PhabricatorPaste $paste) { 9 10 $this->paste = $paste; ··· 12 13 13 14 public function setHandle(PhabricatorObjectHandle $handle) { 14 15 $this->handle = $handle; 16 + return $this; 17 + } 18 + 19 + public function setHighlights(array $highlights) { 20 + $this->highlights = $highlights; 15 21 return $this; 16 22 } 17 23 ··· 41 47 'div', 42 48 array(), 43 49 id(new PhabricatorSourceCodeView()) 44 - ->setLines($lines)); 50 + ->setLines($lines) 51 + ->setHighlights($this->highlights)); 45 52 46 53 return phutil_tag( 47 54 'div',
+19 -6
src/view/layout/PhabricatorSourceCodeView.php
··· 4 4 5 5 private $lines; 6 6 private $limit; 7 + private $highlights = array(); 7 8 8 9 public function setLimit($limit) { 9 10 $this->limit = $limit; ··· 15 16 return $this; 16 17 } 17 18 19 + public function setHighlights(array $highlights) { 20 + $this->highlights = $highlights; 21 + return $this; 22 + } 23 + 18 24 public function render() { 19 25 require_celerity_resource('phabricator-source-code-view-css'); 20 26 require_celerity_resource('syntax-highlighting-css'); ··· 25 31 26 32 $rows = array(); 27 33 foreach ($this->lines as $line) { 34 + 28 35 $hit_limit = $this->limit && 29 36 ($line_number == $this->limit) && 30 37 (count($this->lines) != $this->limit); ··· 42 49 $content_line = hsprintf("\xE2\x80\x8B%s", $line); 43 50 } 44 51 52 + $row_attributes = array(); 53 + if (in_array($line_number, $this->highlights)) { 54 + $row_attributes['class'] = 'phabricator-source-highlight'; 55 + } 56 + 45 57 // TODO: Provide nice links. 46 58 47 - $rows[] = hsprintf( 48 - '<tr>'. 59 + $rows[] = phutil_tag( 60 + 'tr', 61 + $row_attributes, 62 + hsprintf( 49 63 '<th class="phabricator-source-line">%s</th>'. 50 - '<td class="phabricator-source-code">%s</td>'. 51 - '</tr>', 52 - $content_number, 53 - $content_line); 64 + '<td class="phabricator-source-code">%s</td>', 65 + $content_number, 66 + $content_line)); 54 67 55 68 if ($hit_limit) { 56 69 break;
+2 -3
webroot/rsrc/css/application/paste/paste.css
··· 3 3 */ 4 4 5 5 .paste-embed { 6 - display: inline-block; 7 6 padding: 5px; 8 7 background: #f7f7f7; 8 + border: 1px solid #dbdbdb; 9 9 } 10 10 11 11 .paste-embed-head { 12 - border-bottom: 1px solid #3d3d3d; 13 - padding: 2px; 12 + border-bottom: 1px solid #dbdbdb; 14 13 margin:2px; 15 14 } 16 15
+4
webroot/rsrc/css/layout/phabricator-source-code-view.css
··· 30 30 user-select: none; 31 31 } 32 32 33 + .phabricator-source-highlight { 34 + background: #ff0; 35 + } 36 + 33 37 .phabricator-source-code-summary { 34 38 padding-bottom: 8px; 35 39 }