plugin:boxes_mod
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:boxes_mod [2008-12-30 14:12] – 90.185.122.55 | plugin:boxes_mod [2018-05-25 19:53] (current) – old revision restored (2011-12-04 17:17) Aleksandr | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Modified Boxes Plugin ====== | ||
+ | ---- plugin ---- | ||
+ | description: | ||
+ | author | ||
+ | email : robert.meerman@gmail.com | ||
+ | type : syntax | ||
+ | lastupdate : 2005-10-25 | ||
+ | compatible : | ||
+ | depends | ||
+ | conflicts | ||
+ | similar | ||
+ | tags : boxes | ||
+ | ---- | ||
+ | |||
+ | //This page is a child of [[: | ||
+ | |||
+ | |||
+ | |||
+ | ===== Changes ===== | ||
+ | |||
+ | - Syntax changed: **%%<<< | ||
+ | - Markup allows in captions | ||
+ | - Title and Caption may be multiple lines now (i.e. multiple paragraphs) | ||
+ | - Width may be specified in %, px, em or ex | ||
+ | |||
+ | Why might you want this? If you can specify the width in px, you can use boxes to caption images seamlessly (by making the box the same width as the image) regardless of the browser width. Being able to place markup in the caption is nice for when you want to draw attention to a note about, say, an alternative version of some software — it looks really nice having the download link in the caption. | ||
+ | |||
+ | ===== syntax.php ===== | ||
+ | |||
+ | <file php syntax.php> | ||
+ | <?php | ||
+ | /** | ||
+ | * Box Plugin: Draw highlighting boxes around wiki markup | ||
+ | * | ||
+ | * Syntax: | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | * | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | * | ||
+ | * Acknowledgments: | ||
+ | | ||
+ | | ||
+ | | ||
+ | * @license | ||
+ | * @author | ||
+ | * @modified | ||
+ | */ | ||
+ | |||
+ | if(!defined(' | ||
+ | if(!defined(' | ||
+ | require_once(DOKU_PLUGIN.' | ||
+ | |||
+ | /** | ||
+ | * All DokuWiki plugins to extend the parser/ | ||
+ | * need to inherit from this class | ||
+ | */ | ||
+ | class syntax_plugin_box extends DokuWiki_Syntax_Plugin { | ||
+ | |||
+ | var $title_mode = false; | ||
+ | var $caption_mode = false; | ||
+ | |||
+ | /** | ||
+ | * return some info | ||
+ | */ | ||
+ | function getInfo(){ | ||
+ | return array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | | ||
+ | <<< | ||
+ | or <<< | ||
+ | or <<< | ||
+ | or <<< | ||
+ | or combination of above. | ||
+ | | ||
+ | ' | ||
+ | ); | ||
+ | } | ||
+ | |||
+ | function getType(){ return ' | ||
+ | function getAllowedTypes() { return array(' | ||
+ | function getPType(){ return ' | ||
+ | | ||
+ | // must return a number lower than returned by native ' | ||
+ | function getSort(){ return 195; } | ||
+ | |||
+ | /** | ||
+ | * Connect pattern to lexer | ||
+ | * | ||
+ | * Avoid matching the title (if present) so its markup can be parsed normally | ||
+ | */ | ||
+ | function connectTo($mode) { | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | } | ||
+ | | ||
+ | function postConnect() { | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Handle the match | ||
+ | */ | ||
+ | function handle($match, | ||
+ | |||
+ | switch ($state) { | ||
+ | // addEntryPattern matched | ||
+ | case DOKU_LEXER_ENTER: | ||
+ | // Expect either plain "<<<" | ||
+ | $data = $this-> | ||
+ | if (substr($match, | ||
+ | $this-> | ||
+ | return array(' | ||
+ | } else { | ||
+ | return array(' | ||
+ | } | ||
+ | | ||
+ | // addPattern matched | ||
+ | case DOKU_LEXER_MATCHED: | ||
+ | if ($this-> | ||
+ | // End title mode and open content box | ||
+ | $this-> | ||
+ | return array(' | ||
+ | } else { | ||
+ | // begin caption mode and open caption | ||
+ | $this-> | ||
+ | return array(' | ||
+ | } | ||
+ | | ||
+ | case DOKU_LEXER_UNMATCHED: | ||
+ | return array(' | ||
+ | | ||
+ | // addExitPattern matched | ||
+ | case DOKU_LEXER_EXIT: | ||
+ | return array(' | ||
+ | | ||
+ | } | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Create output | ||
+ | */ | ||
+ | function render($mode, | ||
+ | | ||
+ | list($instr, | ||
+ | |||
+ | if($mode == ' | ||
+ | switch ($instr) { | ||
+ | case ' | ||
+ | $this-> | ||
+ | $renderer-> | ||
+ | break; | ||
+ | | ||
+ | case ' | ||
+ | if ($this-> | ||
+ | $this-> | ||
+ | $renderer-> | ||
+ | } else { | ||
+ | $renderer-> | ||
+ | } | ||
+ | break; | ||
+ | | ||
+ | case ' | ||
+ | $renderer-> | ||
+ | break; | ||
+ | | ||
+ | case ' | ||
+ | $this-> | ||
+ | | ||
+ | $renderer-> | ||
+ | $renderer-> | ||
+ | break; | ||
+ | |||
+ | case ' | ||
+ | if($this-> | ||
+ | // Close caption div | ||
+ | $renderer-> | ||
+ | } else { | ||
+ | // Close content div | ||
+ | $renderer-> | ||
+ | } | ||
+ | | ||
+ | $renderer-> | ||
+ | break; | ||
+ | } | ||
+ | | ||
+ | return true; | ||
+ | } | ||
+ | return false; | ||
+ | } | ||
+ | | ||
+ | function _boxstyle($str) { | ||
+ | if (!strlen($str)) return array(); | ||
+ | | ||
+ | $styles = array(); | ||
+ | | ||
+ | $tokens = preg_split('/ | ||
+ | foreach ($tokens as $token) { | ||
+ | if (preg_match('/ | ||
+ | $styles[' | ||
+ | continue; | ||
+ | } | ||
+ | | ||
+ | $styles[' | ||
+ | } | ||
+ | | ||
+ | return $styles; | ||
+ | } | ||
+ | | ||
+ | function _xhtml_boxopen($style) { | ||
+ | $class = " | ||
+ | $style = isset($style[' | ||
+ | |||
+ | $html = "< | ||
+ | $html .=" | ||
+ | $html .=" | ||
+ | | ||
+ | return $html; | ||
+ | } | ||
+ | | ||
+ | function _xhtml_boxclose() { | ||
+ | | ||
+ | $html = " | ||
+ | $html .= " | ||
+ | $html .= "</ | ||
+ | | ||
+ | return $html; | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | //Setup VIM: ex: et ts=4 enc=utf-8 : | ||
+ | </ | ||
+ | |||
+ | ===== style.css ===== | ||
+ | |||
+ | Not much was changed: Two conversion took place and an additional rule was added: | ||
+ | |||
+ | ==== Title / Caption ==== | ||
+ | This was done to allow multi-line markup within both, giving you greater flexibility. | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ==== Additional Rule ==== | ||
+ | The following rule was added to ensure all immediate child paragraphs of the title and caption did not gaps caused by '' | ||
+ | |||
+ | <code css> | ||
+ | div.box div.box_title > p, div.box div.box_caption > p{ | ||
+ | margin: 0; | ||
+ | padding: 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Complete stylesheet ==== | ||
+ | Should you wish to download the complete stylesheet, here it is. | ||
+ | |||
+ | <file css style.css> | ||
+ | /* plugin:box */ | ||
+ | div.box { | ||
+ | width: 50%; | ||
+ | margin: 1em auto; | ||
+ | border: 1px solid; | ||
+ | padding: 4px; | ||
+ | } | ||
+ | |||
+ | /* rounded corners styles from Stu Nicholls snazzy borders, http:// | ||
+ | .xtop, .xbottom {background: | ||
+ | .xb1, .xb2, .xb3, .xb4 {display: | ||
+ | .xb2, .xb3 {height: | ||
+ | .xb2, .xb3, .xb4 {border-width: | ||
+ | .xb1 {height: 0; margin:0 5px; border-width: | ||
+ | .xb2 {margin:0 3px; border-width: | ||
+ | .xb3 {margin:0 2px;} | ||
+ | .xb4 {height: | ||
+ | |||
+ | div.box .xtop, div.box .xbottom {display: none;} | ||
+ | div.box.round .xtop, div.box.round .xbottom {display: block;} | ||
+ | |||
+ | div.box.round { border: none; padding: 0;} | ||
+ | div.box.round .xbox {display: | ||
+ | |||
+ | div.box div.box_title, | ||
+ | font-size: 90%; | ||
+ | margin: 0; | ||
+ | padding: 2px 6px; | ||
+ | line-height: | ||
+ | } | ||
+ | div.box div.box_title > p, div.box div.box_caption > p{ | ||
+ | margin: 0; | ||
+ | padding: 0; | ||
+ | } | ||
+ | |||
+ | |||
+ | div.box div.box_title { margin-bottom: | ||
+ | div.box div.box_caption { margin-top: 4px;} | ||
+ | |||
+ | div.box .box_content { | ||
+ | margin: 0; | ||
+ | padding: 0 6px; | ||
+ | border-width: | ||
+ | border-style: | ||
+ | line-height: | ||
+ | } | ||
+ | |||
+ | /* floating alignment */ | ||
+ | |||
+ | div.box.left { | ||
+ | float: left; | ||
+ | margin-right: | ||
+ | } | ||
+ | |||
+ | div.box.right { | ||
+ | float: right; | ||
+ | margin-left: | ||
+ | } | ||
+ | |||
+ | /* colours */ | ||
+ | /* default */ | ||
+ | div.box, div.box .box_content, | ||
+ | border-color: | ||
+ | } | ||
+ | |||
+ | div.box, div.box .xbox, div.box .xb1, div.box .xb2, div.box .xb3, div.box .xb4 { | ||
+ | background: #ecf1f4; | ||
+ | } | ||
+ | |||
+ | div.box div.box_title, | ||
+ | div.box .box_content { background: #f7fafb;} | ||
+ | |||
+ | /* blue */ | ||
+ | div.box.blue, | ||
+ | div.box.blue .xb1, div.box.blue .xb2, div.box.blue .xb3, div.box.blue .xb4 { | ||
+ | border-color: | ||
+ | } | ||
+ | |||
+ | div.box.blue, | ||
+ | div.box.blue .xb1, div.box.blue .xb2, div.box.blue .xb3, div.box.blue .xb4 { | ||
+ | background: #e4ecf8; | ||
+ | } | ||
+ | |||
+ | div.box.blue div.box_title, | ||
+ | div.box.blue .box_content {background: | ||
+ | |||
+ | /* red */ | ||
+ | div.box.red, | ||
+ | div.box.red .xb1, div.box.red .xb2, div.box.red .xb3, div.box.red .xb4 { | ||
+ | border-color: | ||
+ | } | ||
+ | |||
+ | div.box.red, | ||
+ | div.box.red .xb1, div.box.red .xb2, div.box.red .xb3, div.box.red .xb4 { | ||
+ | background: #f8ece4; | ||
+ | } | ||
+ | |||
+ | div.box.red div.box_title, | ||
+ | div.box.red .box_content {background: | ||
+ | |||
+ | /* green */ | ||
+ | div.box.green, | ||
+ | div.box.green .xb1, div.box.green .xb2, div.box.green .xb3, div.box.green .xb4 { | ||
+ | border-color: | ||
+ | } | ||
+ | |||
+ | div.box.green, | ||
+ | div.box.green .xb1, div.box.green .xb2, div.box.green .xb3, div.box.green .xb4 { | ||
+ | background: #e4f8f2; | ||
+ | } | ||
+ | |||
+ | div.box.green div.box_title, | ||
+ | div.box.green .box_content {background: | ||
+ | |||
+ | /* orange */ | ||
+ | div.box.orange, | ||
+ | div.box.orange .xb1, div.box.orange .xb2, div.box.orange .xb3, div.box.orange .xb4 { | ||
+ | border-color: | ||
+ | } | ||
+ | |||
+ | div.box.orange, | ||
+ | div.box.orange .xb1, div.box.orange .xb2, div.box.orange .xb3, div.box.orange .xb4 { | ||
+ | background: #f4e8ca; | ||
+ | } | ||
+ | |||
+ | div.box.orange div.box_title, | ||
+ | div.box.orange .box_content {background: | ||
+ | |||
+ | /* must come last to override coloured background when using rounded corners */ | ||
+ | |||
+ | div.box.round { | ||
+ | background: transparent !important; | ||
+ | } | ||
+ | |||
+ | /* end plugin:box */ | ||
+ | </ | ||
+ | |||
+ | ===== Tips ===== | ||
+ | **To resolve the conflicts with ' | ||
+ | * In ''/ | ||
+ | * Download/ | ||
+ | * In the '' | ||
+ | * In the '' | ||
+ | * In both files there may be a few occurrences of the word ' | ||
+ | * Upload both files to the '' | ||
+ | That's it! You're done, and ready to nest boxes from both plugins. | ||
+ | |||
+ | Note: DO NOT MIX the SYNTAX of the two plugins in a single box. | ||
+ | |||
+ | email : Keith Shepherd | ||
+ | |||
+ | rhabdo[dot]sidera[at]gmail[dot]com |