====== box plugin ======
---- plugin ----
description: Highlight particularly important parts of your wiki in boxes that stand out
author : Christopher Smith
email : chris@jalakai.co.uk
type : syntax
lastupdate : 2008-03-03
compatible :
depends :
conflicts :
similar :
tags : boxes, highlight, div
----
This [[plugin]] brings boxes to [[:Dokuwiki]] allowing you to highlight particularly important parts of your wiki in boxes that standout. The plugin comes with the ability to make ordinary square boxes, snazzyTM boxes with rounded corners, boxes with titles and boxes of varying widths. Dokuwiki markup is allowed inside the box - where pretty well anything goes - and inside the title where only text markup, links, smileys and the like should be
used.
It is probably sensible to set the style of the box you will most commonly use to be the default box. For details refer to the [[#style.css]]
==== Notes ====
* My version of this page - which could be more recently updated - can be found [[http://wiki.jalakai.co.uk/dokuwiki/doku.php/tutorial/boxes|here]]
=====Acknowledgement=====
The rounded corners are based on [[http://www.cssplay.co.uk/boxes/snazzy.html|snazzy borders]] by Stu Nicholls of [[http://www.cssplay.co.uk|CSS Play]] which in turn were inspired by Alessandro Fulciniti's [[http://pro.html.it/esempio/nifty/|nifty corners]].
===== Syntax =====
A simple box:
_title_colours}>";
break;
case 'box_open' :
if ($this->title_mode) {
$this->title_mode = false;
$renderer->doc .= " _title_colours}>".$renderer->_xmlEntities($data)." ".$data." ".$renderer->_xmlEntities($data)."
* width% width of the box, must use % unit
* classes one or more classes used to style the box, several predefined styles included in style.css
* title (optional) all text after '|' will be rendered above the main code text with a
* different style.
*
* Acknowledgements:
* Rounded corners based on snazzy borders by Stu Nicholls (http://www.cssplay.co.uk/boxes/snazzy)
* which is in turn based on nifty corners by Alessandro Fulciniti (http://pro.html.it/esempio/nifty/)
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Christopher Smith
Thanks to Andy Webber of Oracle's Ethical Hacking Team for discovering this flaw. --- //[[chris@jalakai.co.uk|Christopher Smith]] 2008-03-03 17:46//
===== To Do =====
===== Bugs =====
* Boxes can overlay TOC at top of the page. CSS fix needed.
**Render bug with IE 6.0** - Running box plugin with roundbox template. Scrolling (or if box is big enough just page refreshes) sometimes causes lines/blocks of the box to not be updated leaving the background colour on display. Managed to replicate problem on box home dokuwiki [[http://wiki.jalakai.co.uk/dokuwiki/doku.php/tutorial/boxes|here]]. The bad region seems to be bigger if the box is larger (more text in it). --- //[[ja@vibtech.co.uk|Jonathan Alexander]] 2005-12-06 14:49//
>Found a fix that seems to work for me from [[http://www.communitymx.com/content/article.cfm?page=2&cid=C37E0|communitymx]] (thanks to Google) just inserted the code below under the "div.box .box_content" declaration in the style.css above.
/* plugin:box */
div.box {
width: 50%;
margin: 1em auto;
border: 1px solid;
padding: 4px;
overflow: hidden;
}
/* rounded corners styles from Stu Nicholls snazzy borders, http://www.cssplay.co.uk/boxes/snazzy.html */
.xtop, .xbottom {background:transparent; font-size:0; line-height: 1px;}
.xb1, .xb2, .xb3, .xb4 {display:block; overflow:hidden; border-style: solid;}
.xb2, .xb3 {height:1px;}
.xb2, .xb3, .xb4 {border-width:0 1px;}
.xb1 {height: 0; margin:0 5px; border-width:1px 0 0 0;}
.xb2 {margin:0 3px; border-width:0 2px;}
.xb3 {margin:0 2px;}
.xb4 {height:2px; margin:0 1px;}
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:block; border-width:0 1px; border-style: solid; padding: 0 4px; }
div.box p.box_title, div.box p.box_caption {
font-size: 90%;
margin: 0;
padding: 2px 6px;
line-height: 1.2;
}
div.box p.box_title { margin-bottom: 4px;}
div.box p.box_caption { margin-top: 4px;}
div.box .box_content {
margin: 0;
padding: 0 6px;
border-width: 1px;
border-style: dashed;
line-height: 1.2;
}
/* floating alignment */
div.box.left {
float: left;
margin-right: 1em;
}
div.box.right {
float: right;
margin-left: 1em;
}
/* colours */
/* default */
div.box, div.box .box_content, div.box .xbox, div.box .xb1, div.box .xb2, div.box .xb3, div.box .xb4 {
border-color: __dark__;
}
div.box, div.box .xbox, div.box .xb1, div.box .xb2, div.box .xb3, div.box .xb4 {
background: __light__;
}
div.box p.box_title, div.box p.box_caption { background: __medium__;}
div.box .box_content { background: __lighter__;}
/* blue */
div.box.blue, div.box.blue > * > .box_content, div.box.blue > .xbox,
div.box.blue > * > .xb1, div.box.blue > * > .xb2, div.box.blue > * > .xb3, div.box.blue > * > .xb4 {
border-color: #bbbbdd;
}
div.box.blue, div.box.blue > .xbox,
div.box.blue > * > .xb1, div.box.blue > * > .xb2, div.box.blue > * > .xb3, div.box.blue > * > .xb4 {
background: #e4ecf8;
}
div.box.blue > * > p.box_title, div.box.blue > * > p.box_caption {background: #cad0ee;}
div.box.blue > * > .box_content {background: #f4f8fd;}
/* red */
div.box.red, div.box.red > * > .box_content, div.box.red > .xbox,
div.box.red > * > .xb1, div.box.red > * > .xb2, div.box.red > * > .xb3, div.box.red > * > .xb4 {
border-color: #ddbbbb;
}
div.box.red, div.box.red > .xbox,
div.box.red > * > .xb1, div.box.red > * > .xb2, div.box.red > * > .xb3, div.box.red > * > .xb4 {
background: #f8ece4;
}
div.box.red > * > p.box_title, div.box.red > * > p.box_caption {background: #eed0ca;}
div.box.red > * > .box_content {background: #fdf4ec;}
/* green */
div.box.green, div.box.green > * > .box_content, div.box.green > .xbox,
div.box.green > * > .xb1, div.box.green > * > .xb2, div.box.green > * > .xb3, div.box.green > * > .xb4 {
border-color: #bbddbb;
}
div.box.green, div.box.green > .xbox,
div.box.green > * > .xb1, div.box.green > * > .xb2, div.box.green > * > .xb3, div.box.green > * > .xb4 {
background: #e4f8f2;
}
div.box.green > * > p.box_title, div.box.green > * > p.box_caption {background: #c4e4d4;}
div.box.green > * > .box_content {background: #ecfaf6;}
/* orange */
div.box.orange, div.box.orange > * > .box_content, div.box.orange > .xbox,
div.box.orange > * > .xb1, div.box.orange > * > .xb2, div.box.orange > * > .xb3, div.box.orange > * > .xb4 {
border-color: #da3;
}
div.box.orange, div.box.orange > .xbox,
div.box.orange > * > .xb1, div.box.orange > * > .xb2, div.box.orange > * > .xb3, div.box.orange > * > .xb4 {
background: #f4e8ca;
}
div.box.orange > * > p.box_title, div.box.orange > * > p.box_caption {background: #f0d499;}
div.box.orange > * > .box_content {background: #f8f0da;}
/* must come last to override coloured background when using rounded corners */
div.box.round {
background: transparent !important;
}
/* IE fixes for unsupported child selector \*/
* html div.box div.box, * html div.box div.box .box_content, * html div.box div.box .xbox,
* html div.box div.box .xb1, * html div.box div.box .xb2,
* html div.box div.box .xb3, * html div.box div.box .xb4 {
border-color: __dark__;
}
* html div.box div.box, * html div.box div.box .xbox,
* html div.box div.box .xb1, * html div.box div.box .xb2,
* html div.box div.box .xb3, * html div.box div.box .xb4 {
background: __light__;
}
* html div.box div.box p.box_title, * html div.box div.box p.box_caption { background: __medium__;}
* html div.box div.box .box_content { background: __lighter__;}
* html div.box.round .xtop, * html div.box.round .xbottom {display: block;}
* html div.box.round .xbox {display:block; border-width:0 1px; border-style: solid; padding: 0 4px; }
/* blue */
* html div.box.blue .box_content, * html div.box.blue .xbox,
* html div.box.blue .xb1, * html div.box.blue .xb2, * html div.box.blue .xb3, * html div.box.blue .xb4 {
border-color: #bbbbdd;
}
* html div.box.blue .xbox,
* html div.box.blue .xb1, * html div.box.blue .xb2, * html div.box.blue .xb3, * html div.box.blue .xb4 {
background: #e4ecf8;
}
* html div.box.blue p.box_title, * html div.box.blue p.box_caption {background: #cad0ee;}
* html div.box.blue .box_content {background: #f4f8fd;}
/* nested blue */
* html div.box div.box.blue .box_content, * html div.box div.box.blue .xbox,
* html div.box div.box.blue .xb1, * html div.box div.box.blue .xb2,
* html div.box div.box.blue .xb3, * html div.box div.box.blue .xb4 {
border-color: #bbbbdd;
}
* html div.box div.box.blue .xbox,
* html div.box div.box.blue .xb1, * html div.box div.box.blue .xb2,
* html div.box div.box.blue .xb3, * html div.box div.box.blue .xb4 {
background: #e4ecf8;
}
* html div.box div.box.blue p.box_title,
* html div.box div.box.blue p.box_caption {background: #cad0ee;}
* html div.box div.box.blue .box_content {background: #f4f8fd;}
/* red */
* html div.box.red .box_content, * html div.box.red .xbox,
* html div.box.red .xb1, * html div.box.red .xb2, * html div.box.red .xb3, * html div.box.red .xb4 {
border-color: #ddbbbb;
}
* html div.box.red .xbox,
* html div.box.red .xb1, * html div.box.red .xb2, * html div.box.red .xb3, * html div.box.red .xb4 {
background: #f8ece4;
}
* html div.box.red p.box_title, * html div.box.red p.box_caption {background: #eed0ca;}
* html div.box.red .box_content {background: #fdf4ec;}
/* nested red */
* html div.box div.box.red .box_content, * html div.box div.box.red .xbox,
* html div.box div.box.red .xb1, * html div.box div.box.red .xb2,
* html div.box div.box.red .xb3, * html div.box div.box.red .xb4 {
border-color: #ddbbbb;
}
* html div.box div.box.red .xbox,
* html div.box div.box.red .xb1, * html div.box div.box.red .xb2,
* html div.box div.box.red .xb3, * html div.box div.box.red .xb4 {
background: #f8ece4;
}
* html div.box div.box.red p.box_title, * html div.box div.box.red p.box_caption {background: #eed0ca;}
* html div.box div.box.red .box_content {background: #fdf4ec;}
/* green */
* html div.box.green .box_content, * html div.box.green .xbox,
* html div.box.green .xb1, * html div.box.green .xb2, * html div.box.green .xb3, * html div.box.green .xb4 {
border-color: #bbddbb;
}
* html div.box.green .xbox,
* html div.box.green .xb1, * html div.box.green .xb2, * html div.box.green .xb3, * html div.box.green .xb4 {
background: #e4f8f2;
}
* html div.box.green p.box_title, * html div.box.green p.box_caption {background: #c4e4d4;}
* html div.box.green .box_content {background: #ecfaf6;}
/* nested green */
* html div.box div.box.green .box_content, * html div.box div.box.green .xbox,
* html div.box div.box.green .xb1, * html div.box div.box.green .xb2,
* html div.box div.box.green .xb3, * html div.box div.box.green .xb4 {
border-color: #bbddbb;
}
* html div.box div.box.green .xbox,
* html div.box div.box.green .xb1, * html div.box div.box.green .xb2,
* html div.box div.box.green .xb3, * html div.box div.box.green .xb4 {
background: #e4f8f2;
}
* html div.box div.box.green p.box_title, * html div.box div.box.green p.box_caption {background: #c4e4d4;}
* html div.box div.box.green .box_content {background: #ecfaf6;}
/* orange */
* html div.box.orange .box_content, * html div.box.orange .xbox,
* html div.box.orange .xb1, * html div.box.orange .xb2, * html div.box.orange .xb3, * html div.box.orange .xb4 {
border-color: #da3;
}
* html div.box.orange .xbox,
* html div.box.orange .xb1, * html div.box.orange .xb2, * html div.box.orange .xb3, * html div.box.orange .xb4 {
background: #f4e8ca;
}
* html div.box.orange p.box_title, * html div.box.orange p.box_caption {background: #f0d499;}
* html div.box.orange .box_content {background: #f8f0da;}
/* nestedorange */
* html div.box div.box.orange .box_content, * html div.box div.box.orange .xbox,
* html div.box div.box.orange .xb1, * html div.box div.box.orange .xb2,
* html div.box div.box.orange .xb3, * html div.box div.box.orange .xb4 {
border-color: #da3;
}
* html div.box div.box.orange .xbox,
* html div.box div.box.orange .xb1, * html div.box div.box.orange .xb2,
* html div.box div.box.orange .xb3, * html div.box div.box.orange .xb4 {
background: #f4e8ca;
}
* html div.box div.box.orange p.box_title, * html div.box div.box.orange p.box_caption {background: #f0d499;}
* html div.box div.box.orange .box_content {background: #f8f0da;}
/* end plugin:box */
===== Revision History =====
* 2006-04-25 --- XSS vulnerability fixed
* 2006-04-20 --- darcs update only
* markup updated inline with Dokuwiki fixes for PType block
* corrections to syntax description
* minor style changes for line-heights
* 2006-03-11 --- 2006-01-24 patch applied to non-darcs package;
* support for all CSS length units added
* styles added to support box nesting
* lists can now be included in boxes
* 2006-01-24 --- darcs update only (package release held until after next Dokuwiki update)
* support nesting of boxes
* default style now uses Dokuwiki CSS substitutions
* 2005-11-25 --- Added caption text (displayed below main box content). Added left & right styles.
* 2005-10-25 --- Bug fix for merged paragraphs in boxes (thanks Matthias).
* 2005-10-17 --- Bug fix for some windows php installations (thanks Pablo).
* 2005-10-12 --- Released.
===== Security Fix =====
This fix is only applicable to those using older versions box plugin with DokuWiki versions prior to March 2006. Those running a Mar 2006 or later version of DokuWiki should update the plugin using the [[#sources]] lists above.
Also apply Fix #2 detailed below.
=== Instructions ===
* locate the file ''lib/plugins/box/syntax.php''
* open it for editing in a text editor
* replace the function _boxstyle($str) (around line #150) with the code given below.
function _boxstyle($str) {
if (!strlen($str)) return array();
$styles = array();
$tokens = preg_split('/\s+/', $str, 9); // limit is defensive
foreach ($tokens as $token) {
if (preg_match('/^\d*\.?\d+(%|px|em|ex|pt|cm|mm|pi|in)$/', $token)) {
$styles['width'] = $token;
continue;
}
// restrict token (class names) characters to prevent any malicious data
if (preg_match('/[^A-Za-z0-9_-]/',$token)) continue;
$styles['class'] = (isset($styles['class']) ? $styles['class'].' ' : '').$token;
}
return $styles;
}
* save the file
This restricts the characters available for use in any custom style names to alphanumerics plus dash and underscore (e.g. A-Z, a-z, 0-9, _ -). It also updates box width detection to support any valid CSS length value. See syntax for details.
===== Security Fix 2 =====
This fix applies to all versions of the plugin prior to Mar 3, 2008. It is recommended that users of the plugin upgrade DW and this plugin to the most recent versions. For those interested who wish to fix the vulnerability with out updating.
case 'box_close' :
$renderer->doc .= "
/* Hides from IE5-mac \*/
* html .div.box.box_content {height: 1%;}
/* End hide from IE5-mac */
* **Missing
foo
bar
results in this html:
foo
bar
as you can see, there's one missing. --- //[[bernd@bzed.de|Bernd Zeimetz]] 2007-03-03 02:39 CET// \\ **solution**: change two lines in function render (near case 'box_open'):
--- syntax.php 2008-02-27 23:44:08.000000000 +0100
+++ syntax.php.new 2008-02-27 23:55:23.000000000 +0100
@@ -129,9 +129,9 @@
case 'box_open' :
if ($this->title_mode) {
$this->title_mode = false;
- $renderer->doc .= "\n";
+ $renderer->doc .= "
\n";
} else {
- $renderer->doc .= $this->_xhtml_boxopen($data)."";
+ $renderer->doc .= $this->_xhtml_boxopen($data)."
";
}
break;
lines beginning with "-" are the original lines, the "+"-lines are the new ones. --- //[[stefan@kuchling.de|Stefan Kuchling]]//
This patch has been added to the latest plugin version. Thanks Bernd and Stefan for your efforts. --- //[[chris@jalakai.co.uk|Christopher Smith]] 2008-03-03 17:46//
===== Tips =====
==== Alternate Syntax & Allowing markup in captions ====
Great plugin! I've modifed my copy and thought others might be interested. [[http://robmeerman.co.uk/coding/file_renamer|See example]].
Changes:
- Syntax changed: ''**%%<<<%%** width classes | title ::: //content// ::: caption **%%>>>%%**''
- Markup allowed in captions
- Title and caption may be over multple lines (i.e. multiple paragraphs)
- Width may be specifed in %, px, em or ex //(now included in release version)//
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.
It works well on my site, and the only problem it seems to have is that I can't nest boxes (not sure why).
For complete code please see: [[:plugin:boxes_mod|Modifed Boxes]]
--- //[[robert.meerman@gmail.com|Robert Meerman]] 2006/02/24 17:13//
> Hi Robert, Have you tried your syntax with the nesting patch, I briefly looked at your code and didn't see anything that should prevent nesting. Cheers --- //[[chris@jalakai.co.uk|Christopher Smith]] 2006-02-24 19:26//
==== Backporting to 2005-07-13 ====
Here's what I did to backport this box plugin to the 2005-07-13 release.
* Add style.css to the end of your template's ''design.css'' and ''print.css'':
$ cd .../lib/plugins/box
$ cat style.css >> ../../tpl/template_name/design.css
$ cat style.css >> ../../tpl/template_name/print.css
* Apply the following patch:
--- box-orig/syntax.php 2005-11-24 13:28:17.000000000 -0800
+++ box/syntax.php 2005-12-16 14:52:48.000000000 -0800
@@ -45,6 +45,19 @@
function getType(){ return 'container';}
function getAllowedTypes() { return array('container','substition','protected','disabled','formatting','paragraphs'); }
+
+ function syntax_plugin_box(){
+ global $PARSER_MODES;
+ $this->allowedModes = array_merge(
+ $PARSER_MODES['container'],
+ $PARSER_MODES['substition'],
+ $PARSER_MODES['protected'],
+ $PARSER_MODES['disabled'],
+ $PARSER_MODES['formatting'],
+ $PARSER_MODES['paragraphs']
+ );
+ }
+
function getPType(){ return 'normal';}
// must return a number lower than returned by native 'code' mode (200)
@@ -54,9 +67,9 @@
* Connect pattern to lexer
*/
function connectTo($mode) {
- $this->Lexer->addEntryPattern('(?=.*?)',$mode,'plugin_box');
- $this->Lexer->addEntryPattern('(?=.*?)',$mode,'plugin_box');
- $this->Lexer->addEntryPattern('.*?)',$mode,'plugin_box');
+ $this->Lexer->addEntryPattern('(?=.*?\x3C/box.*?\x3E)',$mode,'plugin_box');
+ $this->Lexer->addEntryPattern('(?=.*?\x3C/box.*?\x3E)',$mode,'plugin_box');
+ $this->Lexer->addEntryPattern('.*?\x3C/box.*?\x3E)',$mode,'plugin_box');
}
function postConnect() {
@@ -182,4 +195,4 @@
}
==== More Verbose CSS with More Color Options ====
This is a very handy plugin! I started to play with the CSS to do some custom things (I'm going to use this plugin in 3-4 Dokuwiki installations), namely to hide the inner border and a couple other small color tweaks. I ended up with something that I think it a bit more flexible to modify (separate definitions for separate borders), commented more (I tried to note some of the sections a bit better), and possibly more IE friendly (I think I fixed a problem with one of the background colors not displaying in IE 6).
I'm no expert when it comes to css, so I can't guarantee I've done this 100% efficiently, but it holds up with every browser browsershots.org supports.
The CSS can be see here: http://wiki.ryanjacobs.name/public/tech/dokuwiki_box_plugin_css
In case anyone is interested... Cheers! --- //[[ryan.jake@gmail.com|Ryan Jacobs]]//
===== Discussion =====
Thanks, for the plugin, it looks really great. However I want to use it to highlight different content. For example I'd like to use \n";
was missing
----
Hi - Thanks for a terrific plugin. I am having problems with boxes and captions when printing. I copied the plugins/box/style.css -> plugins/box/print.css and it works, but when I include a caption at the top an extra line is inserted between the box top and the caption. I'm using the monobook template. [[http://www.kabissa.org/wiki/doku.php?id=playground&rev=1178805954&mbdo=print|Click to see an example in my wiki playground]]. Would be most grateful for any suggestions. ---//[[http://www.saidia.org|Tobias]] (5/10/2007)//
----
Nice plugin. I'm wondering if it is possible to have the caption work like the title, where links can be embedded in it?
----
Hi, I have a lot of citation. I often copy and paste.
Is it to possible to keep carriage return and avoid to add manually "%%\\%%" at the end of each new lines ?\\
Whereas good plugin. \\
\\
I noticed when I copy the code of the third box of [[http://wiki.jalakai.co.uk/dokuwiki/doku.php/test/boxes]] and paste here (or on my dokuwiki), the text box is on only one line. I don't include the caption \\
this is
also
boxed
e.g. ** this is
also
boxed
**
\\ \\
On your test page, the text box is on 3 lines. Why 1 line, me and you 3 lines on your page ? I copy and paste exactly the same source code. In your page, the carriage return is kept. \\
How can I have the same behavior ? So I will able to copy and paste keeping CR.
> Yes. See the [[plugin:linebreak|linebreak plugin]] --- //[[chris@jalakai.co.uk|Christopher Smith]] 2007-07-26 13:08//
----
Hi Chris,
Very nice and useful effects. Any thoughts about adding an icon on the title bar ?\\
See for example http://www.headshift.com/\\
I just don't understand how they did that!\\
Cheers, Peter Chan 2007-10-02
----
Hi -- I am trying to use boxes in the latest Dokuwiki (2006-06-26b)but it doesn't seem to want to work. The only plug-in behavior that I've been able to identify is with markup in captions. If I bold the caption it displays the asterisks. If the plugin was just whiffing, wouldn't the markup work? Why would this not work? Thanks.
Rick Reynolds 2008-01-16
> Formatting isn't currently supported in captions. However the modified boxes plugin, which uses a slightly different syntax does allow formatting in captions. See links above. --- //[[chris@jalakai.co.uk|Christopher Smith]] 2008-03-03 17:46//
>>That is right, but box_mod is not updated to support DW 2008-05-05: little layout errors, especially when there are more than one boxes on the page... In my experience works far more smoothly. [[gijsh@sherpanet.nl|Gijs van Gemert]]
----
It started working for me when I changed to the dokucms template. With the default template it won't work for me. 2008-02-11
----
Is it possible to add support for absolute (or minimum) height for the boxes? I've tried doing it myself, but both my knowledge of PHP and CSS is insufficient to implement this.
----
Any chance of allowing the text colour to be altered (as black on dark colours is often unreadable)? Bob 4-Apr-08
----
I noticed it was necessary to purge cache to allow new plugin's css instructions to be inserted:
* I followed http://www.dokuwiki.org/wiki:caching advices,
* I touched conf/local.php, edited and saved it ...
* I selected 'embedded html' in config form
still, no div.box css instruction in my css sheet, and box wont display properly.
I finally found a file permission issue:
ls -l box/style.css
-rwx------ 1 box/style.css
should that be fixed in archive.tgz ?