2011-01-30 13:20:56 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DifferentialMarkupEngineFactory {
|
|
|
|
|
|
|
|
public function newDifferentialCommentMarkupEngine() {
|
|
|
|
$engine = new PhutilRemarkupEngine();
|
|
|
|
|
2011-04-10 14:07:00 -07:00
|
|
|
$engine->setConfig('preserve-linebreaks', true);
|
2011-04-30 14:00:14 -07:00
|
|
|
$engine->setConfig(
|
|
|
|
'pygments.enabled',
|
|
|
|
PhabricatorEnv::getEnvConfig('pygments.enabled'));
|
2011-04-10 14:07:00 -07:00
|
|
|
|
2011-01-30 13:20:56 -08:00
|
|
|
$rules = array();
|
|
|
|
$rules[] = new PhutilRemarkupRuleEscapeRemarkup();
|
2011-05-02 14:20:24 -07:00
|
|
|
if (PhabricatorEnv::getEnvConfig('files.enable-proxy')) {
|
|
|
|
$rules[] = new PhabricatorRemarkupRuleProxyImage();
|
|
|
|
}
|
2011-05-27 12:50:02 -07:00
|
|
|
|
|
|
|
if (PhabricatorEnv::getEnvConfig('remarkup.enable-embedded-youtube')) {
|
|
|
|
$rules[] = new PhabricatorRemarkupRuleYoutube();
|
|
|
|
}
|
|
|
|
|
2011-01-30 13:20:56 -08:00
|
|
|
$rules[] = new PhutilRemarkupRuleHyperlink();
|
2011-02-11 18:06:43 -08:00
|
|
|
|
|
|
|
$rules[] = new PhabricatorRemarkupRuleDifferential();
|
2011-04-11 03:02:19 -07:00
|
|
|
$rules[] = new PhabricatorRemarkupRuleDiffusion();
|
2011-02-11 18:06:43 -08:00
|
|
|
$rules[] = new PhabricatorRemarkupRuleManiphest();
|
2011-04-13 15:15:48 -07:00
|
|
|
$rules[] = new PhabricatorRemarkupRuleImageMacro();
|
2011-06-24 10:59:57 -07:00
|
|
|
$rules[] = new PhabricatorRemarkupRuleMention();
|
2011-02-11 18:06:43 -08:00
|
|
|
|
2011-05-26 13:13:36 -07:00
|
|
|
$custom_rule_classes =
|
|
|
|
PhabricatorEnv::getEnvConfig('differential.custom-remarkup-rules');
|
|
|
|
if ($custom_rule_classes) {
|
|
|
|
foreach ($custom_rule_classes as $custom_rule_class) {
|
|
|
|
PhutilSymbolLoader::loadClass($custom_rule_class);
|
|
|
|
$rules[] = newv($custom_rule_class, array());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-02 11:50:24 -07:00
|
|
|
$rules[] = new PhutilRemarkupRuleEscapeHTML();
|
|
|
|
$rules[] = new PhutilRemarkupRuleMonospace();
|
|
|
|
$rules[] = new PhutilRemarkupRuleBold();
|
|
|
|
$rules[] = new PhutilRemarkupRuleItalic();
|
|
|
|
|
|
|
|
|
2011-01-30 13:20:56 -08:00
|
|
|
$blocks = array();
|
2011-04-14 12:52:28 -07:00
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupQuotesBlockRule();
|
2011-01-30 13:20:56 -08:00
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupHeaderBlockRule();
|
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupListBlockRule();
|
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupCodeBlockRule();
|
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
|
|
|
|
|
2011-05-26 13:13:36 -07:00
|
|
|
$custom_block_rule_classes =
|
|
|
|
PhabricatorEnv::getEnvConfig('differential.custom-remarkup-block-rules');
|
|
|
|
if ($custom_block_rule_classes) {
|
|
|
|
foreach ($custom_block_rule_classes as $custom_block_rule_class) {
|
|
|
|
PhutilSymbolLoader::loadClass($custom_block_rule_class);
|
|
|
|
$blocks[] = newv($custom_block_rule_class, array());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-30 13:20:56 -08:00
|
|
|
foreach ($blocks as $block) {
|
|
|
|
if (!($block instanceof PhutilRemarkupEngineRemarkupCodeBlockRule)) {
|
|
|
|
$block->setMarkupRules($rules);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$engine->setBlockRules($blocks);
|
|
|
|
|
|
|
|
return $engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|