Skip to content

Commit fa49c6c

Browse files
author
epriestley
committedAug 6, 2011
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
1 parent 2335114 commit fa49c6c

10 files changed

+247
-0
lines changed
 

‎src/__phutil_library_map__.php

+6
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,14 @@
485485
'PhabricatorRedirectController' => 'applications/base/controller/redirect',
486486
'PhabricatorRefreshCSRFController' => 'applications/auth/controller/refresh',
487487
'PhabricatorRemarkupRuleDifferential' => 'infrastructure/markup/remarkup/markuprule/differential',
488+
'PhabricatorRemarkupRuleDifferentialHandle' => 'infrastructure/markup/remarkup/markuprule/handle/differential',
488489
'PhabricatorRemarkupRuleDiffusion' => 'infrastructure/markup/remarkup/markuprule/diffusion',
489490
'PhabricatorRemarkupRuleEmbedFile' => 'infrastructure/markup/remarkup/markuprule/embedobject',
490491
'PhabricatorRemarkupRuleImageMacro' => 'infrastructure/markup/remarkup/markuprule/imagemacro',
491492
'PhabricatorRemarkupRuleManiphest' => 'infrastructure/markup/remarkup/markuprule/maniphest',
493+
'PhabricatorRemarkupRuleManiphestHandle' => 'infrastructure/markup/remarkup/markuprule/handle/maniphest',
492494
'PhabricatorRemarkupRuleMention' => 'infrastructure/markup/remarkup/markuprule/mention',
495+
'PhabricatorRemarkupRuleObjectHandle' => 'infrastructure/markup/remarkup/markuprule/handle',
493496
'PhabricatorRemarkupRuleObjectName' => 'infrastructure/markup/remarkup/markuprule/objectname',
494497
'PhabricatorRemarkupRulePaste' => 'infrastructure/markup/remarkup/markuprule/paste',
495498
'PhabricatorRemarkupRulePhriction' => 'infrastructure/markup/remarkup/markuprule/phriction',
@@ -1028,11 +1031,14 @@
10281031
'PhabricatorRedirectController' => 'PhabricatorController',
10291032
'PhabricatorRefreshCSRFController' => 'PhabricatorAuthController',
10301033
'PhabricatorRemarkupRuleDifferential' => 'PhabricatorRemarkupRuleObjectName',
1034+
'PhabricatorRemarkupRuleDifferentialHandle' => 'PhabricatorRemarkupRuleObjectHandle',
10311035
'PhabricatorRemarkupRuleDiffusion' => 'PhutilRemarkupRule',
10321036
'PhabricatorRemarkupRuleEmbedFile' => 'PhutilRemarkupRule',
10331037
'PhabricatorRemarkupRuleImageMacro' => 'PhutilRemarkupRule',
10341038
'PhabricatorRemarkupRuleManiphest' => 'PhabricatorRemarkupRuleObjectName',
1039+
'PhabricatorRemarkupRuleManiphestHandle' => 'PhabricatorRemarkupRuleObjectHandle',
10351040
'PhabricatorRemarkupRuleMention' => 'PhutilRemarkupRule',
1041+
'PhabricatorRemarkupRuleObjectHandle' => 'PhutilRemarkupRule',
10361042
'PhabricatorRemarkupRuleObjectName' => 'PhutilRemarkupRule',
10371043
'PhabricatorRemarkupRulePaste' => 'PhabricatorRemarkupRuleObjectName',
10381044
'PhabricatorRemarkupRulePhriction' => 'PhutilRemarkupRule',

‎src/applications/markup/engine/PhabricatorMarkupEngine.php

