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.
|
|
|
|
*/
|
|
|
|
|
Generalize the markup engine factory
Summary:
This thing services every app but it lives inside Differential right now. Pull
it out, and separate the factory interfaces per-application.
This will let us accommodate changes we need to make for Phriction to support
wiki linking.
Test Plan: Tested remarkup in differential, diffusion, maniphest, people,
slowvote.
Reviewed By: hsb
Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran
CC: aran, hsb
Differential Revision: 646
2011-07-12 00:58:32 +02:00
|
|
|
class PhabricatorMarkupEngine {
|
2011-01-30 22:20:56 +01:00
|
|
|
|
2011-06-24 20:50:19 +02:00
|
|
|
public static function extractPHIDsFromMentions(array $content_blocks) {
|
|
|
|
$mentions = array();
|
|
|
|
|
Generalize the markup engine factory
Summary:
This thing services every app but it lives inside Differential right now. Pull
it out, and separate the factory interfaces per-application.
This will let us accommodate changes we need to make for Phriction to support
wiki linking.
Test Plan: Tested remarkup in differential, diffusion, maniphest, people,
slowvote.
Reviewed By: hsb
Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran
CC: aran, hsb
Differential Revision: 646
2011-07-12 00:58:32 +02:00
|
|
|
$engine = self::newDifferentialMarkupEngine();
|
2011-06-24 20:50:19 +02:00
|
|
|
|
|
|
|
foreach ($content_blocks as $content_block) {
|
|
|
|
$engine->markupText($content_block);
|
|
|
|
$phids = $engine->getTextMetadata(
|
|
|
|
'phabricator.mentioned-user-phids',
|
|
|
|
array());
|
|
|
|
$mentions += $phids;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $mentions;
|
|
|
|
}
|
|
|
|
|
Generalize the markup engine factory
Summary:
This thing services every app but it lives inside Differential right now. Pull
it out, and separate the factory interfaces per-application.
This will let us accommodate changes we need to make for Phriction to support
wiki linking.
Test Plan: Tested remarkup in differential, diffusion, maniphest, people,
slowvote.
Reviewed By: hsb
Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran
CC: aran, hsb
Differential Revision: 646
2011-07-12 00:58:32 +02:00
|
|
|
public static function newManiphestMarkupEngine() {
|
|
|
|
return self::newMarkupEngine(array(
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function newPhrictionMarkupEngine() {
|
|
|
|
return self::newMarkupEngine(array(
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function newDifferentialMarkupEngine() {
|
|
|
|
return self::newMarkupEngine(array(
|
|
|
|
'custom-inline' => PhabricatorEnv::getEnvConfig(
|
|
|
|
'differential.custom-remarkup-rules'),
|
|
|
|
'custom-block' => PhabricatorEnv::getEnvConfig(
|
|
|
|
'differential.custom-remarkup-block-rules'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function newProfileMarkupEngine() {
|
|
|
|
return self::newMarkupEngine(array(
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function newSlowvoteMarkupEngine() {
|
|
|
|
return self::newMarkupEngine(array(
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function getMarkupEngineDefaultConfiguration() {
|
|
|
|
return array(
|
|
|
|
'pygments' => PhabricatorEnv::getEnvConfig('pygments.enabled'),
|
|
|
|
'fileproxy' => PhabricatorEnv::getEnvConfig('files.enable-proxy'),
|
|
|
|
'youtube' => PhabricatorEnv::getEnvConfig(
|
|
|
|
'remarkup.enable-embedded-youtube'),
|
|
|
|
'custom-inline' => array(),
|
|
|
|
'custom-block' => array(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function newMarkupEngine(array $options) {
|
|
|
|
|
|
|
|
$options += self::getMarkupEngineDefaultConfiguration();
|
|
|
|
|
2011-01-30 22:20:56 +01:00
|
|
|
$engine = new PhutilRemarkupEngine();
|
|
|
|
|
2011-04-10 23:07:00 +02:00
|
|
|
$engine->setConfig('preserve-linebreaks', true);
|
Generalize the markup engine factory
Summary:
This thing services every app but it lives inside Differential right now. Pull
it out, and separate the factory interfaces per-application.
This will let us accommodate changes we need to make for Phriction to support
wiki linking.
Test Plan: Tested remarkup in differential, diffusion, maniphest, people,
slowvote.
Reviewed By: hsb
Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran
CC: aran, hsb
Differential Revision: 646
2011-07-12 00:58:32 +02:00
|
|
|
$engine->setConfig('pygments.enabled', $options['pygments']);
|
2011-04-10 23:07:00 +02:00
|
|
|
|
2011-01-30 22:20:56 +01:00
|
|
|
$rules = array();
|
|
|
|
$rules[] = new PhutilRemarkupRuleEscapeRemarkup();
|
Generalize the markup engine factory
Summary:
This thing services every app but it lives inside Differential right now. Pull
it out, and separate the factory interfaces per-application.
This will let us accommodate changes we need to make for Phriction to support
wiki linking.
Test Plan: Tested remarkup in differential, diffusion, maniphest, people,
slowvote.
Reviewed By: hsb
Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran
CC: aran, hsb
Differential Revision: 646
2011-07-12 00:58:32 +02:00
|
|
|
if ($options['fileproxy']) {
|
2011-05-02 23:20:24 +02:00
|
|
|
$rules[] = new PhabricatorRemarkupRuleProxyImage();
|
|
|
|
}
|
2011-05-27 21:50:02 +02:00
|
|
|
|
Generalize the markup engine factory
Summary:
This thing services every app but it lives inside Differential right now. Pull
it out, and separate the factory interfaces per-application.
This will let us accommodate changes we need to make for Phriction to support
wiki linking.
Test Plan: Tested remarkup in differential, diffusion, maniphest, people,
slowvote.
Reviewed By: hsb
Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran
CC: aran, hsb
Differential Revision: 646
2011-07-12 00:58:32 +02:00
|
|
|
if ($options['youtube']) {
|
2011-05-27 21:50:02 +02:00
|
|
|
$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
|
|
|
|
Generalize the markup engine factory
Summary:
This thing services every app but it lives inside Differential right now. Pull
it out, and separate the factory interfaces per-application.
This will let us accommodate changes we need to make for Phriction to support
wiki linking.
Test Plan: Tested remarkup in differential, diffusion, maniphest, people,
slowvote.
Reviewed By: hsb
Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran
CC: aran, hsb
Differential Revision: 646
2011-07-12 00:58:32 +02:00
|
|
|
$custom_rule_classes = $options['custom-inline'];
|
2011-05-26 22:13:36 +02:00
|
|
|
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();
|
|
|
|
|
Generalize the markup engine factory
Summary:
This thing services every app but it lives inside Differential right now. Pull
it out, and separate the factory interfaces per-application.
This will let us accommodate changes we need to make for Phriction to support
wiki linking.
Test Plan: Tested remarkup in differential, diffusion, maniphest, people,
slowvote.
Reviewed By: hsb
Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran
CC: aran, hsb
Differential Revision: 646
2011-07-12 00:58:32 +02:00
|
|
|
$custom_block_rule_classes = $options['custom-block'];
|
2011-05-26 22:13:36 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|