Page MenuHomePhabricator

D19111.diff
No OneTemporary

D19111.diff

diff --git a/src/markup/engine/__tests__/remarkup/link-square.txt b/src/markup/engine/__tests__/remarkup/link-square.txt
--- a/src/markup/engine/__tests__/remarkup/link-square.txt
+++ b/src/markup/engine/__tests__/remarkup/link-square.txt
@@ -2,7 +2,7 @@
[[http://www.example.com/ | example.com]]
-[[/]]
+[[/x/]]
[[#anchor]]
@@ -12,7 +12,7 @@
<p><a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">example.com</a></p>
-<p><a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/</a></p>
+<p><a href="http://www.example.com/x/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/x/</a></p>
<p><a href="http://www.example.com/page/#anchor" class="remarkup-link" rel="noreferrer">http://www.example.com/page/#anchor</a></p>
@@ -22,7 +22,7 @@
example.com <http://www.example.com/>
-http://www.example.com/
+http://www.example.com/x/
http://www.example.com/page/#anchor
diff --git a/src/markup/engine/remarkup/markuprule/PhutilRemarkupDocumentLinkRule.php b/src/markup/engine/remarkup/markuprule/PhutilRemarkupDocumentLinkRule.php
--- a/src/markup/engine/remarkup/markuprule/PhutilRemarkupDocumentLinkRule.php
+++ b/src/markup/engine/remarkup/markuprule/PhutilRemarkupDocumentLinkRule.php
@@ -15,7 +15,26 @@
// Handle markdown-style links: [name](href)
$text = preg_replace_callback(
- '@\B\\[([^\\]]+)\\]\\(([^\\)]+)\\)\B@U',
+ '@'.
+ '\B'.
+ '\\[([^\\]]+)\\]'.
+ '\\('.
+ '(\s*'.
+ // See T12343. This is making some kind of effort to implement
+ // parenthesis balancing rules. It won't get nested parentheses
+ // right, but should do OK for Wikipedia pages, which seem to be
+ // the most important use case.
+
+ // Match zero or more non-parenthesis, non-space characters.
+ '[^\s()]*'.
+ // Match zero or more sequences of "(...)", where two balanced
+ // parentheses enclose zero or more normal characters. If we
+ // match some, optionally match more stuff at the end.
+ '(?:(?:\\([^ ()]*\\))+[^\s()]*)?'.
+ '\s*)'.
+ '\\)'.
+ '\B'.
+ '@U',
array($this, 'markupAlternateLink'),
$text);
@@ -94,6 +113,10 @@
return $matches[0];
}
+ if (!strlen($uri[0])) {
+ return $matches[0];
+ }
+
if (strpos($uri, '/') === false &&
strpos($uri, '@') === false &&
strncmp($uri, 'tel:', 4)) {
@@ -134,6 +157,13 @@
}
}
+ // As a special case, skip "[[ / ]]" so that Phriction picks it up as a
+ // link to the Phriction root. It is more useful to be able to use this
+ // syntax to link to the root document than the home page of the install.
+ if ($uri == '/') {
+ $is_uri = false;
+ }
+
if (!$is_uri) {
return $matches[0];
}

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 2:53 AM (10 h, 53 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6905783
Default Alt Text
D19111.diff (2 KB)

Event Timeline