@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix weird remarkup linewrapping on a few instructions forms, plus move toward fixing Phame/CORGI remarkup issues

Summary:
Fixes T10381. When we converted to `PHUIRemarkupView`, some instructional text got linebreaks added when it shouldn't have them (the source is written in PHP and wrapped at 80 characters, but the output should flow naturally).

Fix this so we don't preserve linebreaks.

This also makes `PHUIRemarkupView` a little more powerful and inches us toward fixing Phame/CORGI remarkup issues, getting rid of `PhabricatorMarkupInterface` / `PhabricatorMarkupOneOff`, and dropping all the application hard-coding in `PhabricatorMarkupEngine`.

Test Plan:
- Grepped for all callsites, looking for callsites which accept remarkup written in `<<<HEREDOC` format.
- Viewed form instructions, Conduit API methods, HTTP parameter edit instructions.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10381

Differential Revision: https://secure.phabricator.com/D15963

+96 -29
+5
src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php
··· 598 598 599 599 $view = new PHUIRemarkupView($viewer, $remarkup); 600 600 601 + $view->setRemarkupOptions( 602 + array( 603 + PHUIRemarkupView::OPTION_PRESERVE_LINEBREAKS => false, 604 + )); 605 + 601 606 return id(new PHUIBoxView()) 602 607 ->appendChild($view) 603 608 ->addPadding(PHUI::PADDING_LARGE);
+8 -1
src/applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php
··· 313 313 314 314 protected function renderInstructions($corpus) { 315 315 $viewer = $this->getUser(); 316 - return new PHUIRemarkupView($viewer, $corpus); 316 + $view = new PHUIRemarkupView($viewer, $corpus); 317 + 318 + $view->setRemarkupOptions( 319 + array( 320 + PHUIRemarkupView::OPTION_PRESERVE_LINEBREAKS => false, 321 + )); 322 + 323 + return $view; 317 324 } 318 325 319 326 }
+1
src/infrastructure/markup/PhabricatorMarkupEngine.php
··· 470 470 $engine = new PhutilRemarkupEngine(); 471 471 472 472 $engine->setConfig('preserve-linebreaks', $options['preserve-linebreaks']); 473 + 473 474 $engine->setConfig('pygments.enabled', $options['pygments']); 474 475 $engine->setConfig( 475 476 'uri.allowed-protocols',
+14
src/infrastructure/markup/PhabricatorMarkupOneOff.php
··· 10 10 private $content; 11 11 private $preserveLinebreaks; 12 12 private $engineRuleset; 13 + private $engine; 13 14 private $disableCache; 14 15 15 16 public function setEngineRuleset($engine_ruleset) { ··· 35 36 return $this->content; 36 37 } 37 38 39 + public function setEngine(PhutilMarkupEngine $engine) { 40 + $this->engine = $engine; 41 + return $this; 42 + } 43 + 44 + public function getEngine() { 45 + return $this->engine; 46 + } 47 + 38 48 public function setDisableCache($disable_cache) { 39 49 $this->disableCache = $disable_cache; 40 50 return $this; ··· 49 59 } 50 60 51 61 public function newMarkupEngine($field) { 62 + if ($this->engine) { 63 + return $this->engine; 64 + } 65 + 52 66 if ($this->engineRuleset) { 53 67 return PhabricatorMarkupEngine::getEngine($this->engineRuleset); 54 68 } else if ($this->preserveLinebreaks) {
+51 -19
src/infrastructure/markup/view/PHUIRemarkupView.php
··· 12 12 final class PHUIRemarkupView extends AphrontView { 13 13 14 14 private $corpus; 15 - private $markupType; 16 15 private $contextObject; 16 + private $options; 17 17 18 - const DOCUMENT = 'document'; 18 + // TODO: In the long run, rules themselves should define available options. 19 + // For now, just define constants here so we can more easily replace things 20 + // later once this is cleaned up. 21 + const OPTION_PRESERVE_LINEBREAKS = 'preserve-linebreaks'; 19 22 20 23 public function __construct(PhabricatorUser $viewer, $corpus) { 21 24 $this->setUser($viewer); 22 25 $this->corpus = $corpus; 23 26 } 24 27 25 - private function setMarkupType($type) { 26 - $this->markupType($type); 27 - return $this; 28 - } 29 - 30 28 public function setContextObject($context_object) { 31 29 $this->contextObject = $context_object; 32 30 return $this; ··· 36 34 return $this->contextObject; 37 35 } 38 36 37 + public function setRemarkupOption($key, $value) { 38 + $this->options[$key] = $value; 39 + return $this; 40 + } 41 + 42 + public function setRemarkupOptions(array $options) { 43 + foreach ($options as $key => $value) { 44 + $this->setRemarkupOption($key, $value); 45 + } 46 + return $this; 47 + } 48 + 39 49 public function render() { 40 - $viewer = $this->getUser(); 50 + $viewer = $this->getViewer(); 41 51 $corpus = $this->corpus; 42 52 $context = $this->getContextObject(); 43 53 54 + $options = $this->options; 55 + 56 + $oneoff = id(new PhabricatorMarkupOneOff()) 57 + ->setContent($corpus); 58 + 59 + if ($options) { 60 + $oneoff->setEngine($this->getEngine()); 61 + } else { 62 + $oneoff->setPreserveLinebreaks(true); 63 + } 64 + 44 65 $content = PhabricatorMarkupEngine::renderOneObject( 45 - id(new PhabricatorMarkupOneOff()) 46 - ->setPreserveLinebreaks(true) 47 - ->setContent($corpus), 66 + $oneoff, 48 67 'default', 49 68 $viewer, 50 69 $context); 51 70 52 - if ($this->markupType == self::DOCUMENT) { 53 - return phutil_tag( 54 - 'div', 55 - array( 56 - 'class' => 'phabricator-remarkup phui-document-view', 57 - ), 58 - $content); 71 + return $content; 72 + } 73 + 74 + private function getEngine() { 75 + $options = $this->options; 76 + $viewer = $this->getViewer(); 77 + 78 + $viewer_key = $viewer->getCacheFragment(); 79 + 80 + ksort($options); 81 + $engine_key = serialize($options); 82 + $engine_key = PhabricatorHash::digestForIndex($engine_key); 83 + 84 + $cache = PhabricatorCaches::getRequestCache(); 85 + $cache_key = "remarkup.engine({$viewer}, {$engine_key})"; 86 + 87 + $engine = $cache->getKey($cache_key); 88 + if (!$engine) { 89 + $engine = PhabricatorMarkupEngine::newMarkupEngine($options); 90 + $cache->setKey($cache_key, $engine); 59 91 } 60 92 61 - return $content; 93 + return $engine; 62 94 } 63 95 64 96 }
+13 -2
src/view/form/AphrontFormView.php
··· 84 84 } 85 85 86 86 public function appendRemarkupInstructions($remarkup) { 87 - return $this->appendInstructions( 88 - new PHUIRemarkupView($this->getViewer(), $remarkup)); 87 + $view = $this->newInstructionsRemarkupView($remarkup); 88 + return $this->appendInstructions($view); 89 + } 90 + 91 + public function newInstructionsRemarkupView($remarkup) { 92 + $viewer = $this->getViewer(); 93 + $view = new PHUIRemarkupView($viewer, $remarkup); 94 + 95 + $view->setRemarkupOptions( 96 + array( 97 + PHUIRemarkupView::OPTION_PRESERVE_LINEBREAKS => false, 98 + )); 89 99 100 + return $view; 90 101 } 91 102 92 103 public function buildLayoutView() {
+4 -7
src/view/form/PHUIFormLayoutView.php
··· 31 31 } 32 32 33 33 public function appendRemarkupInstructions($remarkup) { 34 - if ($this->getUser() === null) { 35 - throw new PhutilInvalidStateException('setUser'); 36 - } 34 + $view = id(new AphrontFormView()) 35 + ->setViewer($this->getViewer()) 36 + ->newInstructionsRemarkupView($remarkup); 37 37 38 - $viewer = $this->getUser(); 39 - $instructions = new PHUIRemarkupView($viewer, $remarkup); 40 - 41 - return $this->appendInstructions($instructions); 38 + return $this->appendInstructions($view); 42 39 } 43 40 44 41 public function render() {