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',