plugin:highlight
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:highlight [2013-10-24 00:55] – 194.50.240.42 | plugin:highlight [2024-02-12 21:14] (current) – louis-ouellet | ||
---|---|---|---|
Line 2: | Line 2: | ||
---- plugin ---- | ---- plugin ---- | ||
- | description: | + | description: |
- | author | + | author |
email : joe@nahmias.net | email : joe@nahmias.net | ||
type : syntax | type : syntax | ||
lastupdate : 2013-10-24 | lastupdate : 2013-10-24 | ||
- | compatible : Weatherwax | + | compatible : Ponder Stibbons, Binky, |
depends | depends | ||
conflicts | conflicts | ||
- | similar | + | similar |
- | tags : marking, highlight | + | tags : marking, highlight, !discontinued |
downloadurl: | downloadurl: | ||
+ | bugtracker: | ||
+ | sourcerepo: | ||
+ | |||
+ | screenshot_img: | ||
---- | ---- | ||
+ | FIXME: REPOSITORY NO LONGER EXIST | ||
- | ===== Recent changes ===== | ||
- | I've made security fix in function | + | ===== Installation ===== |
- | <code php> | + | Please use the [[plugin: |
- | // old code | + | |
- | function _isValid($c) { | + | |
- | $c = trim($c); | + | |
- | + | ||
- | $pattern = "/ | + | |
- | ([a-zA-z]+)| | + | |
- | (\#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}))| | + | |
- | (rgb\(([0-9]{1, | + | |
- | /x"; | + | |
- | + | ||
- | if (preg_match($pattern, | + | |
- | + | ||
- | return false; | + | |
- | } | + | |
- | | + | //Optional// |
- | | + | |
- | $c = trim($c); | + | ===== Usage ===== |
- | + | ||
- | $pattern | + | |
- | (^[a-zA-Z]+$)| | + | |
- | (^\# | + | |
- | (^rgb\(([0-9]{1, | + | |
- | /x"; | + | |
- | + | ||
- | return (preg_match($pattern, | + | |
- | + | ||
- | } | + | |
- | </code> | + | You could type or input via the toolbar button {{https:// |
+ | < | ||
+ | <hi cyan> | ||
+ | < | ||
+ | <hi # | ||
+ | </ | ||
+ | which looks as | ||
+ | {{: | ||
+ | In a highlight you cannot apply a second highlight: | ||
+ | < | ||
+ | <hi cyan> | ||
+ | --- doesn' | ||
+ | you <hi cyan> | ||
+ | </ | ||
+ | {{: | ||
- | ===== Background ===== | + | ==== Syntax |
- | + | ||
- | Although [[wikidesign@gmail.com|Esther Brunner]] already created a highlight | + | |
- | plugin, [[joe@nahmias.net|I]] felt it was limiting since it didn't allow the user to define | + | |
- | the color of the highlighting. | + | |
- | toolbar menu to choose from various predefined colors. | + | |
- | to add additional colors if you wish. | + | |
- | + | ||
- | You can try out this plugin on [[ncc@staddle.net|Neal]]' | + | |
- | + | ||
- | + | ||
- | + | ||
- | ===== Installation ===== | + | |
- | + | ||
- | - Install via [[plugin: | + | |
- | - Visit [[http:// | + | |
- | - Manual Installation | + | |
- | - Create a directory '' | + | |
- | - Place the PHP code below in a file called '' | + | |
- | - Place the JavaScript code below in a file called '' | + | |
- | - Create a file called '' | + | |
- | - // | + | |
- | - Enjoy! :-) | + | |
- | + | ||
- | + | ||
- | + | ||
- | ===== Syntax | + | |
You surround the text that you would like to highlight with the tags ''< | You surround the text that you would like to highlight with the tags ''< | ||
Line 99: | Line 66: | ||
- | ===== Example | + | ===== Development |
- | < | + | Although [[wikidesign@gmail.com|Esther Brunner]] already created a highlight |
- | <hi cyan> | + | plugin, [[joe@nahmias.net|I]] felt it was limiting since it didn't allow the user to define |
- | \\ | + | the color of the highlighting. |
- | < | + | toolbar menu to choose from various predefined colors. |
- | \\ | + | to add additional colors if you wish. |
- | <hi # | + | |
- | \\ | + | |
- | <hi cyan> | + | |
- | \\ | + | |
- | \\ | + | |
- | you <hi cyan> | + | |
- | </ | + | |
- | you <hi cyan> | + | You can try out this plugin on [[ncc@staddle.net|Neal]]' |
- | ===== Plugin ===== | ||
- | + | ==== Changelog ==== | |
- | ==== PHP ==== | + | |
- | + | ||
- | Put this code into '' | + | |
- | + | ||
- | <code php syntax.php> | + | |
- | <?php | + | |
- | /** | + | |
- | * Highlight Plugin: Allows user-defined colored highlighting | + | |
- | * | + | |
- | * @license | + | |
- | * @author | + | |
- | * @link | + | |
- | * @version | + | |
- | */ | + | |
- | + | ||
- | if(!defined(' | + | |
- | if(!defined(' | + | |
- | require_once(DOKU_PLUGIN.' | + | |
- | + | ||
- | /** | + | |
- | * All DokuWiki plugins to extend the parser/ | + | |
- | * need to inherit from this class | + | |
- | */ | + | |
- | class syntax_plugin_highlight extends DokuWiki_Syntax_Plugin { | + | |
- | + | ||
- | function getInfo(){ | + | |
- | return array( | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | | + | |
- | ' | + | |
- | ); | + | |
- | } | + | |
- | + | ||
- | // What kind of syntax are we? | + | |
- | function getType(){ return ' | + | |
- | + | ||
- | // What kind of syntax do we allow (optional) | + | |
- | function getAllowedTypes() { | + | |
- | return array(' | + | |
- | } | + | |
- | + | ||
- | // What about paragraphs? (optional) | + | |
- | | + | |
- | + | ||
- | // Where to sort in? | + | |
- | function getSort(){ return 90; } | + | |
- | + | ||
- | + | ||
- | // Connect pattern to lexer | + | |
- | function connectTo($mode) { | + | |
- | $this-> | + | |
- | } | + | |
- | function postConnect() { | + | |
- | $this-> | + | |
- | } | + | |
- | + | ||
- | + | ||
- | // Handle the match | + | |
- | function handle($match, | + | |
- | switch ($state) { | + | |
- | case DOKU_LEXER_ENTER : | + | |
- | preg_match("/ | + | |
- | if ( $this-> | + | |
- | break; | + | |
- | case DOKU_LEXER_MATCHED : | + | |
- | break; | + | |
- | case DOKU_LEXER_UNMATCHED : | + | |
- | return array($state, | + | |
- | break; | + | |
- | case DOKU_LEXER_EXIT : | + | |
- | break; | + | |
- | case DOKU_LEXER_SPECIAL : | + | |
- | break; | + | |
- | } | + | |
- | return array($state, | + | |
- | } | + | |
- | + | ||
- | // Create output | + | |
- | function render($mode, | + | |
- | if($mode == ' | + | |
- | list($state, | + | |
- | switch ($state) { | + | |
- | case DOKU_LEXER_ENTER : | + | |
- | $renderer-> | + | |
- | break; | + | |
- | case DOKU_LEXER_MATCHED : | + | |
- | break; | + | |
- | case DOKU_LEXER_UNMATCHED : | + | |
- | $renderer-> | + | |
- | break; | + | |
- | case DOKU_LEXER_EXIT : | + | |
- | $renderer-> | + | |
- | break; | + | |
- | case DOKU_LEXER_SPECIAL : | + | |
- | break; | + | |
- | } | + | |
- | return true; | + | |
- | } | + | |
- | return false; | + | |
- | } | + | |
- | + | ||
- | // validate color value $c | + | |
- | // this is cut price validation - only to ensure the basic format is | + | |
- | // correct and there is nothing harmful | + | |
- | // three basic formats | + | |
- | function _isValid($c) { | + | |
- | + | ||
- | $c = trim($c); | + | |
- | + | ||
- | $pattern = "/ | + | |
- | (^[a-zA-Z]+$)| | + | |
- | (^\# | + | |
- | (^rgb\(([0-9]{1, | + | |
- | /x"; | + | |
- | + | ||
- | return (preg_match($pattern, | + | |
- | + | ||
- | } | + | |
- | } | + | |
- | + | ||
- | //Setup VIM: ex: et ts=4 sw=4 enc=utf-8 : | + | |
- | </ | + | |
- | + | ||
- | ==== JavaScript ==== | + | |
- | + | ||
- | Put this code into '' | + | |
- | + | ||
- | <code javascript script.js> | + | |
- | /* JavaScript function to create highlight toolbar in DokuwKki */ | + | |
- | /* see http:// | + | |
- | + | ||
- | var plugin_highlight_colors = { | + | |
- | + | ||
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | "Sky Blue": | + | |
- | " | + | |
- | "Pale Green": | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | + | ||
- | }; | + | |
- | + | ||
- | function plugin_highlight_make_color_button(name, | + | |
- | + | ||
- | var btn = document.createElement(' | + | |
- | + | ||
- | btn.className = ' | + | |
- | btn.value = ' '; | + | |
- | btn.title = name; | + | |
- | btn.style.height = ' | + | |
- | btn.style.padding = ' | + | |
- | btn.style.backgroundColor = value; | + | |
- | + | ||
- | var open = "< | + | |
- | var close ="< | + | |
- | var sample = name + " Highlighted Text"; | + | |
- | btn.onclick = function(){ | + | |
- | insertTags(' | + | |
- | return false; }; | + | |
- | + | ||
- | return(btn); | + | |
- | + | ||
- | } | + | |
- | + | ||
- | function plugin_highlight_toolbar_picker() { | + | |
- | + | ||
- | var toolbar = document.getElementById(' | + | |
- | if (!toolbar) return; | + | |
- | + | ||
- | // Create the picker button | + | |
- | var p_id = ' | + | |
- | var p_ico = document.createElement(' | + | |
- | p_ico.src = DOKU_BASE + ' | + | |
- | var p_btn = document.createElement(' | + | |
- | p_btn.className = ' | + | |
- | p_btn.title = ' | + | |
- | p_btn.appendChild(p_ico); | + | |
- | p_btn.onclick = function() { | + | |
- | showPicker(p_id, | + | |
- | + | ||
- | // Create the picker < | + | |
- | var picker = document.createElement(' | + | |
- | picker.className = ' | + | |
- | picker.id = p_id; | + | |
- | picker.style.position = ' | + | |
- | picker.style.display = ' | + | |
- | + | ||
- | // Add a button to the picker <div> for each of the colors | + | |
- | for( var color in plugin_highlight_colors ) { | + | |
- | var btn = plugin_highlight_make_color_button(color, | + | |
- | plugin_highlight_colors[color]); | + | |
- | picker.appendChild(btn); | + | |
- | } | + | |
- | if (typeof user_highlight_colors != ' | + | |
- | for( var color in user_highlight_colors ) { | + | |
- | var btn = plugin_highlight_make_color_button(color, | + | |
- | user_highlight_colors[color]); | + | |
- | picker.appendChild(btn); | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | var body = document.getElementsByTagName(' | + | |
- | body.appendChild(picker); | + | |
- | toolbar.appendChild(p_btn); | + | |
- | } | + | |
- | addInitEvent(plugin_highlight_toolbar_picker); | + | |
- | + | ||
- | //Setup VIM: ex: et ts=2 sw=2 enc=utf-8 : | + | |
- | </ | + | |
- | + | ||
- | ==== Additional Colors | + | |
- | + | ||
- | To add more colors to the toolbar picker, add the following code to the | + | |
- | '' | + | |
- | + | ||
- | <code javascript> | + | |
- | // Additional user-defined highlighting colors | + | |
- | var user_highlight_colors = { | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | "Sandy Brown": | + | |
- | "Steel Blue": | + | |
- | " | + | |
- | " | + | |
- | "Dark Violet": | + | |
- | " | + | |
- | }; | + | |
- | </ | + | |
- | + | ||
- | For additional colors (with names) check out the page at: [[http:// | + | |
- | + | ||
- | + | ||
- | ===== Changelog | + | |
* Version 3.1: Fix bug in IE when no user-defined colors exists; thanks [[ncc@staddle.net|Neal]]! | * Version 3.1: Fix bug in IE when no user-defined colors exists; thanks [[ncc@staddle.net|Neal]]! | ||
Line 378: | Line 87: | ||
- | ===== TODO ===== | + | ===== Additional Colors |
- | + | ||
- | * < | + | |
- | * Done?! :-) | + | |
- | + | ||
- | + | ||
- | ===== Bugs ===== | + | |
- | + | ||
- | * You can't nest highlights (anyone know how to fix this? --- I thought making the second glob greedy would help, but it doesn' | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | ===== Discussion ===== | + | |
- | + | ||
- | * __NOTE__: Please [[joe+dokuwiki@nahmias.net|email me]] if you change the page; for some reason I can't subscribe to changes... | + | |
- | * I have modified your plugin to change only the colour of the font (not the background). I didn't want to use inline HTML because it conflicts with many other plugins (notes, styler, draw, etc.). | + | |
- | * Here's the modified **plugins/ | + | |
- | <code php> | + | |
- | <?php | + | |
- | /** | + | |
- | * Highlight Plugin: Allows user-defined colored highlighting | + | |
- | * | + | |
- | * @license | + | |
- | * @author | + | |
- | */ | + | |
- | + | ||
- | if(!defined(' | + | |
- | if(!defined(' | + | |
- | require_once(DOKU_PLUGIN.' | + | |
- | + | ||
- | /** | + | |
- | * All DokuWiki plugins to extend the parser/ | + | |
- | * need to inherit from this class | + | |
- | */ | + | |
- | class syntax_plugin_colour extends DokuWiki_Syntax_Plugin { | + | |
- | + | ||
- | /** | + | |
- | * return some info | + | |
- | */ | + | |
- | function getInfo(){ | + | |
- | return array( | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ); | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * What kind of syntax are we? | + | |
- | */ | + | |
- | function getType(){ | + | |
- | return ' | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * What kind of syntax do we allow (optional) | + | |
- | */ | + | |
- | function getAllowedTypes() { | + | |
- | return array(' | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * What about paragraphs? (optional) | + | |
- | */ | + | |
- | | + | |
- | | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * Where to sort in? | + | |
- | */ | + | |
- | function getSort(){ | + | |
- | return 90; | + | |
- | } | + | |
- | + | ||
- | + | ||
- | /** | + | |
- | * Connect pattern to lexer | + | |
- | */ | + | |
- | function connectTo($mode) { | + | |
- | $this-> | + | |
- | } | + | |
- | + | ||
- | function postConnect() { | + | |
- | $this-> | + | |
- | } | + | |
- | + | ||
- | + | ||
- | /** | + | |
- | * Handle the match | + | |
- | */ | + | |
- | function handle($match, | + | |
- | switch ($state) { | + | |
- | case DOKU_LEXER_ENTER : | + | |
- | preg_match("/ | + | |
- | if ( $this-> | + | |
- | break; | + | |
- | case DOKU_LEXER_MATCHED : | + | |
- | break; | + | |
- | case DOKU_LEXER_UNMATCHED : | + | |
- | return array($state, | + | |
- | break; | + | |
- | case DOKU_LEXER_EXIT : | + | |
- | break; | + | |
- | case DOKU_LEXER_SPECIAL : | + | |
- | break; | + | |
- | } | + | |
- | return array($state, | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * Create output | + | |
- | */ | + | |
- | function render($mode, | + | |
- | if($mode == ' | + | |
- | list($state, | + | |
- | switch ($state) { | + | |
- | case DOKU_LEXER_ENTER : | + | |
- | $renderer-> | + | |
- | break; | + | |
- | case DOKU_LEXER_MATCHED : | + | |
- | break; | + | |
- | case DOKU_LEXER_UNMATCHED : | + | |
- | $renderer-> | + | |
- | break; | + | |
- | case DOKU_LEXER_EXIT : | + | |
- | $renderer-> | + | |
- | break; | + | |
- | case DOKU_LEXER_SPECIAL : | + | |
- | break; | + | |
- | } | + | |
- | return true; | + | |
- | } | + | |
- | return false; | + | |
- | } | + | |
- | + | ||
- | // validate color value $c | + | |
- | // this is cut price validation - only to ensure the basic format is | + | |
- | // correct and there is nothing harmful | + | |
- | // three basic formats | + | |
- | function _isValid($c) { | + | |
- | $c = trim($c); | + | |
- | + | ||
- | $pattern = "/ | + | |
- | ([a-zA-z]+)| | + | |
- | (\# | + | |
- | (rgb\(([0-9]{1, | + | |
- | /x"; | + | |
- | + | ||
- | if (preg_match($pattern, | + | |
- | + | ||
- | return false; | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | //Setup VIM: ex: et ts=4 enc=utf-8 : | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | + | ||
- | ...and I have updated the script.js file to correspond | + | |
- | * Here's the modified **plugins/ | + | |
- | <code php> | + | |
- | + | ||
- | /* javascript function to create colour toolbar in dokuwiki */ | + | |
- | /* see http:// | + | |
- | + | ||
- | var plugin_colour_colors = { | + | |
- | + | ||
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | "Sky Blue": | + | |
- | " | + | |
- | "Pale Green": | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | + | ||
- | }; | + | |
- | + | ||
- | function plugin_colour_make_color_button(name, | + | |
- | + | ||
- | var btn = document.createElement(' | + | |
- | + | ||
- | btn.className = ' | + | |
- | btn.value = ' '; | + | |
- | btn.title = name; | + | |
- | btn.style.height = ' | + | |
- | btn.style.padding = ' | + | |
- | btn.style.backgroundColor = value; | + | |
- | + | ||
- | var open = "< | + | |
- | var close ="< | + | |
- | var sample = name + " Colour Text"; | + | |
- | btn.onclick = function(){ | + | |
- | insertTags(' | + | |
- | return false; }; | + | |
- | + | ||
- | return(btn); | + | |
- | + | ||
- | } | + | |
- | + | ||
- | function plugin_colour_toolbar_picker() { | + | |
- | + | ||
- | // Check that we are editing the page - is there a better way to do this? | + | |
- | var edbtn = document.getElementById(' | + | |
- | if (!edbtn) return; | + | |
- | + | ||
- | var toolbar = document.getElementById(' | + | |
- | if (!toolbar) return; | + | |
- | + | ||
- | // Create the picker button | + | |
- | var p_id = ' | + | |
- | var p_ico = document.createElement(' | + | |
- | p_ico.src = DOKU_BASE + ' | + | |
- | var p_btn = document.createElement(' | + | |
- | p_btn.className = ' | + | |
- | p_btn.title = ' | + | |
- | p_btn.appendChild(p_ico); | + | |
- | p_btn.onclick = function() { | + | |
- | showPicker(p_id, | + | |
- | + | ||
- | // Create the picker < | + | |
- | var picker = document.createElement(' | + | |
- | picker.className = ' | + | |
- | picker.id = p_id; | + | |
- | picker.style.position = ' | + | |
- | picker.style.display = ' | + | |
- | + | ||
- | // Add a button to the picker <div> for each of the colors | + | |
- | for( var color in plugin_colour_colors ) { | + | |
- | var btn = plugin_colour_make_color_button(color, | + | |
- | plugin_colour_colors[color]); | + | |
- | picker.appendChild(btn); | + | |
- | } | + | |
- | if (typeof user_colour_colors != ' | + | |
- | for( var color in user_colour_colors ) { | + | |
- | var btn = plugin_colour_make_color_button(color, | + | |
- | user_colour_colors[color]); | + | |
- | picker.appendChild(btn); | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | var body = document.getElementsByTagName(' | + | |
- | body.appendChild(picker); | + | |
- | toolbar.appendChild(p_btn); | + | |
- | } | + | |
- | addInitEvent(plugin_colour_toolbar_picker); | + | |
- | + | ||
- | //Setup VIM: ex: et ts=2 sw=2 enc=utf-8 : | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | ...and, finally the colour_toolbar_icon.png : (oops, can't upload the file) | + | |
- | + | ||
- | + | ||
- | === Toolbar button missing === | + | |
- | + | ||
- | Any tips on making the toolbar button show up? Everything works, except the button isn't there. Thanks. -Richard | + | |
- | Jupp, I'm having the same problem here ... any help welcome! | + | |
- | - Kristine | + | |
- | + | ||
- | Changing script.js line 60 | + | |
- | **from: | + | |
- | **to: | + | |
- | + | ||
- | And placing the image inside the images folder solved the problem. | + | |
- | + | ||
- | The icon for highlighting shows in the page source when not logged in to the wiki. | + | |
- | ADD \\ if (!document.getElementById(' | + | |
- | \\ below | + | |
- | function plugin_highlight_toolbar_picker() { | + | |
- | + | ||
- | + | ||
- | **Toolbar button isn't added to the toolbar.... ** | + | |
- | + | ||
- | ==== Adding button to toolbar ==== | + | |
- | + | ||
- | Does anybody know which changes need to be made in order to have the button displayed in the toolbar? | + | |
- | + | ||
- | ==== Adding button to toolbar | + | |
- | + | ||
- | button image is accessible but the button is not added at all at the toolbar. | + | |
- | ==== Toolbar button still missing ==== | + | To add more colors to the toolbar picker, add a duplicate of some blocks of '' |
- | Bump! Has anybody out there been able to fix the missing toolbar button? Since I've updated to DokuWiki 2009-12-25c the button is gone (the generated HTML isn't even showing the JavaScript to insert the button, so that's not a browser problem). | + | Some examples of additional user-defined highlighting colors |
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * "Sandy Brown": | ||
+ | * "Steel Blue": | ||
+ | * " | ||
+ | * " | ||
+ | * "Dark Violet": | ||
+ | * " | ||
- | === Bugfix for missing toolbar icon === | + | For more additional colors (with names) check out the page at: [[http:// |
- | Yup, after quite a lot of debugging and finally digging into the code, it's obvious that the toolbar has changed quite a bit in recent versions. After rewriting the init function like below, everything works fine in DokuWiki 2010-11-07 (" | ||
- | (code removed, as it breaks rendering you can find a copy in the page history, if you need a fix now.) | ||
- | ==== Adding button to toolbar ==== | ||
- | I've added support for Weatherwax toolbar and made some new icons. The JavaScript code isn't very " | ||
plugin/highlight.1382568933.txt.gz · Last modified: 2013-10-24 00:55 by 194.50.240.42