Page MenuHomePhorge

No OneTemporary

diff --git a/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php b/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php
index 93b987e570..1115bac6c4 100644
--- a/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php
+++ b/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php
@@ -1,60 +1,60 @@
<?php
/**
* @group markup
*/
final class PhabricatorPasteRemarkupRule
extends PhabricatorRemarkupRuleObject {
protected function getObjectNamePrefix() {
return 'P';
}
protected function loadObjects(array $ids) {
$viewer = $this->getEngine()->getConfig('viewer');
return id(new PhabricatorPasteQuery())
->setViewer($viewer)
->withIDs($ids)
->needContent(true)
->execute();
}
protected function renderObjectEmbed($object, $handle, $options) {
$embed_paste = id(new PasteEmbedView())
->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
+ $embed_paste->setLines(preg_replace('/[^0-9]/', '', $value));
} else if ($key == 'highlight') {
- $highlights = explode('&', preg_replace('/\s+/', '', $value));
+ $highlights = preg_split('/,|&/', 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();
}
}
diff --git a/src/applications/paste/view/PasteEmbedView.php b/src/applications/paste/view/PasteEmbedView.php
index 315404cf49..62014ad919 100644
--- a/src/applications/paste/view/PasteEmbedView.php
+++ b/src/applications/paste/view/PasteEmbedView.php
@@ -1,61 +1,69 @@
<?php
final class PasteEmbedView extends AphrontView {
private $paste;
private $handle;
private $highlights = array();
+ private $lines = 30;
public function setPaste(PhabricatorPaste $paste) {
$this->paste = $paste;
return $this;
}
public function setHandle(PhabricatorObjectHandle $handle) {
$this->handle = $handle;
return $this;
}
public function setHighlights(array $highlights) {
$this->highlights = $highlights;
return $this;
}
+ public function setLines($lines) {
+ $this->lines = $lines;
+ }
+
public function render() {
if (!$this->paste) {
throw new Exception("Call setPaste() before render()!");
}
$lines = phutil_split_lines($this->paste->getContent());
require_celerity_resource('paste-css');
$link = phutil_tag(
'a',
array(
'href' => '/P'.$this->paste->getID()
),
$this->handle->getFullName());
$head = phutil_tag(
'div',
array(
'class' => 'paste-embed-head'
),
$link);
+ $body_attributes = array('class' => 'paste-embed-body');
+ if ($this->lines != null) {
+ $body_attributes['style'] = 'max-height: '.$this->lines * (1.15).'em;';
+ }
+
$body = phutil_tag(
'div',
- array(),
+ $body_attributes,
id(new PhabricatorSourceCodeView())
->setLines($lines)
->setHighlights($this->highlights));
return phutil_tag(
'div',
- array(
- 'class' => 'paste-embed'
- ),
+ array('class' => 'paste-embed'),
array($head, $body));
}
}
diff --git a/src/view/layout/PhabricatorSourceCodeView.php b/src/view/layout/PhabricatorSourceCodeView.php
index 70956a4be8..12d051771c 100644
--- a/src/view/layout/PhabricatorSourceCodeView.php
+++ b/src/view/layout/PhabricatorSourceCodeView.php
@@ -1,93 +1,92 @@
<?php
final class PhabricatorSourceCodeView extends AphrontView {
private $lines;
private $limit;
private $highlights = array();
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function setLines(array $lines) {
$this->lines = $lines;
return $this;
}
public function setHighlights(array $highlights) {
- $this->highlights = $highlights;
+ $this->highlights = array_fuse($highlights);
return $this;
}
public function render() {
require_celerity_resource('phabricator-source-code-view-css');
require_celerity_resource('syntax-highlighting-css');
Javelin::initBehavior('phabricator-oncopy', array());
$line_number = 1;
$rows = array();
foreach ($this->lines as $line) {
-
$hit_limit = $this->limit &&
($line_number == $this->limit) &&
(count($this->lines) != $this->limit);
if ($hit_limit) {
$content_number = '';
$content_line = phutil_tag(
'span',
array(
'class' => 'c',
),
pht('...'));
} else {
$content_number = $line_number;
$content_line = hsprintf("\xE2\x80\x8B%s", $line);
}
$row_attributes = array();
- if (in_array($line_number, $this->highlights)) {
+ if (isset($this->highlights[$line_number])) {
$row_attributes['class'] = 'phabricator-source-highlight';
}
// TODO: Provide nice links.
$rows[] = phutil_tag(
'tr',
$row_attributes,
hsprintf(
'<th class="phabricator-source-line">%s</th>'.
'<td class="phabricator-source-code">%s</td>',
$content_number,
$content_line));
if ($hit_limit) {
break;
}
$line_number++;
}
$classes = array();
$classes[] = 'phabricator-source-code-view';
$classes[] = 'remarkup-code';
$classes[] = 'PhabricatorMonospaced';
return phutil_tag(
'div',
array(
'class' => 'phabricator-source-code-container',
),
phutil_tag(
'table',
array(
'class' => implode(' ', $classes),
),
phutil_implode_html('', $rows)));
}
}
diff --git a/webroot/rsrc/css/application/paste/paste.css b/webroot/rsrc/css/application/paste/paste.css
index 9050efe54f..9f0caf08f4 100644
--- a/webroot/rsrc/css/application/paste/paste.css
+++ b/webroot/rsrc/css/application/paste/paste.css
@@ -1,19 +1,23 @@
/**
* @provides paste-css
*/
.paste-embed {
padding: 5px;
background: #f7f7f7;
border: 1px solid #dbdbdb;
}
.paste-embed-head {
border-bottom: 1px solid #dbdbdb;
margin:2px;
}
.paste-embed-head a {
color: #282828;
font-weight: bold;
}
+
+.paste-embed-body {
+ overflow-y: auto;
+}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 19, 17:32 (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1126993
Default Alt Text
(6 KB)

Event Timeline