+4
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ private static function newMarkupEngine(array $options) {
100100

101101
$rules[] = new PhutilRemarkupRuleHyperlink();
102102

103+
$rules[] = new PhabricatorRemarkupRuleDifferentialHandle();
104+
$rules[] = new PhabricatorRemarkupRuleManiphestHandle();
105+
103106
$rules[] = new PhabricatorRemarkupRuleEmbedFile();
107+
104108
$rules[] = new PhabricatorRemarkupRuleDifferential();
105109
$rules[] = new PhabricatorRemarkupRuleDiffusion();
106110
$rules[] = new PhabricatorRemarkupRuleManiphest();

‎src/applications/markup/engine/__init__.php

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/differential');
1111
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/diffusion');
1212
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/embedobject');
13+
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/handle/differential');
14+
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/handle/maniphest');
1315
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/imagemacro');
1416
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/maniphest');
1517
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/mention');

‎src/docs/userguide/remarkup.diviner

+34
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@ other lightweight markup langauges like Markdown and Wiki markup.
1111

1212
This document describes how to format text using Remarkup.
1313

14+
= Quick Reference =
15+
16+
All the syntax is explained in more detail below, but this is a quick guide to
17+
formatting text in Remarkup:
18+
19+
**bold** //italic// ##monospaced##
20+
= Large Header=
21+
== Smaller Header ==
22+
> Quoted Text
23+
D123 T123 rX123 # Link to Objects
24+
{D123} {T123} # Link to Objects (Full Name)
25+
{F123} # Embed Images
26+
[[wiki page]] # Link to Phriction
27+
@username # Mention a user
28+
Indent two spaces for code.
29+
Indent two spaces with "-" for lists.
30+
1431
= Basic Styling =
1532

1633
Format **basic text styles** like this:
@@ -103,6 +120,14 @@ You can also link directly to a comment in Maniphest and Differential:
103120

104121
T123#4 # Link to comment #4 of T123
105122

123+
You can also generate full-name references to some objects by using braces:
124+
125+
{D123} # Link to Differential revision D123 with the full name
126+
{T123} # Link to Maniphest task T123 with the full name
127+
128+
These references will also show when an object changes state (for instance, a
129+
task is closed or a revision is committed).
130+
106131
= Quoting Text =
107132

108133
To quote text, preface it with an ">":
@@ -113,6 +138,15 @@ This appears like this:
113138

114139
> This is quoted text.
115140

141+
= Embedding Images =
142+
143+
You can embed an image by using braces to refer to it:
144+
145+
{F92} # Embed the image file F92
146+
147+
In most interfaces, you can drag-and-drop an image from your computer into the
148+
text area to upload and reference it.
149+
116150
= Embedding Media =
117151

118152
If you set configuration flags, you can embed media directly in text:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2011 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* @group markup
21+
*/
22+
abstract class PhabricatorRemarkupRuleObjectHandle
23+
extends PhutilRemarkupRule {
24+
25+
const KEY_RULE_HANDLE = 'rule.handle';
26+
27+
abstract protected function getObjectNamePrefix();
28+
abstract protected function loadObjectPHID($id);
29+
30+
public function apply($text) {
31+
$prefix = $this->getObjectNamePrefix();
32+
return preg_replace_callback(
33+
"@\B{{$prefix}(\d+)}\B@",
34+
array($this, 'markupObjectHandle'),
35+
$text);
36+
}
37+
38+
private function markupObjectHandle($matches) {
39+
// TODO: These are single gets but should be okay for now, they're behind
40+
// the cache.
41+
$phid = $this->loadObjectPHID($matches[1]);
42+
if (!$phid) {
43+
return $matches[0];
44+
}
45+
46+
$engine = $this->getEngine();
47+
$token = $engine->storeText('');
48+
49+
$metadata_key = self::KEY_RULE_HANDLE;
50+
$metadata = $engine->getTextMetadata($metadata_key, array());
51+
if (empty($metadata[$phid])) {
52+
$metadata[$phid] = array();
53+
}
54+
$metadata[$phid][] = $token;
55+
$engine->setTextMetadata($metadata_key, $metadata);
56+
57+
return $token;
58+
}
59+
60+
public function didMarkupText() {
61+
$engine = $this->getEngine();
62+
63+
$metadata_key = self::KEY_RULE_HANDLE;
64+
$metadata = $engine->getTextMetadata($metadata_key, array());
65+
if (empty($metadata)) {
66+
return;
67+
}
68+
69+
$handles = id(new PhabricatorObjectHandleData(array_keys($metadata)))
70+
->loadHandles();
71+
72+
foreach ($metadata as $phid => $tokens) {
73+
$link = $handles[$phid]->renderLink();
74+
foreach ($tokens as $token) {
75+
$engine->overwriteStoredText($token, $link);
76+
}
77+
}
78+
79+
$engine->setTextMetadata($metadata_key, array());
80+
}
81+
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
phutil_require_module('phabricator', 'applications/phid/handle/data');
10+
11+
phutil_require_module('phutil', 'markup/engine/remarkup/markuprule/base');
12+
phutil_require_module('phutil', 'utils');
13+
14+
15+
phutil_require_source('PhabricatorRemarkupRuleObjectHandle.php');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2011 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* @group markup
21+
*/
22+
final class PhabricatorRemarkupRuleDifferentialHandle
23+
extends PhabricatorRemarkupRuleObjectHandle {
24+
25+
protected function getObjectNamePrefix() {
26+
return 'D';
27+
}
28+
29+
protected function loadObjectPHID($id) {
30+
$revision = id(new DifferentialRevision())->load($id);
31+
if ($revision) {
32+
return $revision->getPHID();
33+
}
34+
return null;
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
phutil_require_module('phabricator', 'applications/differential/storage/revision');
10+
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/handle');
11+
12+
phutil_require_module('phutil', 'utils');
13+
14+
15+
phutil_require_source('PhabricatorRemarkupRuleDifferentialHandle.php');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2011 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* @group markup
21+
*/
22+
final class PhabricatorRemarkupRuleManiphestHandle
23+
extends PhabricatorRemarkupRuleObjectHandle {
24+
25+
protected function getObjectNamePrefix() {
26+
return 'T';
27+
}
28+
29+
protected function loadObjectPHID($id) {
30+
$task = id(new ManiphestTask())->load($id);
31+
if ($task) {
32+
return $task->getPHID();
33+
}
34+
return null;
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
phutil_require_module('phabricator', 'applications/maniphest/storage/task');
10+
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/handle');
11+
12+
phutil_require_module('phutil', 'utils');
13+
14+
15+
phutil_require_source('PhabricatorRemarkupRuleManiphestHandle.php');

0 commit comments

Comments
 (0)
Failed to load comments.