Skip to content

Commit

Permalink
Export table captions
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushalmodi committed Dec 23, 2017
1 parent 748dd4d commit 71e1fdf
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 7 deletions.
14 changes: 13 additions & 1 deletion ox-blackfriday.el
Expand Up @@ -675,6 +675,18 @@ contextual information."
(if lbl
(format "<a id=\"%s\"></a>\n\n" lbl)
"")))
(caption (org-export-get-caption table))
(caption-html (if (not caption)
""
(let* ((table-num (org-export-get-ordinal
table info
nil #'org-html--has-caption-p))
(caption-str (org-export-data caption info)))
(format (concat "<caption class=\"table-caption\">\n"
" <span class=\"table-number\">Table %d:</span>\n"
" %s\n"
"</caption>\n\n")
table-num caption-str))))
(tbl (replace-regexp-in-string "\n\n" "\n" contents)))
;; If the table has only 1 row, do *not* make it a header row..
;; instead create an empty header row.
Expand All @@ -695,7 +707,7 @@ contextual information."
(dummy-header (replace-regexp-in-string "[-:]" " " hrule)))
(setq tbl (concat dummy-header "\n" hrule "\n" row-1))))
;; (message "[ox-bf-table DBG] Tbl:\n%s" tbl)
(concat label tbl)))
(concat label caption-html tbl)))

;;;; Verse Block
(defun org-blackfriday-verse-block (_verse-block contents info)
Expand Down
24 changes: 23 additions & 1 deletion test/site/content-org/all-posts.org
Expand Up @@ -523,6 +523,28 @@ sense. But hey, a test is a test./
| <l> | | <c> | <r> |

You should see *no* table exported above.
** Table caption :caption:
:PROPERTIES:
:EXPORT_FILE_NAME: table-caption
:END:
#+CAPTION: Awesome table
| h1 | h2 | h3 |
|-----+-----+-----|
| abc | def | ghi |

Some text.

#+CAPTION: Another awesome table
| h1 | h2 | h3 |
|-----+-----+-----|
| jkl | mno | pqr |

Some more text.

#+CAPTION: Third table
| h1 | h2 | h3 |
|-----+-----+----|
| stu | vwx | yz |
* Source blocks :src_block:
** Code fence :code_fence:
*** Code-fenced source blocks (default behavior)
Expand Down Expand Up @@ -1723,7 +1745,7 @@ that the link jump is evident):
#+END_SRC

*Here we refer to code snippet [[code__hello]].*
*** Links to tables
*** Links to tables :table:caption:
:PROPERTIES:
:EXPORT_FILE_NAME: links-to-tables
:END:
Expand Down
20 changes: 15 additions & 5 deletions test/site/content/posts/links-to-tables.md
@@ -1,6 +1,6 @@
+++
title = "Links to tables"
tags = ["links", "internal-links"]
tags = ["links", "internal-links", "table", "caption"]
draft = false
+++

Expand Down Expand Up @@ -31,13 +31,18 @@ Here's another table:
will output below (_lorem-ipsum_ added to increase page content so
that the link jump is evident):

<a id="org40b5987"></a>
<a id="org44317dc"></a>

<caption class="table-caption">
<span class="table-number">Table 1:</span>
Simple table 1
</caption>

| a | b |
|---|---|
| c | d |

**Here we refer to table [2](#org8a6806a).**
**Here we refer to table [2](#org0622dcf).**

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque et
quam metus. Etiam in iaculis mi, sit amet pretium magna. Donec ut dui
Expand Down Expand Up @@ -93,13 +98,18 @@ blandit in.

Here's another table:

<a id="org8a6806a"></a>
<a id="org0622dcf"></a>

<caption class="table-caption">
<span class="table-number">Table 2:</span>
Simple table 2
</caption>

| e | f |
|---|---|
| g | h |

**Here we refer to table [1](#org40b5987).**
**Here we refer to table [1](#org44317dc).**

---

Expand Down
36 changes: 36 additions & 0 deletions test/site/content/posts/table-caption.md
@@ -0,0 +1,36 @@
+++
title = "Table caption"
tags = ["table", "caption"]
draft = false
+++

<caption class="table-caption">
<span class="table-number">Table 1:</span>
Awesome table
</caption>

| h1 | h2 | h3 |
|-----|-----|-----|
| abc | def | ghi |

Some text.

<caption class="table-caption">
<span class="table-number">Table 2:</span>
Another awesome table
</caption>

| h1 | h2 | h3 |
|-----|-----|-----|
| jkl | mno | pqr |

Some more text.

<caption class="table-caption">
<span class="table-number">Table 3:</span>
Third table
</caption>

| h1 | h2 | h3 |
|-----|-----|----|
| stu | vwx | yz |

0 comments on commit 71e1fdf

Please sign in to comment.