DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:relativelinks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
plugin:relativelinks [2008-03-07 11:56] 155.198.108.162plugin:relativelinks [2017-10-28 15:00] – [Code] turnermm
Line 1: Line 1:
 +====== relativelinks plugin ======
 +
 +---- plugin ----
 +description: Replaces standard wiki-base-centric links with relative ones (anything which doesn't start with . or : is assumed to be relative to the current namespace
 +author     : Andy Turner
 +email      : public [at] ssbd [dot] net
 +type       : Syntax
 +lastupdate : 2008-03-07
 +compatible : 
 +depends    : 
 +conflicts 
 +similar    : 
 +tags       : links namespace
 +----
 +
 +====== Description ======
 +
 +Whether it is of general interest to the wider community or not, I would prefer it if DokuWiki's links were relative to the current document's namespace.  As such, I created this incredibly simple plugin (based upon the first syntax plugin example) which rewrites the links that don't start with ".", ".." or ":".
 +
 +
 +
 +====== Discussion ======
 +
 +"Works for me, does what I want" ;-)
 +
 +Hmm, doesn't work for me.  I noticed that it messes up external links... oops.
 +
 +<code>
 +    $event->data = preg_replace( "/\[\[([^:.][^\/]*?(?:\|.*?))\]\]/", '[[.:${1}]]', $event->data );
 +</code>
 +
 +Updated the regexp so that it doesn't match links with slashes in the address.  :-\
 +
 +====== Code ======
 +
 +<code php syntax.php>
 +<?php 
 +/**
 + * Relative Linking Plugin
 + *
 + * @author Andy Turner <public@ssbd.net>
 + */
 +
 +if(!defined('DOKU_INC')) die();
 +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
 +require_once(DOKU_PLUGIN.'action.php');
 +
 +class action_plugin_relativelinks extends DokuWiki_Action_Plugin {
 +
 +  /**
 +   * return some info
 +   */
 +  function getInfo(){
 +    return array(
 +                 'author' => 'Andy Turner',
 +                 'email'  => 'public [at] ssbd [dot] net',
 +                 'date'   => '2008-03-07',
 +                 'name'   => 'Relative Links',
 +                 'desc'   => 'Replaces standard wiki-base-centric links with relative ones (anything which doesn't start with . or : is assumed to be relative to the current namespace)',
 +                 );
 +  }
 +
 +  /**
 +   * Register its handlers with the DokuWiki's event controller
 +   */
 +  function register(Doku_Event_Handler $controller) {
 +    $controller->register_hook('PARSER_WIKITEXT_PREPROCESS', 'BEFORE',  $this, '_hookrellink');
 +  }
 +
 +  /**
 +   * Stick a colon in front of links... that's all :D
 +   *
 +   * @author Andy Turner <public [at] ssbd [dot] net>
 +   */
 +  function _hookrellink(&$event, $param) {
 +        $event->data = preg_replace( "/\[\[([^:.][^\/]*?(?:\|.*?))\]\]/", '[[.:${1}]]', $event->data );
 +  }
 +}
 +</code>
 +
  
plugin/relativelinks.txt · Last modified: 2017-10-28 15:10 by turnermm

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