From 7026615f898023645af6886f50a1e72a14fef9f1 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Fri, 19 Apr 2013 21:39:53 +0200 Subject: [PATCH] Fix local links to not included sections, fixes #108 This transforms local links in an included page into internal links if the page hasn't been fully included. This doesn't consider the case that the target section (but not the full page) has been included at another place in the page as this is considered to be rather unlikely. --- _test/locallink_conversion.test.php | 38 +++++++++++++++++++++++++++++ helper.php | 7 ++++++ 2 files changed, 45 insertions(+) create mode 100644 _test/locallink_conversion.test.php diff --git a/_test/locallink_conversion.test.php b/_test/locallink_conversion.test.php new file mode 100644 index 0000000..b344237 --- /dev/null +++ b/_test/locallink_conversion.test.php @@ -0,0 +1,38 @@ +pluginsEnabled[] = 'include'; + parent::setUp(); + + $this->helper = plugin_load('helper', 'include'); + + saveWikiText('included', 'Example content with link [[#jump]]', 'Test setup'); + idx_addPage('test:included'); + + saveWikiText('test:includefull', '{{page>..:included}}', 'Test setup'); + idx_addPage('test:includefull'); + + saveWikiText('test:includefirst', '{{page>..:included&firstseconly}}', 'Test setup'); + idx_addPage('test:includefirst'); + } + + public function testLocalConverted() { + $html = p_wiki_xhtml('test:includefirst'); + $this->assertContains('href="'.wl('included').'#jump"', $html); + $this->assertNotContains('href="#jump"', $html); + } + + public function testLocalExistsIfIncluded() { + $html = p_wiki_xhtml('test:includefull'); + $this->assertContains('href="#jump"', $html); + } +} diff --git a/helper.php b/helper.php index 4a1b336..4c76404 100644 --- a/helper.php +++ b/helper.php @@ -385,6 +385,13 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc } } break; + case 'locallink': + /* Convert local links to internal links if the page hasn't been fully included */ + if ($included_pages == null || !array_key_exists($page, $included_pages)) { + $ins[$i][0] = 'internallink'; + $ins[$i][1][0] = ':'.$page.'#'.$ins[$i][1][0]; + } + break; case 'plugin': // FIXME skip other plugins? switch($ins[$i][1][0]) {