Path: blob/master/src/infrastructure/markup/rule/PhabricatorNavigationRemarkupRule.php
12241 views
<?php12final class PhabricatorNavigationRemarkupRule extends PhutilRemarkupRule {34public function getPriority() {5return 200.0;6}78public function apply($text) {9return preg_replace_callback(10'@{nav\b((?:[^}\\\\]+|\\\\.)*)}@m',11array($this, 'markupNavigation'),12$text);13}1415public function markupNavigation(array $matches) {16if (!$this->isFlatText($matches[0])) {17return $matches[0];18}1920$elements = ltrim($matches[1], ", \n");21$elements = explode('>', $elements);2223$defaults = array(24'name' => null,25'type' => 'link',26'href' => null,27'icon' => null,28);2930$sequence = array();31$parser = new PhutilSimpleOptions();32foreach ($elements as $element) {33if (strpos($element, '=') === false) {34$sequence[] = array(35'name' => trim($element),36) + $defaults;37} else {38$sequence[] = $parser->parse($element) + $defaults;39}40}4142if ($this->getEngine()->isTextMode()) {43return implode(' > ', ipull($sequence, 'name'));44}4546static $icon_names;47if (!$icon_names) {48$icon_names = array_fuse(PHUIIconView::getIcons());49}5051$out = array();52foreach ($sequence as $item) {53$item_name = $item['name'];54$item_color = PHUITagView::COLOR_GREY;55if ($item['type'] == 'instructions') {56$item_name = phutil_tag('em', array(), $item_name);57$item_color = PHUITagView::COLOR_INDIGO;58}5960$tag = id(new PHUITagView())61->setType(PHUITagView::TYPE_SHADE)62->setColor($item_color)63->setName($item_name);6465if ($item['icon']) {66$icon_name = 'fa-'.$item['icon'];67if (isset($icon_names[$icon_name])) {68$tag->setIcon($icon_name);69}70}7172if ($item['href'] !== null) {73if (PhabricatorEnv::isValidRemoteURIForLink($item['href'])) {74$tag->setHref($item['href']);75$tag->setExternal(true);76}77}7879$out[] = $tag;80}8182if ($this->getEngine()->isHTMLMailMode()) {83$arrow_attr = array(84'style' => 'color: #92969D;',85);86$nav_attr = array();87} else {88$arrow_attr = array(89'class' => 'remarkup-nav-sequence-arrow',90);91$nav_attr = array(92'class' => 'remarkup-nav-sequence',93);94}9596$joiner = phutil_tag(97'span',98$arrow_attr,99" \xE2\x86\x92 ");100101$out = phutil_implode_html($joiner, $out);102103$out = phutil_tag(104'span',105$nav_attr,106$out);107108return $this->getEngine()->storeText($out);109}110111}112113114