DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:bookmark

This is an old revision of the document!


Bookmark Plugin

Compatible with DokuWiki

2010-11-07 2011-05-25, angua, weatherwax

plugin Insert a link anchor into the page

Last updated on
2005-08-01
Provides
Syntax

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to anchor

Tagged with anchor, bookmark, links

Description

With this plugin you can insert a bookmark to your page. The format is

<BOOKMARK:bookmark_name>

This will insert code

<a name='bookmark_name'></a>

To link to the bookmark from the same page (i.e. to use the bookmark as an anchor link within the page), use this syntax:

[[namespace:page_name#bookmark_name|anchor_text]]

Where anchor_text is the text-link your visitors will see.

Installation

Install with Plugin Manager from here

Plugin

Create a new folder lib/plugin/bookmark/ and place the following file in it: syntax.php.

lib/plugin/bookmark/syntax.php:

<?php
/**
 * Plugin bookmark: Creates a bookmark to your document.
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Otto Vainio <bookmark.plugin@valjakko.net>
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_bookmark extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Otto Vainio',
            'email'  => 'bookmark.plugin@valjakko.net',
            'date'   => '2005-08-01',
            'name'   => 'Bookmark plugin',
            'desc'   => 'a bookmark <a name=\'name\'></a>',
            'url'    => 'http://www.dokuwiki.org/plugin:bookmark',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
    function getSort(){ return 357; }
 
    function connectTo($mode) {
        $this->Lexer->addSpecialPattern('<BOOKMARK:\w+>',$mode,'plugin_bookmark');
    }
 
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        $match = substr($match,10,-1); //strip <BOOKMARK: from start and > from end
        return array(strtolower($match));
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
            $renderer->doc .= '<a name="' . $data[0] . '" id="' . $data[0]. '"></a>';
            return true;
        }
        return false;
    }
}
?>

Discussion

I Installed this plugin, but this script didn't work. I tried to use the syntax but it didn't work. Is there any manual or samples about this plugin?

Hi. Remember to use capital letters for BOOKMARK. So the format is: <BOOKMARK:name> With the < and > marks. <bookmark:name> will not work… sorry — Otto Vainio 2006-09-04 12:08


While it works nicely with Firefox, it does not work for me with MSIE 6.0.2800.1106CO SP1, unless is hack the syntax.php to add an id attribute alongside to the name attribute of the anchor tag:

<a name='name' id='name'></a>

Yes I know that MSIE sucks, but DokuWiki uses the same trick for the anchor tags automatically generated for headings… — Gábor Ziegler 2007/06/15 10:01


Hi ! I just love this plugin. But I failed to address one of this bookmarks from within the wiki?

[[page#bookmark]]

Does not work … Markus A. Engelkamp
Hi,

Is it possible to use this plugin to point to a particular section of the page?


This plugin doesn't appear to work in the current version of DokuWiki.

It works well for me with the DokuWiki Release 2009-12-25c “Lemming” on Wiki Eolienne

Jean
I tested it with release 2013-05-10a “Weatherwax” and it worked, even without plugin.info.txt file.
archangel 2013/07/03 22:42

—-

I tested it with release 2014-05-05a “Ponder Stibbons” and it worked. 2014/07/31 11:00am

It would be great if other characters, apart from word characters (\w) are allowed in the anchor name. I.e. I have modified syntax.php, line 43 to “$this→Lexer→addSpecialPattern('<BOOKMARK:[\w\-]+>',$mode,'plugin_bookmark');” since I needed '-' in the anchor name.

plugin/bookmark.1406797345.txt.gz · Last modified: 2014-07-31 11:02 by 213.174.234.130

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki