This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
|
dokuwiki_add_caption [2021/06/05 22:55] admin [A table without caption] |
dokuwiki_add_caption [2021/06/09 22:41] admin [Mechanism] |
||
|---|---|---|---|
| Line 2: | Line 2: | ||
| + | * This is a small piece of Javascript code to add a caption to a table. | ||
| * Works with DokuWiki' | * Works with DokuWiki' | ||
| - | * | + | * Works with WRAP plugin. |
| + | * Just add a line of '' | ||
| + | ===== Code ===== | ||
| + | Add the following code to your '' | ||
| + | |||
| + | <code javascript add_caption.js> | ||
| + | jQuery(' | ||
| + | let $table = jQuery(this); | ||
| + | let $prevDiv = $table.parent().prev(); | ||
| + | if ($prevDiv.hasClass(' | ||
| + | if ($prevDiv.children(' | ||
| + | let captionText = $prevDiv.children(' | ||
| + | $table.prepend('< | ||
| + | $prevDiv.remove(); | ||
| + | if (location.hash) { | ||
| + | location.href = location.hash; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | }); | ||
| + | </ | ||
| + | |||
| + | Probably you like to add the following lines or similar to your '' | ||
| + | |||
| + | <code css styles.css> | ||
| + | caption { | ||
| + | text-align: center; | ||
| + | font-weight: | ||
| + | } | ||
| + | </ | ||
| ===== Test drive ===== | ===== Test drive ===== | ||
| - | ==== A table without caption ==== | + | ==== A table without caption |
| + | |||
| + | The default syntax of a table is like this: | ||
| < | < | ||
| - | ^ No. ^ Description ^ Quantity ^ | + | ^ No. ^ Description ^ Quantity |
| - | | 1 | Lorem ipsum dolor sit amet | 100 | | + | | 1 | Lorem ipsum dolor sit amet | 100 |Euismod posuere mus lobortis |
| - | | 2 | Konsectetur adipiscing elit molestie | + | | 2 | Konsectetur adipiscing elit molestie |
| - | | 3 | Scelerisque vestibulum metus risus |25 | | + | | 3 | Scelerisque vestibulum metus risus |25 |Sociis mollis, morbi proin suspendisse magnis| |
| - | | 4 | Nunc a commodo nullam | 200 | | + | | 4 | Nunc a commodo nullam | 200 | |
| </ | </ | ||
| The above code is rendered as follows: | The above code is rendered as follows: | ||
| - | ^ No. ^ Description ^ Quantity ^ | + | ^ No. ^ Description ^ Quantity |
| - | | 1 | Lorem ipsum dolor sit amet | 100 | | + | | 1 | Lorem ipsum dolor sit amet | 100 |Euismod posuere mus lobortis |
| - | | 2 | Konsectetur adipiscing elit molestie | + | | 2 | Konsectetur adipiscing elit molestie |
| - | | 3 | Scelerisque vestibulum metus risus |25 | | + | | 3 | Scelerisque vestibulum metus risus |25 |Sociis mollis, morbi proin suspendisse magnis| |
| - | | 4 | Nunc a commodo nullam | 200 | | + | | 4 | Nunc a commodo nullam | 200 | |
| - | ==== A table without caption ==== | ||
| + | ==== A table with a caption ==== | ||
| - | <WRAP caption> | + | Add one line above the table like this: |
| + | |||
| + | < | ||
| + | <WRAP caption> | ||
| ^ No. ^ Description ^ Quantity ^ Remark ^ | ^ No. ^ Description ^ Quantity ^ Remark ^ | ||
| Line 36: | Line 71: | ||
| | 3 | Scelerisque vestibulum metus risus |25 |Sociis mollis, morbi proin suspendisse magnis| | | 3 | Scelerisque vestibulum metus risus |25 |Sociis mollis, morbi proin suspendisse magnis| | ||
| | 4 | Nunc a commodo nullam | 200 | | | | 4 | Nunc a commodo nullam | 200 | | | ||
| + | </ | ||
| + | |||
| + | this is rendered as: | ||
| + | |||
| + | <WRAP caption> | ||
| + | |||
| + | ^ No. ^ Description ^ Quantity ^ Remark ^ | ||
| + | | 1 | Lorem ipsum dolor sit amet | 100 |Euismod posuere mus lobortis | | ||
| + | | 2 | Konsectetur adipiscing elit molestie | ||
| + | | 3 | Scelerisque vestibulum metus risus |25 |Sociis mollis, morbi proin suspendisse magnis| | ||
| + | | 4 | Nunc a commodo nullam | 200 | | | ||
| + | |||
| + | Since the caption is inserted within the table, it aligns with the table, as shown below with a small table. | ||
| + | |||
| + | <WRAP caption> | ||
| + | |||
| + | ^ No. ^ Description ^ Quantity ^ | ||
| + | | 1 | Lorem ipsum dolor sit amet | 100 | | ||
| + | | 2 | Konsectetur adipiscing elit molestie | ||
| + | | 3 | Scelerisque vestibulum metus risus |25 | | ||
| + | | 4 | Nunc a commodo nullam | 200 | | ||
| + | |||
| + | ===== Mechanism ===== | ||
| + | |||
| + | The original HTML text is: | ||
| + | |||
| + | <code html> | ||
| + | <div class=" | ||
| + | <p> Caption text</ | ||
| + | </ | ||
| + | <div class=" | ||
| + | < | ||
| + | ... | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | This is transformed to: | ||
| + | |||
| + | <code html> | ||
| + | <div class=" | ||
| + | < | ||
| + | < | ||
| + | ... | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | Since this transformation is made **after** the rendering by DokuWiki, the normal formatting syntax (such as '' | ||