Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/markup/PhabricatorMarkupEngine.php
| Show First 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | /* -( Markup Pipeline )---------------------------------------------------- */ | ||||
| /** | /** | ||||
| * @task markup | * @task markup | ||||
| */ | */ | ||||
| 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; | |||||
| } | } | ||||
| /** | /** | ||||
| * @task markup | * @task markup | ||||
| */ | */ | ||||
| private function loadPreprocessorCaches(array $engines, array $objects) { | private function loadPreprocessorCaches(array $engines, array $objects) { | ||||
| $blocks = array(); | $blocks = array(); | ||||
| ▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | /* -( Engine Construction )------------------------------------------------ */ | ||||
| } | } | ||||
| /** | /** | ||||
| * @task engine | * @task engine | ||||
| */ | */ | ||||
| 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'), | ||||
| )); | )); | ||||
| } | } | ||||
| /** | /** | ||||
| * @task engine | * @task engine | ||||
| */ | */ | ||||
| Show All 33 Lines | /* -( Engine Construction )------------------------------------------------ */ | ||||
| /** | /** | ||||
| * @task engine | * @task engine | ||||
| */ | */ | ||||
| private static function getMarkupEngineDefaultConfiguration() { | private static function getMarkupEngineDefaultConfiguration() { | ||||
| return array( | return array( | ||||
| '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, | ||||
| 'uri.allowed-protocols' => PhabricatorEnv::getEnvConfig( | 'uri.allowed-protocols' => PhabricatorEnv::getEnvConfig( | ||||
| 'uri.allowed-protocols'), | 'uri.allowed-protocols'), | ||||
| 'syntax-highlighter.engine' => PhabricatorEnv::getEnvConfig( | 'syntax-highlighter.engine' => PhabricatorEnv::getEnvConfig( | ||||
| 'syntax-highlighter.engine'), | 'syntax-highlighter.engine'), | ||||
| 'preserve-linebreaks' => true, | 'preserve-linebreaks' => true, | ||||
| Show All 20 Lines | public static function newMarkupEngine(array $options) { | ||||
| $engine->setConfig( | $engine->setConfig( | ||||
| 'syntax-highlighter.engine', | 'syntax-highlighter.engine', | ||||
| $options['syntax-highlighter.engine']); | $options['syntax-highlighter.engine']); | ||||
| $rules = array(); | $rules = array(); | ||||
| $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(); | ||||
| if ($options['youtube']) { | if ($options['youtube']) { | ||||
| $rules[] = new PhabricatorRemarkupRuleYoutube(); | $rules[] = new PhabricatorRemarkupRuleYoutube(); | ||||
| } | } | ||||
| $applications = PhabricatorApplication::getAllInstalledApplications(); | $applications = PhabricatorApplication::getAllInstalledApplications(); | ||||
| Show All 9 Lines | if ($options['macros']) { | ||||
| $rules[] = new PhabricatorRemarkupRuleImageMacro(); | $rules[] = new PhabricatorRemarkupRuleImageMacro(); | ||||
| $rules[] = new PhabricatorRemarkupRuleMeme(); | $rules[] = new PhabricatorRemarkupRuleMeme(); | ||||
| } | } | ||||
| $rules[] = new PhutilRemarkupRuleBold(); | $rules[] = new PhutilRemarkupRuleBold(); | ||||
| $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(); | ||||
| $blocks[] = new PhutilRemarkupEngineRemarkupHeaderBlockRule(); | $blocks[] = new PhutilRemarkupEngineRemarkupHeaderBlockRule(); | ||||
| $blocks[] = new PhutilRemarkupEngineRemarkupHorizontalRuleBlockRule(); | $blocks[] = new PhutilRemarkupEngineRemarkupHorizontalRuleBlockRule(); | ||||
| $blocks[] = new PhutilRemarkupEngineRemarkupListBlockRule(); | $blocks[] = new PhutilRemarkupEngineRemarkupListBlockRule(); | ||||
| $blocks[] = new PhutilRemarkupEngineRemarkupCodeBlockRule(); | $blocks[] = new PhutilRemarkupEngineRemarkupCodeBlockRule(); | ||||
| $blocks[] = new PhutilRemarkupEngineRemarkupNoteBlockRule(); | $blocks[] = new PhutilRemarkupEngineRemarkupNoteBlockRule(); | ||||
| $blocks[] = new PhutilRemarkupEngineRemarkupTableBlockRule(); | $blocks[] = new PhutilRemarkupEngineRemarkupTableBlockRule(); | ||||
| $blocks[] = new PhutilRemarkupEngineRemarkupSimpleTableBlockRule(); | $blocks[] = new PhutilRemarkupEngineRemarkupSimpleTableBlockRule(); | ||||
| $blocks[] = new PhutilRemarkupEngineRemarkupInterpreterRule(); | $blocks[] = new PhutilRemarkupEngineRemarkupInterpreterRule(); | ||||
| $blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule(); | |||||
| $custom_block_rule_classes = $options['custom-block']; | foreach (self::loadCustomBlockRules() as $rule) { | ||||
| if ($custom_block_rule_classes) { | $blocks[] = $rule; | ||||
| foreach ($custom_block_rule_classes as $custom_block_rule_class) { | |||||
| $blocks[] = newv($custom_block_rule_class, array()); | |||||
| } | } | ||||
| } | |||||
| $blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule(); | |||||
| foreach ($blocks as $block) { | foreach ($blocks as $block) { | ||||
| $block->setMarkupRules($rules); | $block->setMarkupRules($rules); | ||||
| } | } | ||||
| $engine->setBlockRules($blocks); | $engine->setBlockRules($blocks); | ||||
| return $engine; | return $engine; | ||||
| ▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | foreach ($blocks as $block) { | ||||
| // use the first block. | // use the first block. | ||||
| $best = $block; | $best = $block; | ||||
| } | } | ||||
| } | } | ||||
| 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(); | |||||
| } | |||||
| } | } | ||||