mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 08:42:41 +01:00
Simplify and generalize remarkup engine construction
Summary: Depends on D6395. - Now that inline rules have explicit priorities, they can just go in applications in all cases. - We don't need the inline rule conditionals anymore after D6395. Test Plan: Wrote remarkup with mentions, phriction links, countdowns, etc. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D6396
This commit is contained in:
parent
f548dc0067
commit
c5f2e617d8
7 changed files with 43 additions and 20 deletions
|
@ -29,6 +29,12 @@ final class PhabricatorApplicationCountdown extends PhabricatorApplication {
|
|||
return self::GROUP_UTILITIES;
|
||||
}
|
||||
|
||||
public function getRemarkupRules() {
|
||||
return array(
|
||||
new PhabricatorCountdownRemarkupRule(),
|
||||
);
|
||||
}
|
||||
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
'/countdown/' => array(
|
||||
|
|
|
@ -39,6 +39,12 @@ final class PhabricatorApplicationDiviner extends PhabricatorApplication {
|
|||
return self::GROUP_COMMUNICATION;
|
||||
}
|
||||
|
||||
public function getRemarkupRules() {
|
||||
return array(
|
||||
new DivinerRemarkupRuleSymbol(),
|
||||
);
|
||||
}
|
||||
|
||||
public function buildMainMenuItems(
|
||||
PhabricatorUser $user,
|
||||
PhabricatorController $controller = null) {
|
||||
|
|
|
@ -34,6 +34,13 @@ final class PhabricatorApplicationFiles extends PhabricatorApplication {
|
|||
return false;
|
||||
}
|
||||
|
||||
public function getRemarkupRules() {
|
||||
return array(
|
||||
new PhabricatorRemarkupRuleEmbedFile(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
'/F(?P<id>[1-9]\d*)' => 'PhabricatorFileShortcutController',
|
||||
|
|
|
@ -54,6 +54,12 @@ final class PhabricatorApplicationPeople extends PhabricatorApplication {
|
|||
);
|
||||
}
|
||||
|
||||
public function getRemarkupRules() {
|
||||
return array(
|
||||
new PhabricatorRemarkupRuleMention(),
|
||||
);
|
||||
}
|
||||
|
||||
public function buildMainMenuItems(
|
||||
PhabricatorUser $user,
|
||||
PhabricatorController $controller = null) {
|
||||
|
|
|
@ -22,6 +22,12 @@ final class PhabricatorApplicationPhriction extends PhabricatorApplication {
|
|||
return "\xE2\x9A\xA1";
|
||||
}
|
||||
|
||||
public function getRemarkupRules() {
|
||||
return array(
|
||||
new PhrictionRemarkupRule(),
|
||||
);
|
||||
}
|
||||
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
// Match "/w/" with slug "/".
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
final class PhrictionRemarkupRule
|
||||
extends PhutilRemarkupRule {
|
||||
|
||||
public function getPriority() {
|
||||
return 350.0;
|
||||
}
|
||||
|
||||
public function apply($text) {
|
||||
return preg_replace_callback(
|
||||
'@\B\\[\\[([^|\\]]+)(?:\\|([^\\]]+))?\\]\\]\B@U',
|
||||
|
@ -17,15 +21,17 @@ final class PhrictionRemarkupRule
|
|||
|
||||
$link = trim($matches[1]);
|
||||
$name = trim(idx($matches, 2, $link));
|
||||
$name = explode('/', trim($name, '/'));
|
||||
$name = end($name);
|
||||
if (empty($matches[2])) {
|
||||
$name = explode('/', trim($name, '/'));
|
||||
$name = end($name);
|
||||
}
|
||||
|
||||
$uri = new PhutilURI($link);
|
||||
$slug = $uri->getPath();
|
||||
$fragment = $uri->getFragment();
|
||||
$slug = PhabricatorSlug::normalize($slug);
|
||||
$slug = PhrictionDocument::getSlugURI($slug);
|
||||
$href = (string) id(new PhutilURI($slug))->setFragment($fragment);
|
||||
$href = (string)id(new PhutilURI($slug))->setFragment($fragment);
|
||||
|
||||
if ($this->getEngine()->getState('toc')) {
|
||||
$text = $name;
|
||||
|
|
|
@ -457,20 +457,12 @@ final class PhabricatorMarkupEngine {
|
|||
}
|
||||
|
||||
$rules[] = new PhutilRemarkupRuleHyperlink();
|
||||
$rules[] = new PhrictionRemarkupRule();
|
||||
|
||||
$rules[] = new PhabricatorRemarkupRuleEmbedFile();
|
||||
$rules[] = new PhabricatorCountdownRemarkupRule();
|
||||
|
||||
if ($options['macros']) {
|
||||
$rules[] = new PhabricatorRemarkupRuleImageMacro();
|
||||
$rules[] = new PhabricatorRemarkupRuleMeme();
|
||||
}
|
||||
|
||||
$rules[] = new DivinerRemarkupRuleSymbol();
|
||||
|
||||
$rules[] = new PhabricatorRemarkupRuleMention();
|
||||
|
||||
$rules[] = new PhutilRemarkupRuleBold();
|
||||
$rules[] = new PhutilRemarkupRuleItalic();
|
||||
$rules[] = new PhutilRemarkupRuleDel();
|
||||
|
@ -485,7 +477,6 @@ final class PhabricatorMarkupEngine {
|
|||
$blocks[] = new PhutilRemarkupEngineRemarkupNoteBlockRule();
|
||||
$blocks[] = new PhutilRemarkupEngineRemarkupTableBlockRule();
|
||||
$blocks[] = new PhutilRemarkupEngineRemarkupSimpleTableBlockRule();
|
||||
$blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
|
||||
|
||||
$custom_block_rule_classes = $options['custom-block'];
|
||||
if ($custom_block_rule_classes) {
|
||||
|
@ -494,15 +485,10 @@ final class PhabricatorMarkupEngine {
|
|||
}
|
||||
}
|
||||
|
||||
$blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
|
||||
|
||||
foreach ($blocks as $block) {
|
||||
if ($block instanceof PhutilRemarkupEngineRemarkupLiteralBlockRule) {
|
||||
$literal_rules = array();
|
||||
$literal_rules[] = new PhutilRemarkupRuleLinebreaks();
|
||||
$block->setMarkupRules($literal_rules);
|
||||
} else if (
|
||||
!($block instanceof PhutilRemarkupEngineRemarkupCodeBlockRule)) {
|
||||
$block->setMarkupRules($rules);
|
||||
}
|
||||
$block->setMarkupRules($rules);
|
||||
}
|
||||
|
||||
$engine->setBlockRules($blocks);
|
||||
|
|
Loading…
Reference in a new issue