1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-16 01:31:06 +01:00

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
This commit is contained in:
Lauri-Henrik Jalonen 2013-03-14 09:32:02 -07:00 committed by epriestley
parent 2f9c981716
commit 30a17c2039
5 changed files with 61 additions and 10 deletions

View file

@ -26,6 +26,34 @@ final class PhabricatorPasteRemarkupRule
->setPaste($object) ->setPaste($object)
->setHandle($handle); ->setHandle($handle);
if (strlen($options)) {
$parser = new PhutilSimpleOptions();
$opts = $parser->parse(substr($options, 1));
foreach ($opts as $key => $value) {
if ($key == 'lines') {
// placeholder for now
} else if ($key == 'highlight') {
$highlights = explode('&', preg_replace('/\s+/', '', $value));
$to_highlight = array();
foreach ($highlights as $highlight) {
$highlight = explode('-', $highlight);
if (!empty($highlight)) {
sort($highlight);
$to_highlight = array_merge(
$to_highlight,
range(head($highlight), last($highlight)));
}
}
$embed_paste->setHighlights(array_unique($to_highlight));
}
}
}
return $embed_paste->render(); return $embed_paste->render();
} }

View file

@ -4,6 +4,7 @@ final class PasteEmbedView extends AphrontView {
private $paste; private $paste;
private $handle; private $handle;
private $highlights = array();
public function setPaste(PhabricatorPaste $paste) { public function setPaste(PhabricatorPaste $paste) {
$this->paste = $paste; $this->paste = $paste;
@ -15,6 +16,11 @@ final class PasteEmbedView extends AphrontView {
return $this; return $this;
} }
public function setHighlights(array $highlights) {
$this->highlights = $highlights;
return $this;
}
public function render() { public function render() {
if (!$this->paste) { if (!$this->paste) {
throw new Exception("Call setPaste() before render()!"); throw new Exception("Call setPaste() before render()!");
@ -41,7 +47,8 @@ final class PasteEmbedView extends AphrontView {
'div', 'div',
array(), array(),
id(new PhabricatorSourceCodeView()) id(new PhabricatorSourceCodeView())
->setLines($lines)); ->setLines($lines)
->setHighlights($this->highlights));
return phutil_tag( return phutil_tag(
'div', 'div',

View file

@ -4,6 +4,7 @@ final class PhabricatorSourceCodeView extends AphrontView {
private $lines; private $lines;
private $limit; private $limit;
private $highlights = array();
public function setLimit($limit) { public function setLimit($limit) {
$this->limit = $limit; $this->limit = $limit;
@ -15,6 +16,11 @@ final class PhabricatorSourceCodeView extends AphrontView {
return $this; return $this;
} }
public function setHighlights(array $highlights) {
$this->highlights = $highlights;
return $this;
}
public function render() { public function render() {
require_celerity_resource('phabricator-source-code-view-css'); require_celerity_resource('phabricator-source-code-view-css');
require_celerity_resource('syntax-highlighting-css'); require_celerity_resource('syntax-highlighting-css');
@ -25,6 +31,7 @@ final class PhabricatorSourceCodeView extends AphrontView {
$rows = array(); $rows = array();
foreach ($this->lines as $line) { foreach ($this->lines as $line) {
$hit_limit = $this->limit && $hit_limit = $this->limit &&
($line_number == $this->limit) && ($line_number == $this->limit) &&
(count($this->lines) != $this->limit); (count($this->lines) != $this->limit);
@ -42,15 +49,21 @@ final class PhabricatorSourceCodeView extends AphrontView {
$content_line = hsprintf("\xE2\x80\x8B%s", $line); $content_line = hsprintf("\xE2\x80\x8B%s", $line);
} }
$row_attributes = array();
if (in_array($line_number, $this->highlights)) {
$row_attributes['class'] = 'phabricator-source-highlight';
}
// TODO: Provide nice links. // TODO: Provide nice links.
$rows[] = hsprintf( $rows[] = phutil_tag(
'<tr>'. 'tr',
$row_attributes,
hsprintf(
'<th class="phabricator-source-line">%s</th>'. '<th class="phabricator-source-line">%s</th>'.
'<td class="phabricator-source-code">%s</td>'. '<td class="phabricator-source-code">%s</td>',
'</tr>', $content_number,
$content_number, $content_line));
$content_line);
if ($hit_limit) { if ($hit_limit) {
break; break;

View file

@ -3,14 +3,13 @@
*/ */
.paste-embed { .paste-embed {
display: inline-block;
padding: 5px; padding: 5px;
background: #f7f7f7; background: #f7f7f7;
border: 1px solid #dbdbdb;
} }
.paste-embed-head { .paste-embed-head {
border-bottom: 1px solid #3d3d3d; border-bottom: 1px solid #dbdbdb;
padding: 2px;
margin:2px; margin:2px;
} }

View file

@ -30,6 +30,10 @@
user-select: none; user-select: none;
} }
.phabricator-source-highlight {
background: #ff0;
}
.phabricator-source-code-summary { .phabricator-source-code-summary {
padding-bottom: 8px; padding-bottom: 8px;
} }