Skip to content

Commit 9e87172

Browse files
author
epriestley
committedOct 25, 2013
Make remarkup rules runtime-pluggable in a reasonable way
Summary: Gets rid of some old Differential-specific nonsense and replaces it with general runtime-pluggable Remarkup rules. Facebook: This removes two options which may be in use. Have any classes being added via config here just subclass the new abstract bases instead. This should take 5 seconds to fix. You can adjust order by overriding `getPriority()` on the rules, if necessary. Test Plan: See comments. Reviewers: btrahan Reviewed By: btrahan CC: FacebookPOC, andrewjcg, aran Differential Revision: https://secure.phabricator.com/D7393
1 parent 87a4408 commit 9e87172

7 files changed

+60
-47
lines changed
 

‎conf/default.conf.php

-8
Original file line numberDiff line numberDiff line change
@@ -827,14 +827,6 @@
827827

828828
'differential.revision-custom-detail-renderer' => null,
829829

830-
// Array for custom remarkup rules. The array should have a list of
831-
// class names of classes that extend PhutilRemarkupRule
832-
'differential.custom-remarkup-rules' => null,
833-
834-
// Array for custom remarkup block rules. The array should have a list of
835-
// class names of classes that extend PhutilRemarkupEngineBlockRule
836-
'differential.custom-remarkup-block-rules' => null,
837-
838830
// List of file regexps where whitespace is meaningful and should not
839831
// use 'ignore-all' by default
840832
'differential.whitespace-matters' => array(

‎src/__phutil_library_map__.php

+4
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,8 @@
15921592
'PhabricatorRemarkupBlockInterpreterFiglet' => 'infrastructure/markup/interpreter/PhabricatorRemarkupBlockInterpreterFiglet.php',
15931593
'PhabricatorRemarkupBlockInterpreterGraphviz' => 'infrastructure/markup/interpreter/PhabricatorRemarkupBlockInterpreterGraphviz.php',
15941594
'PhabricatorRemarkupControl' => 'view/form/control/PhabricatorRemarkupControl.php',
1595+
'PhabricatorRemarkupCustomBlockRule' => 'infrastructure/markup/rule/PhabricatorRemarkupCustomBlockRule.php',
1596+
'PhabricatorRemarkupCustomInlineRule' => 'infrastructure/markup/rule/PhabricatorRemarkupCustomInlineRule.php',
15951597
'PhabricatorRemarkupRuleEmbedFile' => 'applications/files/remarkup/PhabricatorRemarkupRuleEmbedFile.php',
15961598
'PhabricatorRemarkupRuleImageMacro' => 'applications/macro/remarkup/PhabricatorRemarkupRuleImageMacro.php',
15971599
'PhabricatorRemarkupRuleMeme' => 'applications/macro/remarkup/PhabricatorRemarkupRuleMeme.php',
@@ -3886,6 +3888,8 @@
38863888
'PhabricatorRemarkupBlockInterpreterFiglet' => 'PhutilRemarkupBlockInterpreter',
38873889
'PhabricatorRemarkupBlockInterpreterGraphviz' => 'PhutilRemarkupBlockInterpreter',
38883890
'PhabricatorRemarkupControl' => 'AphrontFormTextAreaControl',
3891+
'PhabricatorRemarkupCustomBlockRule' => 'PhutilRemarkupEngineBlockRule',
3892+
'PhabricatorRemarkupCustomInlineRule' => 'PhutilRemarkupRule',
38893893
'PhabricatorRemarkupRuleEmbedFile' => 'PhabricatorRemarkupRuleObject',
38903894
'PhabricatorRemarkupRuleImageMacro' => 'PhutilRemarkupRule',
38913895
'PhabricatorRemarkupRuleMeme' => 'PhutilRemarkupRule',

‎src/applications/config/check/PhabricatorSetupCheckExtraConfig.php

+7
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ public static function getAncientConfig() {
141141

142142
$ancient_config = array_fill_keys($auth_config, $reason_auth);
143143

144+
$markup_reason = pht(
145+
'Custom remarkup rules are now added by subclassing '.
146+
'PhabricatorRemarkupCustomInlineRule or '.
147+
'PhabricatorRemarkupCustomBlockRule.');
148+
144149
$ancient_config += array(
145150
'phid.external-loaders' =>
146151
pht(
@@ -155,6 +160,8 @@ public static function getAncientConfig() {
155160
'Maniphest fields are now defined in '.
156161
'`maniphest.custom-field-definitions`. Existing definitions have '.
157162
'been migrated.'),
163+
'differential.custom-remarkup-rules' => $markup_reason,
164+
'differential.custom-remarkup-block-rules' => $markup_reason,
158165
);
159166

160167
return $ancient_config;

‎src/applications/differential/config/PhabricatorDifferentialConfigOptions.php

-19
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,6 @@ public function getOptions() {
1919
null)
2020
->setBaseClass('DifferentialRevisionDetailRenderer')
2121
->setDescription(pht("Custom revision detail renderer.")),
22-
$this->newOption(
23-
'differential.custom-remarkup-rules',
24-
'list<string>',
25-
array())
26-
->setSummary(pht('Custom remarkup rules.'))
27-
->setDescription(
28-
pht(
29-
"Array for custom remarkup rules. The array should have a list ".
30-
"of class names of classes that extend PhutilRemarkupRule")),
31-
$this->newOption(
32-
'differential.custom-remarkup-block-rules',
33-
'list<string>',
34-
array())
35-
->setSummary(pht('Custom remarkup block rules.'))
36-
->setDescription(
37-
pht(
38-
"Array for custom remarkup block rules. The array should have a ".
39-
"list of class names of classes that extend ".
40-
"PhutilRemarkupEngineBlockRule")),
4122
$this->newOption(
4223
'differential.whitespace-matters',
4324
'list<regex>',

‎src/infrastructure/markup/PhabricatorMarkupEngine.php

+29-20
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,16 @@ private function requireKeyProcessed($key) {
201201
private function getMarkupFieldKey(
202202
PhabricatorMarkupInterface $object,
203203
$field) {
204-
return $object->getMarkupFieldKey($field).'@'.$this->version;
204+
205+
$custom = array_merge(
206+
self::loadCustomInlineRules(),
207+
self::loadCustomBlockRules());
208+
209+
$custom = mpull($custom, 'getRuleVersion', null);
210+
ksort($custom);
211+
$custom = PhabricatorHash::digestForIndex(serialize($custom));
212+
213+
return $object->getMarkupFieldKey($field).'@'.$this->version.'@'.$custom;
205214
}
206215

207216

@@ -328,10 +337,6 @@ public static function newFeedMarkupEngine() {
328337
*/
329338
public static function newDifferentialMarkupEngine(array $options = array()) {
330339
return self::newMarkupEngine(array(
331-
'custom-inline' => PhabricatorEnv::getEnvConfig(
332-
'differential.custom-remarkup-rules'),
333-
'custom-block' => PhabricatorEnv::getEnvConfig(
334-
'differential.custom-remarkup-block-rules'),
335340
'differential.diff' => idx($options, 'differential.diff'),
336341
));
337342
}
@@ -381,8 +386,6 @@ private static function getMarkupEngineDefaultConfiguration() {
381386
'pygments' => PhabricatorEnv::getEnvConfig('pygments.enabled'),
382387
'youtube' => PhabricatorEnv::getEnvConfig(
383388
'remarkup.enable-embedded-youtube'),
384-
'custom-inline' => array(),
385-
'custom-block' => array(),
386389
'differential.diff' => null,
387390
'header.generate-toc' => false,
388391
'macros' => true,
@@ -419,12 +422,6 @@ public static function newMarkupEngine(array $options) {
419422
$rules[] = new PhutilRemarkupRuleEscapeRemarkup();
420423
$rules[] = new PhutilRemarkupRuleMonospace();
421424

422-
$custom_rule_classes = $options['custom-inline'];
423-
if ($custom_rule_classes) {
424-
foreach ($custom_rule_classes as $custom_rule_class) {
425-
$rules[] = newv($custom_rule_class, array());
426-
}
427-
}
428425

429426
$rules[] = new PhutilRemarkupRuleDocumentLink();
430427

@@ -450,6 +447,10 @@ public static function newMarkupEngine(array $options) {
450447
$rules[] = new PhutilRemarkupRuleItalic();
451448
$rules[] = new PhutilRemarkupRuleDel();
452449

450+
foreach (self::loadCustomInlineRules() as $rule) {
451+
$rules[] = $rule;
452+
}
453+
453454
$blocks = array();
454455
$blocks[] = new PhutilRemarkupEngineRemarkupQuotesBlockRule();
455456
$blocks[] = new PhutilRemarkupEngineRemarkupLiteralBlockRule();
@@ -461,16 +462,12 @@ public static function newMarkupEngine(array $options) {
461462
$blocks[] = new PhutilRemarkupEngineRemarkupTableBlockRule();
462463
$blocks[] = new PhutilRemarkupEngineRemarkupSimpleTableBlockRule();
463464
$blocks[] = new PhutilRemarkupEngineRemarkupInterpreterRule();
465+
$blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
464466

465-
$custom_block_rule_classes = $options['custom-block'];
466-
if ($custom_block_rule_classes) {
467-
foreach ($custom_block_rule_classes as $custom_block_rule_class) {
468-
$blocks[] = newv($custom_block_rule_class, array());
469-
}
467+
foreach (self::loadCustomBlockRules() as $rule) {
468+
$blocks[] = $rule;
470469
}
471470

472-
$blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
473-
474471
foreach ($blocks as $block) {
475472
$block->setMarkupRules($rules);
476473
}
@@ -564,4 +561,16 @@ public static function summarize($corpus) {
564561
return $best;
565562
}
566563

564+
private static function loadCustomInlineRules() {
565+
return id(new PhutilSymbolLoader())
566+
->setAncestorClass('PhabricatorRemarkupCustomInlineRule')
567+
->loadObjects();
568+
}
569+
570+
private static function loadCustomBlockRules() {
571+
return id(new PhutilSymbolLoader())
572+
->setAncestorClass('PhabricatorRemarkupCustomBlockRule')
573+
->loadObjects();
574+
}
575+
567576
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
abstract class PhabricatorRemarkupCustomBlockRule
4+
extends PhutilRemarkupEngineBlockRule {
5+
6+
public function getRuleVersion() {
7+
return 1;
8+
}
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
abstract class PhabricatorRemarkupCustomInlineRule
4+
extends PhutilRemarkupRule {
5+
6+
public function getRuleVersion() {
7+
return 1;
8+
}
9+
10+
}

0 commit comments

Comments
 (0)
Failed to load comments.