mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 16:22:43 +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:
parent
87a440888d
commit
9e87172166
7 changed files with 61 additions and 48 deletions
|
@ -827,14 +827,6 @@ return array(
|
||||||
|
|
||||||
'differential.revision-custom-detail-renderer' => null,
|
'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
|
// List of file regexps where whitespace is meaningful and should not
|
||||||
// use 'ignore-all' by default
|
// use 'ignore-all' by default
|
||||||
'differential.whitespace-matters' => array(
|
'differential.whitespace-matters' => array(
|
||||||
|
|
|
@ -1592,6 +1592,8 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorRemarkupBlockInterpreterFiglet' => 'infrastructure/markup/interpreter/PhabricatorRemarkupBlockInterpreterFiglet.php',
|
'PhabricatorRemarkupBlockInterpreterFiglet' => 'infrastructure/markup/interpreter/PhabricatorRemarkupBlockInterpreterFiglet.php',
|
||||||
'PhabricatorRemarkupBlockInterpreterGraphviz' => 'infrastructure/markup/interpreter/PhabricatorRemarkupBlockInterpreterGraphviz.php',
|
'PhabricatorRemarkupBlockInterpreterGraphviz' => 'infrastructure/markup/interpreter/PhabricatorRemarkupBlockInterpreterGraphviz.php',
|
||||||
'PhabricatorRemarkupControl' => 'view/form/control/PhabricatorRemarkupControl.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',
|
'PhabricatorRemarkupRuleEmbedFile' => 'applications/files/remarkup/PhabricatorRemarkupRuleEmbedFile.php',
|
||||||
'PhabricatorRemarkupRuleImageMacro' => 'applications/macro/remarkup/PhabricatorRemarkupRuleImageMacro.php',
|
'PhabricatorRemarkupRuleImageMacro' => 'applications/macro/remarkup/PhabricatorRemarkupRuleImageMacro.php',
|
||||||
'PhabricatorRemarkupRuleMeme' => 'applications/macro/remarkup/PhabricatorRemarkupRuleMeme.php',
|
'PhabricatorRemarkupRuleMeme' => 'applications/macro/remarkup/PhabricatorRemarkupRuleMeme.php',
|
||||||
|
@ -3886,6 +3888,8 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorRemarkupBlockInterpreterFiglet' => 'PhutilRemarkupBlockInterpreter',
|
'PhabricatorRemarkupBlockInterpreterFiglet' => 'PhutilRemarkupBlockInterpreter',
|
||||||
'PhabricatorRemarkupBlockInterpreterGraphviz' => 'PhutilRemarkupBlockInterpreter',
|
'PhabricatorRemarkupBlockInterpreterGraphviz' => 'PhutilRemarkupBlockInterpreter',
|
||||||
'PhabricatorRemarkupControl' => 'AphrontFormTextAreaControl',
|
'PhabricatorRemarkupControl' => 'AphrontFormTextAreaControl',
|
||||||
|
'PhabricatorRemarkupCustomBlockRule' => 'PhutilRemarkupEngineBlockRule',
|
||||||
|
'PhabricatorRemarkupCustomInlineRule' => 'PhutilRemarkupRule',
|
||||||
'PhabricatorRemarkupRuleEmbedFile' => 'PhabricatorRemarkupRuleObject',
|
'PhabricatorRemarkupRuleEmbedFile' => 'PhabricatorRemarkupRuleObject',
|
||||||
'PhabricatorRemarkupRuleImageMacro' => 'PhutilRemarkupRule',
|
'PhabricatorRemarkupRuleImageMacro' => 'PhutilRemarkupRule',
|
||||||
'PhabricatorRemarkupRuleMeme' => 'PhutilRemarkupRule',
|
'PhabricatorRemarkupRuleMeme' => 'PhutilRemarkupRule',
|
||||||
|
|
|
@ -141,6 +141,11 @@ final class PhabricatorSetupCheckExtraConfig extends PhabricatorSetupCheck {
|
||||||
|
|
||||||
$ancient_config = array_fill_keys($auth_config, $reason_auth);
|
$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(
|
$ancient_config += array(
|
||||||
'phid.external-loaders' =>
|
'phid.external-loaders' =>
|
||||||
pht(
|
pht(
|
||||||
|
@ -155,6 +160,8 @@ final class PhabricatorSetupCheckExtraConfig extends PhabricatorSetupCheck {
|
||||||
'Maniphest fields are now defined in '.
|
'Maniphest fields are now defined in '.
|
||||||
'`maniphest.custom-field-definitions`. Existing definitions have '.
|
'`maniphest.custom-field-definitions`. Existing definitions have '.
|
||||||
'been migrated.'),
|
'been migrated.'),
|
||||||
|
'differential.custom-remarkup-rules' => $markup_reason,
|
||||||
|
'differential.custom-remarkup-block-rules' => $markup_reason,
|
||||||
);
|
);
|
||||||
|
|
||||||
return $ancient_config;
|
return $ancient_config;
|
||||||
|
|
|
@ -19,25 +19,6 @@ final class PhabricatorDifferentialConfigOptions
|
||||||
null)
|
null)
|
||||||
->setBaseClass('DifferentialRevisionDetailRenderer')
|
->setBaseClass('DifferentialRevisionDetailRenderer')
|
||||||
->setDescription(pht("Custom revision detail renderer.")),
|
->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(
|
$this->newOption(
|
||||||
'differential.whitespace-matters',
|
'differential.whitespace-matters',
|
||||||
'list<regex>',
|
'list<regex>',
|
||||||
|
|
|
@ -201,7 +201,16 @@ final class PhabricatorMarkupEngine {
|
||||||
private function getMarkupFieldKey(
|
private function getMarkupFieldKey(
|
||||||
PhabricatorMarkupInterface $object,
|
PhabricatorMarkupInterface $object,
|
||||||
$field) {
|
$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()) {
|
public static function newDifferentialMarkupEngine(array $options = array()) {
|
||||||
return self::newMarkupEngine(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'),
|
'differential.diff' => idx($options, 'differential.diff'),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -381,8 +386,6 @@ final class PhabricatorMarkupEngine {
|
||||||
'pygments' => PhabricatorEnv::getEnvConfig('pygments.enabled'),
|
'pygments' => PhabricatorEnv::getEnvConfig('pygments.enabled'),
|
||||||
'youtube' => PhabricatorEnv::getEnvConfig(
|
'youtube' => PhabricatorEnv::getEnvConfig(
|
||||||
'remarkup.enable-embedded-youtube'),
|
'remarkup.enable-embedded-youtube'),
|
||||||
'custom-inline' => array(),
|
|
||||||
'custom-block' => array(),
|
|
||||||
'differential.diff' => null,
|
'differential.diff' => null,
|
||||||
'header.generate-toc' => false,
|
'header.generate-toc' => false,
|
||||||
'macros' => true,
|
'macros' => true,
|
||||||
|
@ -419,12 +422,6 @@ final class PhabricatorMarkupEngine {
|
||||||
$rules[] = new PhutilRemarkupRuleEscapeRemarkup();
|
$rules[] = new PhutilRemarkupRuleEscapeRemarkup();
|
||||||
$rules[] = new PhutilRemarkupRuleMonospace();
|
$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();
|
$rules[] = new PhutilRemarkupRuleDocumentLink();
|
||||||
|
|
||||||
|
@ -450,6 +447,10 @@ final class PhabricatorMarkupEngine {
|
||||||
$rules[] = new PhutilRemarkupRuleItalic();
|
$rules[] = new PhutilRemarkupRuleItalic();
|
||||||
$rules[] = new PhutilRemarkupRuleDel();
|
$rules[] = new PhutilRemarkupRuleDel();
|
||||||
|
|
||||||
|
foreach (self::loadCustomInlineRules() as $rule) {
|
||||||
|
$rules[] = $rule;
|
||||||
|
}
|
||||||
|
|
||||||
$blocks = array();
|
$blocks = array();
|
||||||
$blocks[] = new PhutilRemarkupEngineRemarkupQuotesBlockRule();
|
$blocks[] = new PhutilRemarkupEngineRemarkupQuotesBlockRule();
|
||||||
$blocks[] = new PhutilRemarkupEngineRemarkupLiteralBlockRule();
|
$blocks[] = new PhutilRemarkupEngineRemarkupLiteralBlockRule();
|
||||||
|
@ -461,16 +462,12 @@ final class PhabricatorMarkupEngine {
|
||||||
$blocks[] = new PhutilRemarkupEngineRemarkupTableBlockRule();
|
$blocks[] = new PhutilRemarkupEngineRemarkupTableBlockRule();
|
||||||
$blocks[] = new PhutilRemarkupEngineRemarkupSimpleTableBlockRule();
|
$blocks[] = new PhutilRemarkupEngineRemarkupSimpleTableBlockRule();
|
||||||
$blocks[] = new PhutilRemarkupEngineRemarkupInterpreterRule();
|
$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();
|
$blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
|
||||||
|
|
||||||
|
foreach (self::loadCustomBlockRules() as $rule) {
|
||||||
|
$blocks[] = $rule;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($blocks as $block) {
|
foreach ($blocks as $block) {
|
||||||
$block->setMarkupRules($rules);
|
$block->setMarkupRules($rules);
|
||||||
}
|
}
|
||||||
|
@ -564,4 +561,16 @@ final class PhabricatorMarkupEngine {
|
||||||
return $best;
|
return $best;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function loadCustomInlineRules() {
|
||||||
|
return id(new PhutilSymbolLoader())
|
||||||
|
->setAncestorClass('PhabricatorRemarkupCustomInlineRule')
|
||||||
|
->loadObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function loadCustomBlockRules() {
|
||||||
|
return id(new PhutilSymbolLoader())
|
||||||
|
->setAncestorClass('PhabricatorRemarkupCustomBlockRule')
|
||||||
|
->loadObjects();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class PhabricatorRemarkupCustomBlockRule
|
||||||
|
extends PhutilRemarkupEngineBlockRule {
|
||||||
|
|
||||||
|
public function getRuleVersion() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class PhabricatorRemarkupCustomInlineRule
|
||||||
|
extends PhutilRemarkupRule {
|
||||||
|
|
||||||
|
public function getRuleVersion() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue