2011-01-30 22:20:56 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-04 01:17:40 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-01-30 22:20:56 +01:00
|
|
|
*
|
|
|
|
* 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(
|
2011-07-27 21:41:21 +02:00
|
|
|
PhabricatorRemarkupRuleMention::KEY_MENTIONED,
|
2011-06-24 20:50:19 +02:00
|
|
|
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(
|
2011-07-17 03:25:45 +02:00
|
|
|
// Disable image macros on the wiki since they're less useful, we don't
|
|
|
|
// cache documents, and the module is prohibitively expensive for large
|
|
|
|
// documents.
|
|
|
|
'macros' => false,
|
2012-01-06 18:08:59 +01:00
|
|
|
'header.generate-toc' => 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
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-10-20 18:41:38 +02:00
|
|
|
public static function newDifferentialMarkupEngine(array $options = 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
|
|
|
return self::newMarkupEngine(array(
|
|
|
|
'custom-inline' => PhabricatorEnv::getEnvConfig(
|
|
|
|
'differential.custom-remarkup-rules'),
|
|
|
|
'custom-block' => PhabricatorEnv::getEnvConfig(
|
|
|
|
'differential.custom-remarkup-block-rules'),
|
2011-10-20 18:41:38 +02:00
|
|
|
'differential.diff' => idx($options, 'differential.diff'),
|
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
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2012-02-24 23:14:39 +01:00
|
|
|
public static function newDiffusionMarkupEngine(array $options = array()) {
|
|
|
|
return self::newMarkupEngine(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
|
|
|
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(),
|
2011-10-20 18:41:38 +02:00
|
|
|
'differential.diff' => null,
|
2012-01-07 08:32:15 +01:00
|
|
|
'header.generate-toc' => false,
|
2011-07-17 03:25:45 +02:00
|
|
|
'macros' => true,
|
2011-10-09 22:47:27 +02:00
|
|
|
'uri.allowed-protocols' => PhabricatorEnv::getEnvConfig(
|
|
|
|
'uri.allowed-protocols'),
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10-09 22:47:27 +02:00
|
|
|
$engine->setConfig(
|
|
|
|
'uri.allowed-protocols',
|
|
|
|
$options['uri.allowed-protocols']);
|
2011-10-20 18:41:38 +02:00
|
|
|
$engine->setConfig('differential.diff', $options['differential.diff']);
|
2012-01-06 18:08:59 +01:00
|
|
|
$engine->setConfig('header.generate-toc', $options['header.generate-toc']);
|
2011-04-10 23:07:00 +02:00
|
|
|
|
2011-01-30 22:20:56 +01:00
|
|
|
$rules = array();
|
|
|
|
$rules[] = new PhutilRemarkupRuleEscapeRemarkup();
|
2011-10-20 18:41:38 +02:00
|
|
|
|
|
|
|
$custom_rule_classes = $options['custom-inline'];
|
|
|
|
if ($custom_rule_classes) {
|
|
|
|
foreach ($custom_rule_classes as $custom_rule_class) {
|
|
|
|
PhutilSymbolLoader::loadClass($custom_rule_class);
|
|
|
|
$rules[] = newv($custom_rule_class, 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
|
|
|
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-10-09 22:47:27 +02:00
|
|
|
$rules[] = new PhabricatorRemarkupRulePhriction();
|
2011-01-30 22:20:56 +01:00
|
|
|
$rules[] = new PhutilRemarkupRuleHyperlink();
|
2011-02-12 03:06:43 +01:00
|
|
|
|
Provide a "reference-with-full-name" syntax for Remarkup
Summary:
Provide a {T123} syntax which pulls in the entire name of an object, not just a
link to it. A major use for this is organizing projects using wiki pages. Since
handle links show object status now, this lets you organize stuff in an ad-hoc
way and get a reasonable overview of it. We can make handles richer in the
future, too.
The performance on this isn't perfect (it adds some potential single gets) but I
think it's okay for now and I don't want to make remarkup engine even more
complex until the preprocess/postprocess stuff has had a chance to settle and
I'm more confident it works.
In Differential and Maniphest we'll also incorrectly cache the object
state/name, but that'll fix itself once I move the cache code to use
preprocess/postprocess correctly.
Test Plan:
- See https://secure.phabricator.com/file/view/PHID-FILE-5f9ca32407bec20899b9/
for an example.
- Generated and looked over the documentation.
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran, hunterbridges
CC: skrul, aran, jungejason, epriestley
Differential Revision: 784
2011-08-05 17:50:26 +02:00
|
|
|
$rules[] = new PhabricatorRemarkupRuleDifferentialHandle();
|
|
|
|
$rules[] = new PhabricatorRemarkupRuleManiphestHandle();
|
|
|
|
|
2011-07-15 23:17:55 +02:00
|
|
|
$rules[] = new PhabricatorRemarkupRuleEmbedFile();
|
Provide a "reference-with-full-name" syntax for Remarkup
Summary:
Provide a {T123} syntax which pulls in the entire name of an object, not just a
link to it. A major use for this is organizing projects using wiki pages. Since
handle links show object status now, this lets you organize stuff in an ad-hoc
way and get a reasonable overview of it. We can make handles richer in the
future, too.
The performance on this isn't perfect (it adds some potential single gets) but I
think it's okay for now and I don't want to make remarkup engine even more
complex until the preprocess/postprocess stuff has had a chance to settle and
I'm more confident it works.
In Differential and Maniphest we'll also incorrectly cache the object
state/name, but that'll fix itself once I move the cache code to use
preprocess/postprocess correctly.
Test Plan:
- See https://secure.phabricator.com/file/view/PHID-FILE-5f9ca32407bec20899b9/
for an example.
- Generated and looked over the documentation.
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran, hunterbridges
CC: skrul, aran, jungejason, epriestley
Differential Revision: 784
2011-08-05 17:50:26 +02:00
|
|
|
|
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-07-17 03:25:45 +02:00
|
|
|
|
|
|
|
if ($options['macros']) {
|
|
|
|
$rules[] = new PhabricatorRemarkupRuleImageMacro();
|
|
|
|
}
|
|
|
|
|
2011-06-24 19:59:57 +02:00
|
|
|
$rules[] = new PhabricatorRemarkupRuleMention();
|
2011-02-12 03:06:43 +01:00
|
|
|
|
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();
|
2012-01-04 01:17:40 +01:00
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupLiteralBlockRule();
|
2011-01-30 22:20:56 +01:00
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupHeaderBlockRule();
|
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupListBlockRule();
|
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupCodeBlockRule();
|
2011-12-01 18:48:27 +01:00
|
|
|
$blocks[] = new PhutilRemarkupEngineRemarkupNoteBlockRule();
|
2011-01-30 22:20:56 +01:00
|
|
|
$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) {
|
2012-01-04 01:17:40 +01:00
|
|
|
if ($block instanceof PhutilRemarkupEngineRemarkupLiteralBlockRule) {
|
|
|
|
$literal_rules = array();
|
|
|
|
$literal_rules[] = new PhutilRemarkupRuleHyperlink();
|
|
|
|
$literal_rules[] = new PhutilRemarkupRuleEscapeHTML();
|
|
|
|
$literal_rules[] = new PhutilRemarkupRuleLinebreaks();
|
|
|
|
$block->setMarkupRules($literal_rules);
|
|
|
|
} else if (
|
|
|
|
!($block instanceof PhutilRemarkupEngineRemarkupCodeBlockRule)) {
|
2011-01-30 22:20:56 +01:00
|
|
|
$block->setMarkupRules($rules);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$engine->setBlockRules($blocks);
|
|
|
|
|
|
|
|
return $engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|