Bookmark Plugin

Compatible with DokuWiki

  • 2012-01-25 "Angua" yes
  • 2011-05-25 "Rincewind" yes
  • 2010-11-07 "Anteater" yes

plugin Insert a link anchor into the page

Last updated on
2005-08-01
Provides
Syntax

Similar to anchor

Tagged with bookmark, links

Description

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

<BOOKMARK:name>

This will insert code

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

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

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.txt · Last modified: 2011/12/23 21:53 by rikblok
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate