DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:linkway

Link Way Plugin

Compatible with DokuWiki

No compatibility info given!

plugin Extends the link syntax so you can put the link text before the brackets

Last updated on
2006-06-29
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.

Tagged with links

This plugin extends DokuWiki's link syntax. It should not interfere with the built in syntax.

Syntax

Basically, this plugin lets you put the link title text before the bracketed link.

title[[syntax]]

and

"this is a link"[[syntax]]

or

title[wiki:syntax]

and

"this is a link"[wiki:syntax]

Note that you can use single or double brackets. Surround the title text with double quotes if you are using multiple words.

Installation

Download a zip here.

syntax.php

<?php
/**
* LinkWay Plugin: extends DokuWiki's link syntax.
* 
* @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author     Allen Ormond <aormond [at] gmail>  
*/
 
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_linkway extends DokuWiki_Syntax_Plugin {
 
	/**
	* return some info
	*/
	function getInfo(){
		return array(
			'author' => 'Allen Ormond',
			'email'  => 'aormond at gmaildotcom',
			'date'   => '2006-06-29',
			'name'   => 'Link Way',
			'desc'   => 'Extends DokuWiki\'s link syntax.',
			'url'    => 'http://www.dokuwiki.org/plugin:link_way',
			);
		}
 
		/**
		* Syntax Type
		*
		* Needs to return one of the mode types defined in $PARSER_MODES in parser.php
		*/
		function getType(){
			return('substition');
		}
 
		function connectTo($mode) {
			$this->Lexer->addSpecialPattern('[a-zA-Z0-9]+?\[{1,2}.*?\]{1,2}',$mode,'plugin_linkway');
			$this->Lexer->addSpecialPattern('"[a-zA-Z0-9 ]+?"\[{1,2}.*?\]{1,2}',$mode,'plugin_linkway');
			}
 
			function getSort() {
				return 244;
			}
 
			/**
			* Handler to prepare matched data for the rendering process
			*/
			function handle($match, $state, $pos, &$handler){
				if (preg_match('/"[a-zA-Z0-9 ]+?"\[/',$match)){
					preg_match_all('/"([a-zA-Z0-9 ]+?)"\[{1,2}(.*?)\]{1,2}/',$match, $matches);
					$link = $matches[2][0];
					$text = $matches[1][0];
					return array($link, $text);
				} else {
					preg_match_all('/([a-zA-Z0-9]+?)\[{1,2}(.*?)\]{1,2}/',$match, $matches);
					$link = $matches[2][0];
					$text = $matches[1][0];
					return array($link, $text);					
				}
			}
 
			/**
			* Handles the actual output creation.
			*/
			function render($format, &$renderer, $data) {
				$renderer->internallink($data[0],$data[1]); 
			}
 
		}
		//Setup VIM: ex: et ts=4 enc=utf-8 :
?>

Revision History

  • 2006-06-30 — Released.

Bugs

Discussion

This is my first attempt at a plugin. It's been working fine for me, but please let me know of any suggestions/problems. — Allen Ormond 2006-06-30 07:26

Seems to be useful. Just some notes:

  • The RegEx patterns are wrong. Links must be marked up by two brackets while your REs allow one or two.
  • The REs allow any content between the brackets. I'd suggest to limit this to the actually possible characters.
  • In handle() (and render()) you should check the state for DOKU_LEXER_SPECIAL.
  • In render() undiscriminating internal links are created. I'd suggest to extend handle() to check for external links and add a flag to the returned array which you could check in render().
  • Why are you accepting both single and double quotes? Wouldn't be one enough for your intended purpose?

Matthias Watermann 2007-01-18 15:07

plugin/linkway.txt · Last modified: 2015-04-04 06:25 by PatrickBrown