1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 21:32:43 +01:00

Document wiki relative link syntax

Summary: Also make `../` work to start relative a link so I don't have to document it as `./../path`.

Test Plan:
  - Used `./`, `../`. `./../`, and normal links (proper title pickup).
  - Used bad links (red).
  - Regenerated documentation:

{F1221692}

Reviewers: hach-que

Reviewed By: hach-que

Differential Revision: https://secure.phabricator.com/D15734
This commit is contained in:
epriestley 2016-04-16 08:48:05 -07:00
parent b2d2f03dea
commit 025b243e27
2 changed files with 25 additions and 2 deletions

View file

@ -19,7 +19,7 @@ final class PhrictionRemarkupRule extends PhutilRemarkupRule {
$link = trim($matches[1]); $link = trim($matches[1]);
// Handle relative links. // Handle relative links.
if (substr($link, 0, 2) === './') { if ((substr($link, 0, 2) === './') || (substr($link, 0, 3) === '../')) {
$base = null; $base = null;
$context = $this->getEngine()->getConfig('contextObject'); $context = $this->getEngine()->getConfig('contextObject');
if ($context !== null && $context instanceof PhrictionContent) { if ($context !== null && $context instanceof PhrictionContent) {
@ -33,7 +33,7 @@ final class PhrictionRemarkupRule extends PhutilRemarkupRule {
} }
if ($base !== null) { if ($base !== null) {
$base_parts = explode('/', rtrim($base, '/')); $base_parts = explode('/', rtrim($base, '/'));
$rel_parts = explode('/', substr(rtrim($link, '/'), 2)); $rel_parts = explode('/', rtrim($link, '/'));
foreach ($rel_parts as $part) { foreach ($rel_parts as $part) {
if ($part === '.') { if ($part === '.') {
// Consume standalone dots in a relative path, and do // Consume standalone dots in a relative path, and do

View file

@ -512,11 +512,34 @@ You can link to Phriction documents with a name or path:
Make sure you sign and date your [[legal/Letter of Marque and Reprisal]]! Make sure you sign and date your [[legal/Letter of Marque and Reprisal]]!
By default, the link will render with the document title as the link name.
With a pipe (`|`), you can retitle the link. Use this to mislead your With a pipe (`|`), you can retitle the link. Use this to mislead your
opponents: opponents:
Check out these [[legal/boring_documents/ | exciting legal documents]]! Check out these [[legal/boring_documents/ | exciting legal documents]]!
Links to pages which do not exist are shown in red. Links to pages which exist
but which the viewer does not have permission to see are shown with a lock
icon, and the link will not disclose the page title.
If you begin a link path with `./` or `../`, the remainder of the path will be
evaluated relative to the current wiki page. For example, if you are writing
content for the document `fruit/` a link to `[[./guava]]` is the same as a link
to `[[fruit/guava]]` from elsewhere.
Relative links may use `../` to transverse up the document tree. From the
`produce/vegetables/` page, you can use `[[../fruit/guava]]` to link to the
`produce/fruit/guava` page.
Relative links do not work when used outside of wiki pages. For example,
you can't use a relative link in a comment on a task, because there is no
reasonable place for the link to start resolving from.
When documents are moved, relative links are not automatically updated: they
are preserved as currently written. After moving a document, you may need to
review and adjust any relative links it contains.
= Literal Blocks = = Literal Blocks =
To place text in a literal block use `%%%`: To place text in a literal block use `%%%`: