1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

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
This commit is contained in:
epriestley 2013-10-24 17:26:07 -07:00
parent 87a440888d
commit 9e87172166
7 changed files with 61 additions and 48 deletions

View file

@ -827,14 +827,6 @@ return array(
'differential.revision-custom-detail-renderer' => null,
// Array for custom remarkup rules. The array should have a list of
// class names of classes that extend PhutilRemarkupRule
'differential.custom-remarkup-rules' => null,
// Array for custom remarkup block rules. The array should have a list of
// class names of classes that extend PhutilRemarkupEngineBlockRule
'differential.custom-remarkup-block-rules' => null,
// List of file regexps where whitespace is meaningful and should not
// use 'ignore-all' by default
'differential.whitespace-matters' => array(

View file

@ -1592,6 +1592,8 @@ phutil_register_library_map(array(
'PhabricatorRemarkupBlockInterpreterFiglet' => 'infrastructure/markup/interpreter/PhabricatorRemarkupBlockInterpreterFiglet.php',
'PhabricatorRemarkupBlockInterpreterGraphviz' => 'infrastructure/markup/interpreter/PhabricatorRemarkupBlockInterpreterGraphviz.php',
'PhabricatorRemarkupControl' => 'view/form/control/PhabricatorRemarkupControl.php',
'PhabricatorRemarkupCustomBlockRule' => 'infrastructure/markup/rule/PhabricatorRemarkupCustomBlockRule.php',
'PhabricatorRemarkupCustomInlineRule' => 'infrastructure/markup/rule/PhabricatorRemarkupCustomInlineRule.php',
'PhabricatorRemarkupRuleEmbedFile' => 'applications/files/remarkup/PhabricatorRemarkupRuleEmbedFile.php',
'PhabricatorRemarkupRuleImageMacro' => 'applications/macro/remarkup/PhabricatorRemarkupRuleImageMacro.php',
'PhabricatorRemarkupRuleMeme' => 'applications/macro/remarkup/PhabricatorRemarkupRuleMeme.php',
@ -3886,6 +3888,8 @@ phutil_register_library_map(array(
'PhabricatorRemarkupBlockInterpreterFiglet' => 'PhutilRemarkupBlockInterpreter',
'PhabricatorRemarkupBlockInterpreterGraphviz' => 'PhutilRemarkupBlockInterpreter',
'PhabricatorRemarkupControl' => 'AphrontFormTextAreaControl',
'PhabricatorRemarkupCustomBlockRule' => 'PhutilRemarkupEngineBlockRule',
'PhabricatorRemarkupCustomInlineRule' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleEmbedFile' => 'PhabricatorRemarkupRuleObject',
'PhabricatorRemarkupRuleImageMacro' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleMeme' => 'PhutilRemarkupRule',

View file

@ -141,6 +141,11 @@ final class PhabricatorSetupCheckExtraConfig extends PhabricatorSetupCheck {
$ancient_config = array_fill_keys($auth_config, $reason_auth);
$markup_reason = pht(
'Custom remarkup rules are now added by subclassing '.
'PhabricatorRemarkupCustomInlineRule or '.
'PhabricatorRemarkupCustomBlockRule.');
$ancient_config += array(
'phid.external-loaders' =>
pht(
@ -155,6 +160,8 @@ final class PhabricatorSetupCheckExtraConfig extends PhabricatorSetupCheck {
'Maniphest fields are now defined in '.
'`maniphest.custom-field-definitions`. Existing definitions have '.
'been migrated.'),
'differential.custom-remarkup-rules' => $markup_reason,
'differential.custom-remarkup-block-rules' => $markup_reason,
);
return $ancient_config;

View file

@ -19,25 +19,6 @@ final class PhabricatorDifferentialConfigOptions
null)
->setBaseClass('DifferentialRevisionDetailRenderer')
->setDescription(pht("Custom revision detail renderer.")),
$this->newOption(
'differential.custom-remarkup-rules',
'list<string>',
array())
->setSummary(pht('Custom remarkup rules.'))
->setDescription(
pht(
"Array for custom remarkup rules. The array should have a list ".
"of class names of classes that extend PhutilRemarkupRule")),
$this->newOption(
'differential.custom-remarkup-block-rules',
'list<string>',
array())
->setSummary(pht('Custom remarkup block rules.'))
->setDescription(
pht(
"Array for custom remarkup block rules. The array should have a ".
"list of class names of classes that extend ".
"PhutilRemarkupEngineBlockRule")),
$this->newOption(
'differential.whitespace-matters',
'list<regex>',

View file

@ -201,7 +201,16 @@ final class PhabricatorMarkupEngine {
private function getMarkupFieldKey(
PhabricatorMarkupInterface $object,
$field) {
return $object->getMarkupFieldKey($field).'@'.$this->version;
$custom = array_merge(
self::loadCustomInlineRules(),
self::loadCustomBlockRules());
$custom = mpull($custom, 'getRuleVersion', null);
ksort($custom);
$custom = PhabricatorHash::digestForIndex(serialize($custom));
return $object->getMarkupFieldKey($field).'@'.$this->version.'@'.$custom;
}
@ -328,10 +337,6 @@ final class PhabricatorMarkupEngine {
*/
public static function newDifferentialMarkupEngine(array $options = array()) {
return self::newMarkupEngine(array(
'custom-inline' => PhabricatorEnv::getEnvConfig(
'differential.custom-remarkup-rules'),
'custom-block' => PhabricatorEnv::getEnvConfig(
'differential.custom-remarkup-block-rules'),
'differential.diff' => idx($options, 'differential.diff'),
));
}
@ -381,8 +386,6 @@ final class PhabricatorMarkupEngine {
'pygments' => PhabricatorEnv::getEnvConfig('pygments.enabled'),
'youtube' => PhabricatorEnv::getEnvConfig(
'remarkup.enable-embedded-youtube'),
'custom-inline' => array(),
'custom-block' => array(),
'differential.diff' => null,
'header.generate-toc' => false,
'macros' => true,
@ -419,12 +422,6 @@ final class PhabricatorMarkupEngine {
$rules[] = new PhutilRemarkupRuleEscapeRemarkup();
$rules[] = new PhutilRemarkupRuleMonospace();
$custom_rule_classes = $options['custom-inline'];
if ($custom_rule_classes) {
foreach ($custom_rule_classes as $custom_rule_class) {
$rules[] = newv($custom_rule_class, array());
}
}
$rules[] = new PhutilRemarkupRuleDocumentLink();
@ -450,6 +447,10 @@ final class PhabricatorMarkupEngine {
$rules[] = new PhutilRemarkupRuleItalic();
$rules[] = new PhutilRemarkupRuleDel();
foreach (self::loadCustomInlineRules() as $rule) {
$rules[] = $rule;
}
$blocks = array();
$blocks[] = new PhutilRemarkupEngineRemarkupQuotesBlockRule();
$blocks[] = new PhutilRemarkupEngineRemarkupLiteralBlockRule();
@ -461,16 +462,12 @@ final class PhabricatorMarkupEngine {
$blocks[] = new PhutilRemarkupEngineRemarkupTableBlockRule();
$blocks[] = new PhutilRemarkupEngineRemarkupSimpleTableBlockRule();
$blocks[] = new PhutilRemarkupEngineRemarkupInterpreterRule();
$custom_block_rule_classes = $options['custom-block'];
if ($custom_block_rule_classes) {
foreach ($custom_block_rule_classes as $custom_block_rule_class) {
$blocks[] = newv($custom_block_rule_class, array());
}
}
$blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
foreach (self::loadCustomBlockRules() as $rule) {
$blocks[] = $rule;
}
foreach ($blocks as $block) {
$block->setMarkupRules($rules);
}
@ -564,4 +561,16 @@ final class PhabricatorMarkupEngine {
return $best;
}
private static function loadCustomInlineRules() {
return id(new PhutilSymbolLoader())
->setAncestorClass('PhabricatorRemarkupCustomInlineRule')
->loadObjects();
}
private static function loadCustomBlockRules() {
return id(new PhutilSymbolLoader())
->setAncestorClass('PhabricatorRemarkupCustomBlockRule')
->loadObjects();
}
}

View file

@ -0,0 +1,10 @@
<?php
abstract class PhabricatorRemarkupCustomBlockRule
extends PhutilRemarkupEngineBlockRule {
public function getRuleVersion() {
return 1;
}
}

View file

@ -0,0 +1,10 @@
<?php
abstract class PhabricatorRemarkupCustomInlineRule
extends PhutilRemarkupRule {
public function getRuleVersion() {
return 1;
}
}