1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +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)
->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();
}

View file

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

View file

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

View file

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

View file

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