Differential D25118 Diff 1769 src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php
Show All 38 Lines | $text = preg_replace_callback( | ||||
$text); | $text); | ||||
return $text; | return $text; | ||||
} | } | ||||
protected function renderHyperlink($link, $name) { | protected function renderHyperlink($link, $name) { | ||||
$engine = $this->getEngine(); | $engine = $this->getEngine(); | ||||
$is_anchor = false; | $uri = new PhutilURIHelper($link); | ||||
if (strncmp($link, '/', 1) == 0) { | $is_anchor = $uri->isAnchor(); | ||||
$starts_with_slash = $uri->isStartingWithSlash(); | |||||
if ($starts_with_slash) { | |||||
valerio.bozzolan: ✅ This is the exact equivalent | |||||
$base = phutil_string_cast($engine->getConfig('uri.base')); | $base = phutil_string_cast($engine->getConfig('uri.base')); | ||||
$base = rtrim($base, '/'); | $base = rtrim($base, '/'); | ||||
$link = $base.$link; | $link = $base.$link; | ||||
} else if (strncmp($link, '#', 1) == 0) { | } else if ($is_anchor) { | ||||
Done Inline Actions✅ This is the exact equivalent valerio.bozzolan: ✅ This is the exact equivalent | |||||
$here = $engine->getConfig('uri.here'); | $here = $engine->getConfig('uri.here'); | ||||
$link = $here.$link; | $link = $here.$link; | ||||
$is_anchor = true; | |||||
} | } | ||||
if ($engine->isTextMode()) { | if ($engine->isTextMode()) { | ||||
// If present, strip off "mailto:" or "tel:". | // If present, strip off "mailto:" or "tel:". | ||||
$link = preg_replace('/^(?:mailto|tel):/', '', $link); | $link = preg_replace('/^(?:mailto|tel):/', '', $link); | ||||
if (!strlen($name)) { | if (!strlen($name)) { | ||||
return $link; | return $link; | ||||
} | } | ||||
return $name.' <'.$link.'>'; | return $name.' <'.$link.'>'; | ||||
} | } | ||||
if (!strlen($name)) { | if (!strlen($name)) { | ||||
$name = $link; | $name = $link; | ||||
$name = preg_replace('/^(?:mailto|tel):/', '', $name); | $name = preg_replace('/^(?:mailto|tel):/', '', $name); | ||||
} | } | ||||
if ($engine->getState('toc')) { | if ($engine->getState('toc')) { | ||||
return $name; | return $name; | ||||
} | } | ||||
$same_window = $engine->getConfig('uri.same-window', false); | // Check if this link points to Phorge itself. Micro-optimized. | ||||
Done Inline ActionsHere I just changed the false to $is_internal valerio.bozzolan: Here I just changed the `false` to `$is_internal` | |||||
$is_self = $is_anchor || $starts_with_slash || $uri->isSelf(); | |||||
// For historical reasons, links opened in a different tab | |||||
// for most links as default. | |||||
// Now internal resources keep internal link, as default. | |||||
$same_window = $engine->getConfig('uri.same-window', $is_self); | |||||
if ($same_window) { | if ($same_window) { | ||||
Done Inline Actions✅ This is just a better default. Note that if uri.same-window is already set, we also never call our extra logic. valerio.bozzolan: ✅ This is just a better default. Note that if `uri.same-window` is already set, we also never… | |||||
Done Inline ActionsThis comment is redundant (and long). Remove it please. avivey: This comment is redundant (and long). Remove it please. | |||||
$target = null; | $target = null; | ||||
} else { | } else { | ||||
$target = '_blank'; | $target = '_blank'; | ||||
} | } | ||||
// For anchors on the same page, always stay here. | // For anchors on the same page, always stay here. | ||||
if ($is_anchor) { | if ($is_anchor) { | ||||
$target = null; | $target = null; | ||||
} | } | ||||
return phutil_tag( | return phutil_tag( | ||||
'a', | 'a', | ||||
array( | array( | ||||
'href' => $link, | 'href' => $link, | ||||
'class' => 'remarkup-link', | 'class' => $this->getRemarkupLinkClass($is_self), | ||||
'target' => $target, | 'target' => $target, | ||||
'rel' => 'noreferrer', | 'rel' => 'noreferrer', | ||||
), | ), | ||||
$name); | $name); | ||||
} | } | ||||
public function markupAlternateLink(array $matches) { | public function markupAlternateLink(array $matches) { | ||||
$uri = trim($matches[2]); | $uri = trim($matches[2]); | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0
✅ This is the exact equivalent