dokuwiki_add_caption
This is an old revision of the document!
Table of Contents
DokuWiki: Add caption to table
- This is a small piece of Javascript code to add a caption to a table.
- Works with DokuWiki's default template.
- Works with WRAP plugin.
- Add a line of
<WRAP caption>Caption text</WRAP>before the table.
Code
Add the following code to your conf/userscript.js.
- add_caption.js
jQuery('.page div.table>table').each(function (index) { let $table = jQuery(this); let $prevDiv = $table.parent().prev(); if ($prevDiv.hasClass('wrap_caption') || $prevDiv.hasClass('caption')) { let captionHtml = '<caption>' + $prevDiv.text().trim() + '</caption>'; $table.prepend(captionHtml); $prevDiv.remove(); } });
Probably you like to add the following lines or similar to your conf/userall.css.
- styles.css
caption { text-align: center; font-weight: bold; }
Test drive
A table without caption (default)
^ No. ^ Description ^ Quantity ^ | 1 | Lorem ipsum dolor sit amet | 100 | | 2 | Konsectetur adipiscing elit molestie | 50 | | 3 | Scelerisque vestibulum metus risus |25 | | 4 | Nunc a commodo nullam | 200 |
The above code is rendered as follows:
| No. | Description | Quantity |
|---|---|---|
| 1 | Lorem ipsum dolor sit amet | 100 |
| 2 | Konsectetur adipiscing elit molestie | 50 |
| 3 | Scelerisque vestibulum metus risus | 25 |
| 4 | Nunc a commodo nullam | 200 |
A table with a caption
<WRAP caption>Table 2. Caption text is displayed like this</WRAP> ^ No. ^ Description ^ Quantity ^ Remark ^ | 1 | Lorem ipsum dolor sit amet | 100 |Euismod posuere mus lobortis | | 2 | Konsectetur adipiscing elit molestie | 50 |Aenean sed ornare| | 3 | Scelerisque vestibulum metus risus |25 |Sociis mollis, morbi proin suspendisse magnis| | 4 | Nunc a commodo nullam | 200 | |
is rendered as:
Table 2. Caption text is displayed like this
| No. | Description | Quantity | Remark |
|---|---|---|---|
| 1 | Lorem ipsum dolor sit amet | 100 | Euismod posuere mus lobortis |
| 2 | Konsectetur adipiscing elit molestie | 50 | Aenean sed ornare |
| 3 | Scelerisque vestibulum metus risus | 25 | Sociis mollis, morbi proin suspendisse magnis |
| 4 | Nunc a commodo nullam | 200 |
dokuwiki_add_caption.1623075005.txt.gz · Last modified: 2021/06/07 23:10 by admin
