From 079b22f249675c7ea6dd381d71e578b96cf4d5a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Mon, 25 May 2020 22:49:51 +0200 Subject: [PATCH] Handle anchors on confluence links #208 --- .../ContentTypes/Markdown/LinkRenderer.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libs/Format/Confluence/ContentTypes/Markdown/LinkRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/LinkRenderer.php index 9bb662f..06590b1 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/LinkRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/LinkRenderer.php @@ -30,15 +30,25 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer return $element; } + // if there's a hash component in the url, ensure we + // don't put that part through the resolver. + $urlAndHash = explode('#', $url); + $url = $urlAndHash[0]; + //Internal links $file = DauxHelper::resolveInternalFile($this->daux, $url); - $link_props = [ + $link_props = []; + if (isset($urlAndHash[1])) { + $link_props["ac:anchor"] = $urlAndHash[1]; + } + + $page_props = [ 'ri:content-title' => trim(trim($this->daux['confluence']['prefix']) . ' ' . $file->getTitle()), 'ri:space-key' => $this->daux['confluence']['space_id'], ]; - $page = strval(new HtmlElement('ri:page', $link_props, '', true)); + $page = strval(new HtmlElement('ri:page', $page_props, '', true)); $children = $htmlRenderer->renderInlines($inline->children()); if (strpos($children, '<') !== false) { $children = '' . $children . ''; @@ -46,6 +56,6 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer $children = ''; } - return new HtmlElement('ac:link', [], $page . $children); + return new HtmlElement('ac:link', $link_props, $page . $children); } }