plugin:term
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:term [2006-03-02 16:09] – 139.149.1.211 | plugin:term [2018-06-06 00:09] (current) – Klap-in | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Term Highlighter Plugin ====== | ||
+ | ---- plugin ---- | ||
+ | description: | ||
+ | author | ||
+ | email : pavel.vitis@seznam.cz | ||
+ | type : syntax | ||
+ | lastupdate : 2005-08-17 | ||
+ | compatible : | ||
+ | depends | ||
+ | conflicts | ||
+ | similar | ||
+ | tags : definitions, | ||
+ | ---- | ||
+ | |||
+ | This plugin allows definition of term which is then highlighted using ''< | ||
+ | |||
+ | |||
+ | ===== Syntax ===== | ||
+ | |||
+ | DokuWiki Syntax: | ||
+ | <term Title> | ||
+ | |||
+ | Example: | ||
+ | <term Apple> | ||
+ | |||
+ | will highlight all occurrences of word Apple as acronym with 'Sort of fruit' description. | ||
+ | \\ | ||
+ | This is useful whenever you write a big article and you wish to have some term highlighted across the document and you either don't have access to dokuwiki configuration files or simply don't want to clutter the config with terms used only locally. | ||
+ | \\ | ||
+ | ---- | ||
+ | You can see a working example on < | ||
+ | \\ | ||
+ | [[pavel.vitis@seznam.cz|Pavel Vitis]] | ||
+ | |||
+ | ===== Notes ===== | ||
+ | * Title parameter is not case sensitive. ' | ||
+ | * Acronym tags defined inside '' | ||
+ | * This plugin needs support for subfolders inside plugin folder. It was introduced in DokuWiki on august 2, 2005. So it will not work in older releases. It is possible to make it working in older version by splitting plugin into two plugins. | ||
+ | |||
+ | ===== Plugin ===== | ||
+ | |||
+ | ==== Step 1: Check requirements === | ||
+ | |||
+ | This plugin needs DokuWiki 2005-08-02 or later. You can check this by viewing the source of one of your DokuWiki pages: it contains a header with the DokuWiki version. Example: | ||
+ | < | ||
+ | <meta name=" | ||
+ | </ | ||
+ | |||
+ | If you have an older version, you can either upgrade DokuWiki or split this plugin into two parts. To split this plugin in two parts, please replace these file locations in the following steps:\\ | ||
+ | ''/ | ||
+ | ''/ | ||
+ | ''/ | ||
+ | |||
+ | ==== Step 2: The dokuwiki plugin Termadd ==== | ||
+ | |||
+ | This is the term registering plugin, which parses ''< | ||
+ | To install, put the following PHP file into ''/ | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | /** | ||
+ | * Allows definition of term which is then highlighted using < | ||
+ | * Example: | ||
+ | * <term Title> | ||
+ | * All occurrences of ' | ||
+ | * Title parameter is not case sensitive. | ||
+ | * TODO: Acronym tags defined inside acronyms.conf or acronyms.local.conf cannot be overridden. | ||
+ | * Termadd is term registering plugin, Termshow is needed to display terms | ||
+ | * | ||
+ | * @license | ||
+ | * @author | ||
+ | */ | ||
+ | |||
+ | if (!defined(' | ||
+ | define(' | ||
+ | } | ||
+ | if (!defined(' | ||
+ | define(' | ||
+ | } | ||
+ | require_once(DOKU_PLUGIN.' | ||
+ | |||
+ | global $terms; | ||
+ | if (!isset($terms)) { | ||
+ | $terms = array(); | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * All DokuWiki plugins to extend the parser/ | ||
+ | * need to inherit from this class | ||
+ | */ | ||
+ | class syntax_plugin_term_add extends DokuWiki_Syntax_Plugin { | ||
+ | |||
+ | /** | ||
+ | * return some info | ||
+ | */ | ||
+ | function getInfo(){ | ||
+ | return array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ); | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * What kind of syntax are we? | ||
+ | */ | ||
+ | function getType(){ | ||
+ | return ' | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Paragraph Type | ||
+ | * | ||
+ | * Defines how this syntax is handled regarding paragraphs. This is important | ||
+ | * for correct XHTML nesting. Should return one of the following: | ||
+ | * | ||
+ | * ' | ||
+ | * ' | ||
+ | * ' | ||
+ | * | ||
+ | * @see Doku_Handler_Block | ||
+ | */ | ||
+ | function getPType() { | ||
+ | return ' | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Where to sort in? | ||
+ | */ | ||
+ | function getSort() { | ||
+ | // Somewhere on the beginning | ||
+ | return 09; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Connect pattern to lexer | ||
+ | */ | ||
+ | function connectTo($mode) { | ||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | function postConnect() { | ||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Handle the match | ||
+ | */ | ||
+ | function handle($match, | ||
+ | switch ($state) { | ||
+ | case DOKU_LEXER_UNMATCHED: | ||
+ | $parts = explode('>', | ||
+ | $this-> | ||
+ | return array($match, | ||
+ | break; | ||
+ | default: | ||
+ | return array($match, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Create output | ||
+ | */ | ||
+ | function render($mode, | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | function _replaceTerm($def, | ||
+ | global $terms; | ||
+ | $terms[strtoupper($def)] = $desc; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | //Setup VIM: ex: et ts=4 enc=utf-8 : | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Step 3: The DokuWiki plugin Termshow ==== | ||
+ | |||
+ | This is the term rendering plugin that will recognize words and highlight them if found in list of terms. | ||
+ | To install, put the following PHP file into ''/ | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | /** | ||
+ | * Allows definition of term which is then highlighted using < | ||
+ | * Example: | ||
+ | * <term Title> | ||
+ | * All occurrences of ' | ||
+ | * Title parameter is not case sensitive. | ||
+ | * TODO: Acronym tags defined inside acronyms.conf or acronyms.local.conf cannot be overridden. | ||
+ | * Termshow is term displaying plugin, Termadd is needed to register term first | ||
+ | * | ||
+ | * @license | ||
+ | * @author | ||
+ | */ | ||
+ | |||
+ | if (!defined(' | ||
+ | define(' | ||
+ | } | ||
+ | if (!defined(' | ||
+ | define(' | ||
+ | } | ||
+ | require_once(DOKU_PLUGIN.' | ||
+ | |||
+ | global $terms; | ||
+ | if (!isset($terms)) { | ||
+ | $terms = array(); | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * All DokuWiki plugins to extend the parser/ | ||
+ | * need to inherit from this class | ||
+ | */ | ||
+ | class syntax_plugin_term_show extends DokuWiki_Syntax_Plugin { | ||
+ | |||
+ | /** | ||
+ | * return some info | ||
+ | */ | ||
+ | function getInfo(){ | ||
+ | return array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ); | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * What kind of syntax are we? | ||
+ | */ | ||
+ | function getType(){ | ||
+ | return ' | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Paragraph Type | ||
+ | * | ||
+ | * Defines how this syntax is handled regarding paragraphs. This is important | ||
+ | * for correct XHTML nesting. Should return one of the following: | ||
+ | * | ||
+ | * ' | ||
+ | * ' | ||
+ | * ' | ||
+ | * | ||
+ | * @see Doku_Handler_Block | ||
+ | */ | ||
+ | function getPType() { | ||
+ | return ' | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Where to sort in? | ||
+ | */ | ||
+ | function getSort() { | ||
+ | // This should be larger than acronym sort, otherwise it conflicts with it | ||
+ | return 500; | ||
+ | } | ||
+ | |||
+ | function connectTo($mode) { | ||
+ | | ||
+ | } | ||
+ | | ||
+ | /** | ||
+ | * Handle the match | ||
+ | */ | ||
+ | function handle($match, | ||
+ | | ||
+ | // save some useless processing | ||
+ | if (count($terms) > 0) { | ||
+ | $word = $match; | ||
+ | // save some useless processing, do not allow words shorter than 2 characters | ||
+ | if ($word != '' | ||
+ | $word = strtoupper($word); | ||
+ | if (array_key_exists($word, | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Create output | ||
+ | */ | ||
+ | function render($mode, | ||
+ | global $terms; | ||
+ | if($mode == ' | ||
+ | if (!empty($data[2])) { | ||
+ | $renderer-> | ||
+ | } | ||
+ | else { | ||
+ | $renderer-> | ||
+ | } | ||
+ | return true; | ||
+ | } | ||
+ | return false; | ||
+ | } | ||
+ | | ||
+ | function _renderTerm(& | ||
+ | return '< | ||
+ | } | ||
+ | } | ||
+ | |||
+ | //Setup VIM: ex: et ts=4 enc=utf-8 : | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | ==== Step 4: Stylesheet ==== | ||
+ | |||
+ | To install stylesheet, put the following CSS text into ''/ | ||
+ | |||
+ | <code css> | ||
+ | acronym.term { | ||
+ | border-bottom: | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | You can customize this to totally differentiate terms from acronyms, for example using yellow background etc. | ||
+ | |||
+ | ===== Bugs ===== | ||
+ | |||
+ | Don't work with Russian language, please, make it | ||
+ | ===== Todo ===== | ||
+ | |||
+ | * Solve conflict with internal acronym parsing, so we can override configured acronym with our own term. | ||
+ | * Make some optimization so not every word in page gets passed to '' | ||
+ | |||
+ | |||
+ | |||
+ | ===== Discussion ===== | ||
+ | |||
+ | > Why don't you combine those two plugins in one folder, like: | ||
+ | > < | ||
+ | / | ||
+ | syntax/ | ||
+ | add.php | ||
+ | show.php | ||
+ | style.css | ||
+ | </ | ||
+ | > The functions would then have to be called '' | ||
+ | > | ||
+ | >> Well, good idea. Updated. --- // | ||
+ | >>> | ||
+ | |||
+ | ---- | ||
+ | |||
+ | I'm trying the plugin with the latest dev sources, but it appears that termshow breaks underlines...? | ||
+ | > I confirm, with the latest 2007-06-26b DokuWiki release, the underline is broken. | ||
+ | > If you replace, in the connectTo() function of show.php, the regexp ' | ||
+ | > I took the liberty to update the show.php listing, located above this section. --- [[daniel.chaffiol@sgcib.com|dc]] 2007/08/22 | ||
+ | |||
+ | ---- | ||
+ | Hi, on DokuWiki Release 2006-03-09 i have problem with installation, | ||
+ | >same here with me. I tried <term lol> | ||
+ | >> |