2011-01-30 22:20:56 +01: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 {
|
|
|
|
|
2011-06-24 20:50:19 +02:00
|
|
|
public static function extractPHIDsFromMentions(array $content_blocks) {
|
|
|
|
$mentions = array();
|
|
|
|
|
|
|
|
$factory = new DifferentialMarkupEngineFactory();
|
|
|
|
$engine = $factory->newDifferentialCommentMarkupEngine();
|
|
|
|
|
|
|
|
foreach ($content_blocks as $content_block) {
|
|
|
|
$engine->markupText($content_block);
|
|
|
|
$phids = $engine->getTextMetadata(
|
|
|
|
'phabricator.mentioned-user-phids',
|
|
|
|
array());
|
|
|
|
$mentions += $phids;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $mentions;
|
|
|
|
}
|
|
|
|
|
2011-01-30 22:20:56 +01:00
|
|
|
public function newDifferentialCommentMarkupEngine() {
|
|
|
|
$engine = new PhutilRemarkupEngine();
|
|
|
|
|
2011-04-10 23:07:00 +02:00
|
|
|
$engine->setConfig('preserve-linebreaks', true);
|
2011-04-30 23:00:14 +02:00
|
|
|
$engine->setConfig(
|
|
|
|
'pygments.enabled',
|
|
|
|
PhabricatorEnv::getEnvConfig('pygments.enabled'));
|
2011-04-10 23:07:00 +02:00
|
|
|
|
2011-01-30 22:20:56 +01:00
|
|
|
$rules = array();
|
|
|
|
$rules[] = new PhutilRemarkupRuleEscapeRemarkup();
|
2011-05-02 23:20:24 +02:00
|
|
|
if (PhabricatorEnv::getEnvConfig('files.enable-proxy')) {
|
|
|
|
$rules[] = new PhabricatorRemarkupRuleProxyImage();
|
|
|
|
}
|
2011-05-27 21:50:02 +02:00
|
|
|
|
|
|
|
if (PhabricatorEnv::getEnvConfig('remarkup.enable-embedded-youtube')) {
|
|
|
|
$rules[] = new PhabricatorRemarkupRuleYoutube();
|
|
|
|
}
|
|
|
|
|
2011-01-30 22:20:56 +01:00
|
|
|
$rules[] = new PhutilRemarkupRuleHyperlink();
|
2011-02-12 03:06:43 +01:00
|
|
|
|
|
|
|
$rules[] = new PhabricatorRemarkupRuleDifferential();
|
2011-04-11 12:02:19 +02:00
|
|
|
$rules[] = new PhabricatorRemarkupRuleDiffusion();
|
2011-02-12 03:06:43 +01:00
|
|
|
$rules[] = new PhabricatorRemarkupRuleManiphest();
|
2011-06-27 08:57:43 +02:00
|
|
|
$rules[] = new PhabricatorRemarkupRulePaste();
|
2011-04-14 00:15:48 +02:00
|
|
|
$rules[] = new PhabricatorRemarkupRuleImageMacro();
|
2011-06-24 19:59:57 +02:00
|
|
|
$rules[] = new PhabricatorRemarkupRuleMention();
|
2011-02-12 03:06:43 +01:00
|
|
|
|
2011-05-26 22:13:36 +02: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 20:50:24 +02:00
|
|
|
$rules[] = new PhutilRemarkupRuleEscapeHTML();
|
|
|
|
$rules[] = new PhutilRemarkupRuleMonospace();
|
|
|
|
$rules[] = new PhutilRemarkupRuleBold();
|
|
|
|
$rules[] = new PhutilRemarkupRuleItalic();
|
|
|
|
|
|
|
|
|
2011-01-30 22:20:56 +01:00
|
|
|
$blocks = array();
|
2011-04-14 21:52:28 +02:00
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupQuotesBlockRule();
|
2011-01-30 22:20:56 +01:00
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupHeaderBlockRule();
|
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupListBlockRule();
|
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupCodeBlockRule();
|
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
|
|
|
|
|
2011-05-26 22:13:36 +02: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 22:20:56 +01:00
|
|
|
foreach ($blocks as $block) {
|
|
|
|
if (!($block instanceof PhutilRemarkupEngineRemarkupCodeBlockRule)) {
|
|
|
|
$block->setMarkupRules($rules);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$engine->setBlockRules($blocks);
|
|
|
|
|
|
|
|
return $engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|