1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-02 03:32:42 +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:
epriestley 2013-07-09 16:23:33 -07:00
parent f548dc0067
commit c5f2e617d8
7 changed files with 43 additions and 20 deletions

View file

@ -29,6 +29,12 @@ final class PhabricatorApplicationCountdown extends PhabricatorApplication {
return self::GROUP_UTILITIES; return self::GROUP_UTILITIES;
} }
public function getRemarkupRules() {
return array(
new PhabricatorCountdownRemarkupRule(),
);
}
public function getRoutes() { public function getRoutes() {
return array( return array(
'/countdown/' => array( '/countdown/' => array(

View file

@ -39,6 +39,12 @@ final class PhabricatorApplicationDiviner extends PhabricatorApplication {
return self::GROUP_COMMUNICATION; return self::GROUP_COMMUNICATION;
} }
public function getRemarkupRules() {
return array(
new DivinerRemarkupRuleSymbol(),
);
}
public function buildMainMenuItems( public function buildMainMenuItems(
PhabricatorUser $user, PhabricatorUser $user,
PhabricatorController $controller = null) { PhabricatorController $controller = null) {

View file

@ -34,6 +34,13 @@ final class PhabricatorApplicationFiles extends PhabricatorApplication {
return false; return false;
} }
public function getRemarkupRules() {
return array(
new PhabricatorRemarkupRuleEmbedFile(),
);
}
public function getRoutes() { public function getRoutes() {
return array( return array(
'/F(?P<id>[1-9]\d*)' => 'PhabricatorFileShortcutController', '/F(?P<id>[1-9]\d*)' => 'PhabricatorFileShortcutController',

View file

@ -54,6 +54,12 @@ final class PhabricatorApplicationPeople extends PhabricatorApplication {
); );
} }
public function getRemarkupRules() {
return array(
new PhabricatorRemarkupRuleMention(),
);
}
public function buildMainMenuItems( public function buildMainMenuItems(
PhabricatorUser $user, PhabricatorUser $user,
PhabricatorController $controller = null) { PhabricatorController $controller = null) {

View file

@ -22,6 +22,12 @@ final class PhabricatorApplicationPhriction extends PhabricatorApplication {
return "\xE2\x9A\xA1"; return "\xE2\x9A\xA1";
} }
public function getRemarkupRules() {
return array(
new PhrictionRemarkupRule(),
);
}
public function getRoutes() { public function getRoutes() {
return array( return array(
// Match "/w/" with slug "/". // Match "/w/" with slug "/".

View file

@ -6,6 +6,10 @@
final class PhrictionRemarkupRule final class PhrictionRemarkupRule
extends PhutilRemarkupRule { extends PhutilRemarkupRule {
public function getPriority() {
return 350.0;
}
public function apply($text) { public function apply($text) {
return preg_replace_callback( return preg_replace_callback(
'@\B\\[\\[([^|\\]]+)(?:\\|([^\\]]+))?\\]\\]\B@U', '@\B\\[\\[([^|\\]]+)(?:\\|([^\\]]+))?\\]\\]\B@U',
@ -17,15 +21,17 @@ final class PhrictionRemarkupRule
$link = trim($matches[1]); $link = trim($matches[1]);
$name = trim(idx($matches, 2, $link)); $name = trim(idx($matches, 2, $link));
$name = explode('/', trim($name, '/')); if (empty($matches[2])) {
$name = end($name); $name = explode('/', trim($name, '/'));
$name = end($name);
}
$uri = new PhutilURI($link); $uri = new PhutilURI($link);
$slug = $uri->getPath(); $slug = $uri->getPath();
$fragment = $uri->getFragment(); $fragment = $uri->getFragment();
$slug = PhabricatorSlug::normalize($slug); $slug = PhabricatorSlug::normalize($slug);
$slug = PhrictionDocument::getSlugURI($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')) { if ($this->getEngine()->getState('toc')) {
$text = $name; $text = $name;

View file

@ -457,20 +457,12 @@ final class PhabricatorMarkupEngine {
} }
$rules[] = new PhutilRemarkupRuleHyperlink(); $rules[] = new PhutilRemarkupRuleHyperlink();
$rules[] = new PhrictionRemarkupRule();
$rules[] = new PhabricatorRemarkupRuleEmbedFile();
$rules[] = new PhabricatorCountdownRemarkupRule();
if ($options['macros']) { if ($options['macros']) {
$rules[] = new PhabricatorRemarkupRuleImageMacro(); $rules[] = new PhabricatorRemarkupRuleImageMacro();
$rules[] = new PhabricatorRemarkupRuleMeme(); $rules[] = new PhabricatorRemarkupRuleMeme();
} }
$rules[] = new DivinerRemarkupRuleSymbol();
$rules[] = new PhabricatorRemarkupRuleMention();
$rules[] = new PhutilRemarkupRuleBold(); $rules[] = new PhutilRemarkupRuleBold();
$rules[] = new PhutilRemarkupRuleItalic(); $rules[] = new PhutilRemarkupRuleItalic();
$rules[] = new PhutilRemarkupRuleDel(); $rules[] = new PhutilRemarkupRuleDel();
@ -485,7 +477,6 @@ final class PhabricatorMarkupEngine {
$blocks[] = new PhutilRemarkupEngineRemarkupNoteBlockRule(); $blocks[] = new PhutilRemarkupEngineRemarkupNoteBlockRule();
$blocks[] = new PhutilRemarkupEngineRemarkupTableBlockRule(); $blocks[] = new PhutilRemarkupEngineRemarkupTableBlockRule();
$blocks[] = new PhutilRemarkupEngineRemarkupSimpleTableBlockRule(); $blocks[] = new PhutilRemarkupEngineRemarkupSimpleTableBlockRule();
$blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
$custom_block_rule_classes = $options['custom-block']; $custom_block_rule_classes = $options['custom-block'];
if ($custom_block_rule_classes) { if ($custom_block_rule_classes) {
@ -494,15 +485,10 @@ final class PhabricatorMarkupEngine {
} }
} }
$blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
foreach ($blocks as $block) { foreach ($blocks as $block) {
if ($block instanceof PhutilRemarkupEngineRemarkupLiteralBlockRule) { $block->setMarkupRules($rules);
$literal_rules = array();
$literal_rules[] = new PhutilRemarkupRuleLinebreaks();
$block->setMarkupRules($literal_rules);
} else if (
!($block instanceof PhutilRemarkupEngineRemarkupCodeBlockRule)) {
$block->setMarkupRules($rules);
}
} }
$engine->setBlockRules($blocks); $engine->setBlockRules($blocks);