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 [2017-06-20 09:54] – Changed signature of methods "handle'' and ''render'' to suppress warnings in PHP 7.1 85.132.140.57plugin: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 stibbonshrundetritusfrusterick+compatible : 2010-11-07, 2011-05-25, AnguaWeatherwaxBinkyPonder StibbonsHrunDetritusFrusterick 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:  +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: 
 ---- ----
  
-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 simple, so 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.
  
-<code php lib/plugins/anchor/syntax.php> 
-<?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';  // Alternatively: return 'normal'; if you don't want new paragraph. 
-    function getSort() {return 167;} 
-    function getInfo() {return array('author' => 'Eli Fenton', 'name' => 'Anchor Plugin', 'url' => 'http://dokuwiki.org/plugin:anchor');} 
-    function connectTo($mode){ 
-        $this->Lexer->addSpecialPattern('\{\{anchor:[^}]*\}\}', $mode, 'plugin_anchor'); 
-    } 
- 
-    function handle($match, $state, $pos, Doku_Handler $handler) { 
-        return explode(':', substr($match, strlen('{{anchor:'), -2)); 
-    } 
-  
-    function render($mode, Doku_Renderer $renderer, $data) { 
-        $renderer->doc .= '<a name="' .htmlspecialchars($data[0]) . '">' .htmlspecialchars($data[1]) . '</a>'; 
-    } 
-} 
-?> 
-</code> 
  
 ===== Examples/Usage ===== ===== Examples/Usage =====
  
-Here's how you create an anchor:+This syntax creates an anchor. Put it anywhere in your page, and links will automatically scroll to that point.
  
 <code> <code>
Line 62: Line 37:
 </code> </code>
  
-The anchor_name part is the name of the anchor to use in linksThe text part is optional, and, for the most part, not very useful. It lets you wrap the anchor around a specific piece of text.+**anchor_name** is an arbitrary name of your choosingIt must begin with a letter, and must be lowercase. 
 + 
 +**text**if providedis 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: 
 + 
 +<code> 
 +{{anchor:anchor_name}} 
 +</code>
  
 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 75: Line 58:
 http://server.com/doku/doku.php?id=page_name#anchor_name http://server.com/doku/doku.php?id=page_name#anchor_name
 </code> </code>
- 
  
 ==== Changelog ==== ==== Changelog ====
-  * 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.+  * 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.
  
 ===== 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.
 To enable copy&paste of anchor names from other text-parts, it would be more convenient if the plugin did that itself. To enable copy&paste of anchor names from other text-parts, it would be more convenient if the plugin did that itself.
- 
-==== Avoiding that Extension Managers erroneously thinks there is an update for this plugin ==== 
-If you install the plugin from the source code given above, the Extension Manager of Dokuwiki (I'm using release 2014-05-05 "Ponder Stibbons") erroneously thinks that there is an update of the plugin available. The reason is that the plugin code does not provide a version data for comparison. 
- 
-You can fix this by installing the following file in the ''lib/plugins/anchor'' directory: 
- 
-<file txt plugin.info.txt>     
-base  anchor 
-author Eli Fenton 
-date  2013-05-23 
-name  Anchor Plugin 
-url http://dokuwiki.org/plugin:anchor 
-</file> 
- 
-==== Compatible with "Frusterick Manners" ==== 
-IMO: Works fine with Release 2017-02-19 "Frusterick Manners"\\ 
-//Sig// 
- 
-==== Compatible with "Anteater" ==== 
-In my opinion, it works fine with ''Anteater'' :-) \\ 
-//AlekS// 
- 
-==== Compatible with "Angua" ==== 
-Works also with "Angua"  --- [[user>aleks|aleks]] //2012/01/10 09:48// 
- 
-==== Compatible with "Elenor Of Tsort" ==== 
-Works fine with 2016-06-26 "Elenor Of Tsort"  --- [[user>Mr. Magpie|Mr. Magpie]] //2016/09/14// 
  
 ==== Jumps to top of the page ==== ==== Jumps to top of the page ====
Line 118: 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 133: 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)
 +
 +Very handy little plugin!
 +//2023/06/30 jon p// 
  
-Hello, 
-in my private wiki __it does not work__. 
-How i have to create an anchor and an anchor-goal? 
-Please give me an example! 
 ===== Old Discussion ===== ===== Old Discussion =====
 +
 [[plugin:anchor:olddiscussion]] [[plugin:anchor:olddiscussion]]
  
plugin/anchor.1497945298.txt.gz · Last modified: 2017-06-20 09:54 by 85.132.140.57

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