1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-02 10:51:01 +01:00

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
This commit is contained in:
Jakub Vrana 2013-03-22 17:33:36 -07:00
parent c81592bf5c
commit efe0c135fe
9 changed files with 73 additions and 15 deletions

View file

@ -19,9 +19,19 @@ final class PhabricatorCountdownRemarkupRule extends PhutilRemarkupRule {
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;

View file

@ -100,14 +100,20 @@ final class DivinerRemarkupRuleSymbol extends PhutilRemarkupRule {
$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(

View file

@ -27,9 +27,15 @@ final class PhabricatorRemarkupRuleEmbedFile
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());

View file

@ -35,6 +35,14 @@ final class PhabricatorRemarkupRuleImageMacro
$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) {

View file

@ -30,11 +30,18 @@ final class PhabricatorRemarkupRuleMeme
->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);
}

View file

@ -29,6 +29,11 @@ final class PhabricatorRemarkupRuleMention
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

View file

@ -29,14 +29,16 @@ final class PhrictionRemarkupRule
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);

View file

@ -50,6 +50,10 @@ abstract class PhabricatorRemarkupRuleObject
}
}
if ($this->getEngine()->isTextMode()) {
return PhabricatorEnv::getProductionURI($href);
}
$status_closed = PhabricatorObjectHandleStatus::STATUS_CLOSED;
$attr = array(
@ -63,6 +67,11 @@ abstract class PhabricatorRemarkupRuleObject
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(),
);

View file

@ -20,6 +20,11 @@ final class PhabricatorRemarkupRuleYoutube
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>',