public function addRemarkupSection($header, $text) { try { $engine = PhabricatorMarkupEngine::newMarkupEngine(array()); $engine->setConfig('viewer', $this->getViewer()); $engine->setMode(PhutilRemarkupEngine::MODE_TEXT); $styled_text = $engine->markupText($text); $this->addPlaintextSection($header, $styled_text); } catch (Exception $ex) { phlog($ex); $this->addTextSection($header, $text); } try { $mail_engine = PhabricatorMarkupEngine::newMarkupEngine(array()); $mail_engine->setConfig('viewer', $this->getViewer()); $mail_engine->setMode(PhutilRemarkupEngine::MODE_HTML_MAIL); $mail_engine->setConfig('uri.base', PhabricatorEnv::getProductionURI('/')); $html = $mail_engine->markupText($text); $this->addHTMLSection($header, $html); } catch (Exception $ex) { phlog($ex); $this->addHTMLSection($header, $text); } return $this; }
public function addRemarkupSection($text) { try { $engine = PhabricatorMarkupEngine::newMarkupEngine(array()); $engine->setConfig('viewer', $this->getViewer()); $engine->setMode(PhutilRemarkupEngine::MODE_TEXT); $styled_text = $engine->markupText($text); $this->sections[] = $styled_text; } catch (Exception $ex) { phlog($ex); $this->sections[] = $text; } try { $mail_engine = PhabricatorMarkupEngine::newMarkupEngine(array()); $mail_engine->setConfig('viewer', $this->getViewer()); $mail_engine->setMode(PhutilRemarkupEngine::MODE_HTML_MAIL); $mail_engine->setConfig('uri.base', PhabricatorEnv::getProductionURI('/')); $html = $mail_engine->markupText($text); $this->htmlSections[] = $html; } catch (Exception $ex) { phlog($ex); $this->htmlSections[] = phutil_escape_html_newlines(phutil_tag('div', array(), $text)); } return $this; }
private function getEngine() { $options = $this->options; $viewer = $this->getViewer(); $viewer_key = $viewer->getCacheFragment(); ksort($options); $engine_key = serialize($options); $engine_key = PhabricatorHash::digestForIndex($engine_key); $cache = PhabricatorCaches::getRequestCache(); $cache_key = "remarkup.engine({$viewer_key}, {$engine_key})"; $engine = $cache->getKey($cache_key); if (!$engine) { $engine = PhabricatorMarkupEngine::newMarkupEngine($options); $cache->setKey($cache_key, $engine); } return $engine; }
public function renderForAsanaBridge($implied_context = false) { $data = $this->getStoryData(); $comment = $data->getValue('content'); $author_name = $this->getHandle($this->getAuthorPHID())->getName(); $action = $this->getValue('action'); $verb = PhabricatorAuditActionConstants::getActionPastTenseVerb($action); $commit_phid = $this->getPrimaryObjectPHID(); $commit_name = $this->getHandle($commit_phid)->getFullName(); if ($implied_context) { $title = "{$author_name} {$verb} this commit."; } else { $title = "{$author_name} {$verb} commit {$commit_name}."; } if (strlen($comment)) { $engine = PhabricatorMarkupEngine::newMarkupEngine(array())->setConfig('viewer', new PhabricatorUser())->setMode(PhutilRemarkupEngine::MODE_TEXT); $comment = $engine->markupText($comment); $title .= "\n\n"; $title .= $comment; } return $title; }
public function newMarkupEngine($field) { return PhabricatorMarkupEngine::newMarkupEngine(array()); }
public function renderForAsanaBridge($implied_context = false) { $data = $this->getStoryData(); $comment = $data->getValue('feedback_content'); $author_name = $this->getHandle($this->getAuthorPHID())->getName(); $action = $this->getValue('action'); $engine = PhabricatorMarkupEngine::newMarkupEngine(array())->setConfig('viewer', new PhabricatorUser())->setMode(PhutilRemarkupEngine::MODE_TEXT); $revision_phid = $this->getPrimaryObjectPHID(); $revision_name = $this->getHandle($revision_phid)->getFullName(); if ($implied_context) { $title = DifferentialAction::getBasicStoryText($action, $author_name); } else { switch ($action) { case DifferentialAction::ACTION_COMMENT: $title = pht('%s commented on revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_ACCEPT: $title = pht('%s accepted revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_REJECT: $title = pht('%s requested changes to revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_RETHINK: $title = pht('%s planned changes to revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_ABANDON: $title = pht('%s abandoned revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_CLOSE: $title = pht('%s closed revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_REQUEST: $title = pht('%s requested a review of revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_RECLAIM: $title = pht('%s reclaimed revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_UPDATE: $title = pht('%s updated revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_RESIGN: $title = pht('%s resigned from revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_SUMMARIZE: $title = pht('%s summarized revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_TESTPLAN: $title = pht('%s explained the test plan for revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_CREATE: $title = pht('%s created revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_ADDREVIEWERS: $title = pht('%s added reviewers to revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_ADDCCS: $title = pht('%s added CCs to revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_CLAIM: $title = pht('%s commandeered revision %s', $author_name, $revision_name); break; case DifferentialAction::ACTION_REOPEN: $title = pht('%s reopened revision %s', $author_name, $revision_name); break; case DifferentialTransaction::TYPE_INLINE: $title = pht('%s added inline comments to %s', $author_name, $revision_name); break; default: $title = pht('%s edited revision %s', $author_name, $revision_name); break; } } if (strlen($comment)) { $comment = $engine->markupText($comment); $title .= "\n\n"; $title .= $comment; } // Roughly render inlines into the comment. $xaction_phids = $data->getValue('temporaryTransactionPHIDs'); if ($xaction_phids) { $inlines = id(new DifferentialTransactionQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs($xaction_phids)->needComments(true)->withTransactionTypes(array(DifferentialTransaction::TYPE_INLINE))->execute(); if ($inlines) { $title .= "\n\n"; $title .= pht('Inline Comments'); $title .= "\n"; $changeset_ids = array(); foreach ($inlines as $inline) { $changeset_ids[] = $inline->getComment()->getChangesetID(); } $changesets = id(new DifferentialChangeset())->loadAllWhere('id IN (%Ld)', $changeset_ids); foreach ($inlines as $inline) { $comment = $inline->getComment(); $changeset = idx($changesets, $comment->getChangesetID()); if (!$changeset) { continue; } $filename = $changeset->getDisplayFilename(); $linenumber = $comment->getLineNumber(); $inline_text = $engine->markupText($comment->getContent()); $inline_text = rtrim($inline_text); $title .= "{$filename}:{$linenumber} {$inline_text}\n"; } } } return $title; }
public function renderAsTextForDoorkeeper(DoorkeeperFeedStoryPublisher $publisher, PhabricatorFeedStory $story, array $xactions) { $body = parent::renderAsTextForDoorkeeper($publisher, $story, $xactions); $inlines = array(); foreach ($xactions as $xaction) { if ($xaction->getTransactionType() == self::TYPE_INLINE) { $inlines[] = $xaction; } } // TODO: This is a bit gross, but far less bad than it used to be. It // could be further cleaned up at some point. if ($inlines) { $engine = PhabricatorMarkupEngine::newMarkupEngine(array())->setConfig('viewer', new PhabricatorUser())->setMode(PhutilRemarkupEngine::MODE_TEXT); $body .= "\n\n"; $body .= pht('Inline Comments'); $body .= "\n"; $changeset_ids = array(); foreach ($inlines as $inline) { $changeset_ids[] = $inline->getComment()->getChangesetID(); } $changesets = id(new DifferentialChangeset())->loadAllWhere('id IN (%Ld)', $changeset_ids); foreach ($inlines as $inline) { $comment = $inline->getComment(); $changeset = idx($changesets, $comment->getChangesetID()); if (!$changeset) { continue; } $filename = $changeset->getDisplayFilename(); $linenumber = $comment->getLineNumber(); $inline_text = $engine->markupText($comment->getContent()); $inline_text = rtrim($inline_text); $body .= "{$filename}:{$linenumber} {$inline_text}\n"; } } return $body; }
protected function getBlockMarkupEngine() { $engine = PhabricatorMarkupEngine::newMarkupEngine(array()); $engine->setConfig('preserve-linebreaks', false); $engine->setConfig('viewer', new PhabricatorUser()); $engine->setConfig('diviner.renderer', $this); $engine->setConfig('header.generate-toc', true); return $engine; }
private function renderRemarkupContent($content, $is_html) { $viewer = $this->getViewer(); $production_uri = PhabricatorEnv::getProductionURI('/'); if ($is_html) { $mode = PhutilRemarkupEngine::MODE_HTML_MAIL; } else { $mode = PhutilRemarkupEngine::MODE_TEXT; } $attributes = array('style' => 'padding: 0; margin: 8px;'); $engine = PhabricatorMarkupEngine::newMarkupEngine(array())->setConfig('viewer', $viewer)->setConfig('uri.base', $production_uri)->setConfig('default.p.attributes', $attributes)->setMode($mode); try { return $engine->markupText($content); } catch (Exception $ex) { return $content; } }