Permalink
Browse files

Implement text mode for Phabricator Remarkup rules

Test Plan:
  lang=remarkup
  D1
  {D1}
  {C1}
  {F1}
  [[ Test ]]
  iiam
  {meme, src=iiam, above="I\'m not always", below="But I am"}
  @{function:pht}
  @vrana

Reviewers: epriestley, edward

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2617

Differential Revision: https://secure.phabricator.com/D5392
  • Loading branch information...
1 parent c81592b commit efe0c135fece1501ba2a5ec2288b175f09e19e64 @vrana vrana committed Mar 23, 2013
@@ -19,9 +19,19 @@ protected function markupCountdown($matches) {
if (!$countdown) {
return $matches[0];
}
- $id = celerity_generate_unique_node_id();
$engine = $this->getEngine();
+
+ if ($engine->isTextMode()) {
+ $date = $countdown->getDatepoint();
+ $viewer = $engine->getConfig('viewer');
+ if ($viewer) {
+ $date = phabricator_datetime($date, $viewer);
+ }
+ return $engine->storeText($date);
+ }
+
+ $id = celerity_generate_unique_node_id();
$token = $engine->storeText('');
$metadata_key = self::KEY_RULE_COUNTDOWN;
@@ -100,14 +100,20 @@ public function didMarkupText() {
$href = $renderer->getHrefForAtomRef($ref);
}
} else {
- // Here, we're generating commment text or something like that. Just
+ // Here, we're generating comment text or something like that. Just
// link to Diviner and let it sort things out.
$href = id(new PhutilURI('/diviner/find/'))
->setQueryParams($ref_dict + array('jump' => true));
}
- if ($href) {
+ if ($this->getEngine()->isTextMode()) {
+ if ($href) {
+ $link = $title.' <'.PhabricatorEnv::getProductionURI($href).'>';
+ } else {
+ $link = $title;
+ }
+ } else if ($href) {
$link = phutil_tag(
'a',
array(
@@ -27,9 +27,15 @@ public function markupEmbedFile($matches) {
if (!$file) {
return $matches[0];
}
- $phid = $file->getPHID();
$engine = $this->getEngine();
+
+ if ($engine->isTextMode()) {
+ return $engine->storeText($file->getBestURI());
+ }
+
+ $phid = $file->getPHID();
+
$token = $engine->storeText('');
$metadata_key = self::KEY_RULE_EMBED_FILE;
$metadata = $engine->getTextMetadata($metadata_key, array());
@@ -35,6 +35,14 @@ public function markupImageMacro($matches) {
$phid = $this->images[$name];
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid);
+
+ if ($this->getEngine()->isTextMode()) {
+ if ($file) {
+ $name .= ' <'.$file->getBestURI().'>';
+ }
+ return $this->getEngine()->storeText($name);
+ }
+
$style = null;
$src_uri = null;
if ($file) {
@@ -30,11 +30,18 @@ public function markupMeme($matches) {
->alter('uppertext', $options['above'])
->alter('lowertext', $options['below']);
- $img = phutil_tag(
- 'img',
- array(
- 'src' => (string)$uri,
- ));
+ if ($this->getEngine()->isTextMode()) {
+ $img =
+ ($options['above'] != '' ? "\"{$options['above']}\"\n" : '').
+ $options['src'].' <'.PhabricatorEnv::getProductionURI($uri).'>'.
+ ($options['below'] != '' ? "\n\"{$options['below']}\"" : '');
+ } else {
+ $img = phutil_tag(
+ 'img',
+ array(
+ 'src' => (string)$uri,
+ ));
+ }
return $this->getEngine()->storeText($img);
}
@@ -29,6 +29,11 @@ public function apply($text) {
protected function markupMention($matches) {
$engine = $this->getEngine();
+
+ if ($engine->isTextMode()) {
+ return $engine->storeText($matches[0]);
+ }
+
$token = $engine->storeText('');
// Store the original text exactly so we can preserve casing if it doesn't
@@ -29,14 +29,16 @@ public function markupDocumentLink($matches) {
if ($this->getEngine()->getState('toc')) {
$text = $name;
+ } else if ($this->getEngine()->isTextMode()) {
+ return PhabricatorEnv::getProductionURI($href);
} else {
$text = phutil_tag(
- 'a',
- array(
- 'href' => $href,
- 'class' => 'phriction-link',
- ),
- $name);
+ 'a',
+ array(
+ 'href' => $href,
+ 'class' => 'phriction-link',
+ ),
+ $name);
}
return $this->getEngine()->storeText($text);
@@ -50,6 +50,10 @@ protected function renderObjectRef($object, $handle, $anchor, $id) {
}
}
+ if ($this->getEngine()->isTextMode()) {
+ return PhabricatorEnv::getProductionURI($href);
+ }
+
$status_closed = PhabricatorObjectHandleStatus::STATUS_CLOSED;
$attr = array(
@@ -63,6 +67,11 @@ protected function renderObjectRef($object, $handle, $anchor, $id) {
protected function renderObjectEmbed($object, $handle, $options) {
$name = $handle->getFullName();
$href = $handle->getURI();
+
+ if ($this->getEngine()->isTextMode()) {
+ return $name.' <'.PhabricatorEnv::getProductionURI($href).'>';
+ }
+
$attr = array(
'phid' => $handle->getPHID(),
);
@@ -20,6 +20,11 @@ public function apply($text) {
public function markupYoutubeLink() {
$v = idx($this->uri->getQueryParams(), 'v');
+
+ if ($this->getEngine()->isTextMode()) {
+ return $this->getEngine()->storeText('http://youtu.be/'.$v);
+ }
+
$youtube_src = 'https://www.youtube.com/embed/'.$v;
$iframe = hsprintf(
'<div class="embedded-youtube-video">%s</div>',

0 comments on commit efe0c13

Please sign in to comment.