DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:anchor

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
plugin:anchor [2018-11-27 15:37] ziothplugin:anchor [2024-02-11 03:39] (current) zioth
Line 1: Line 1:
-====== anchor Plugin ======+====== Anchor Plugin ======
  
 ---- plugin ---- ---- plugin ----
-description: Add HTML anchors to a page. Useful when section headers are really long.+description: Add HTML anchors to a page. Useful when section headers are really long
 author     : Eli Fenton author     : Eli Fenton
 email      : elifenton@this_is_not_a_real_email.fake email      : elifenton@this_is_not_a_real_email.fake
 type       : syntax type       : syntax
-lastupdate : 2013-08-16 +lastupdate : 2024-02-10 
-compatible : 2010-11-07, 2011-05-25, anguaweatherwaxbinkyponder stibbonshrundetritus, Frusterick Manners+compatible : 2010-11-07, 2011-05-25, AnguaWeatherwaxBinkyPonder StibbonsHrunDetritus, Frusterick Manners, Greebo, Hogfather, Igor, Jack Jackrum, Kaos
 depends    :  depends    : 
 conflicts  conflicts 
-similar    : bookmark +similar    : bookmark,wrap 
-tags       : anchor, links, sample, bookmark+tags       : anchor, bookmark, links
  
-downloadurl: https://trello-attachments.s3.amazonaws.com/5af4815352fa15728c62aaae/5afe9c8a66d239ee43a6f068/92c13557957b1d6893779951e94ef181/anchor.zip +downloadurl: https://github.com/zioth/dokuwiki-anchor/zipball/master 
-bugtracker :  +bugtracker : https://github.com/zioth/dokuwiki-anchor/issues 
-sourcerepo : +sourcerepo : https://github.com/zioth/dokuwiki-anchor
 donationurl:  donationurl: 
- 
 screenshot_img:  screenshot_img: 
 ---- ----
  
-Normally, you can only link to a wiki pageor a specific section header. This is impractical when header names are long, or you expect that they might change. This plugin lets you create links to any part of your page.+DokuWiki allows you to create links to pagesand to section headers. This plugin allows you to link to any arbitrary point in a page.
  
-This plugin is also a useful sample, if you're having trouble figuring out how to create a syntax plugin.+This plugin is extremely simpleso it's a good place to start if you're trying to figure out how to create a syntax plugin.
  
 ===== Installation ===== ===== Installation =====
- 
-This plugin is so simple, and I'm so lazy, that I'm just going to include the source code. The following text should be in the file ''lib/plugins/anchor/syntax.php'' 
  
 Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually. Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually.
  
  
-==== syntax.php ====+===== Examples/Usage =====
  
-<code php lib/plugins/anchor/syntax.php> +This syntax creates an anchor. Put it anywhere in your pageand links will automatically scroll to that point.
-<?php +
-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');   +
-     +
-class syntax_plugin_anchor extends DokuWiki_Syntax_Plugin  +
-+
- function getType() {return 'substition';+
- function getPType() {return 'block';+
- function getSort() {return 167;}+
  
- function getInfo() { +<code
- return array( +{{anchor:anchor_name:text}}
- 'author' ='Eli Fenton', +
- 'name' => 'Anchor Plugin', +
- 'date' => '2013-08-16', +
- 'url' => 'http://dokuwiki.org/plugin:anchor', +
- 'desc' => 'Add HTML anchors to a page' +
- ); +
-+
-     +
- function connectTo($mode){ +
- $this->Lexer->addSpecialPattern('\{\{anchor:[^}]*\}\}', $mode, 'plugin_anchor'); +
-+
- +
- function handle($match, $state, $pos, &$handler) { +
- return explode(':', substr($match, strlen('{{anchor:'), -2)); +
- } +
-  +
- function render($mode, &$renderer, $data) { +
- $renderer->doc .= '<a name="' . $data[0] . '">' . $data[1] . '</a>'; +
-+
-}+
 </code> </code>
  
 +**anchor_name** is an arbitrary name of your choosing. It must begin with a letter, and must be lowercase.
  
-===== Examples/Usage ===== +**text**, if provided, is a block of text that the anchor will wrap in HTML. It'not all that useful, unless your template adds space or other decoration to empty anchor tags. It's also optional, so this is also valid:
- +
-Here'how you create an anchor:+
  
 <code> <code>
-{{anchor:anchor_name:text}}+{{anchor:anchor_name}}
 </code> </code>
- 
-The anchor_name part is the name of the anchor to use in links. The text part is optional, and, for the most part, not very useful. It lets you wrap the anchor around a specific piece of text. 
  
 To link to an anchor from within DokuWiki: To link to an anchor from within DokuWiki:
 +
 +Use standard DokuWiki syntax to link to the new anchor:
  
 <code> <code>
Line 95: Line 61:
 ==== Changelog ==== ==== Changelog ====
  
-  * 2017-06-20  Changed signature of methods ''handle'' and ''render'' to suppress warnings in PHP 7.1. +  * 2017-06-20 -- Changed signature of methods ''handle'' and ''render'' to suppress warnings in PHP 7.1. 
-  * 2013-05-23  Integrated changes made by Peter B to fix escaping vulnerability and paragraph formatting.+  * 2013-05-23 -- Integrated changes made by Peter B to fix escaping vulnerability and paragraph formatting.
  
 ===== Discussion ===== ===== Discussion =====
  
 +==== Gratuitous newline ====
 +
 +The plugin inserts an unwanted newline after the anchor tag. But I want to create a glossary page with anchored entries of the form:\\
 +**term** -- definition
 +
 +It looks like the [[:plugin:bookmark|Bookmark]] plugin will serve my purpose.
 ==== Case sensitivity is not compatible with DW ==== ==== Case sensitivity is not compatible with DW ====
 While using anchor I found that you have to type the anchor_name in all lowercase letters to be compatible with the DW internal link mechanics, which converts the letters of a link to lowercase. While using anchor I found that you have to type the anchor_name in all lowercase letters to be compatible with the DW internal link mechanics, which converts the letters of a link to lowercase.
Line 108: Line 80:
 If I use this internal link, DW jumps to the top of the page.\\  If I use this internal link, DW jumps to the top of the page.\\ 
 Isn't it possible to jump to the part of the page, where the anchor is defined?<sub>//27.08.2013, Joe//</sub> Isn't it possible to jump to the part of the page, where the anchor is defined?<sub>//27.08.2013, Joe//</sub>
 +
 +Answer: It's possible that your DokuWiki template includes code that automatically scrolls to the top of the page after page load. You can confirm this by creating a link to a Doku section header and seeing if it behaves the same way.
  
 ==== /exe/fetch... ==== ==== /exe/fetch... ====
Line 123: Line 97:
 //ViForEver 20140207// //ViForEver 20140207//
  
 +==== Needs the colon even with no text ====
 +Note that even if you don't provide the optional text for the anchor you still need the colon following the anchor name, otherwise the plugin will error.
  
 +UPDATE: This has been fixed (2023-08-14)
  
-Hello, +Very handy little plugin! 
-in my private wiki __it does not work__. +//2023/06/30 jon p// 
-How i have to create an anchor and an anchor-goal? +
-Please give me an example!+
  
 ===== Old Discussion ===== ===== Old Discussion =====
plugin/anchor.1543329471.txt.gz · Last modified: 2018-11-27 15:37 by zioth

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