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]) {