From 71e1fdfda5eb59cc3362b1afa3e67ed130b42aed Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Sat, 23 Dec 2017 12:20:07 -0500 Subject: [PATCH] Export table captions https://github.com/kaushalmodi/ox-hugo/issues/38 --- ox-blackfriday.el | 14 ++++++++- test/site/content-org/all-posts.org | 24 ++++++++++++++- test/site/content/posts/links-to-tables.md | 20 +++++++++--- test/site/content/posts/table-caption.md | 36 ++++++++++++++++++++++ 4 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 test/site/content/posts/table-caption.md diff --git a/ox-blackfriday.el b/ox-blackfriday.el index cc7793b..a764f16 100644 --- a/ox-blackfriday.el +++ b/ox-blackfriday.el @@ -675,6 +675,18 @@ contextual information." (if lbl (format "\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 "\n" + " Table %d:\n" + " %s\n" + "\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. @@ -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) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index ad165d2..0611834 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -523,6 +523,28 @@ sense. But hey, a test is a test./ | | | | | 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) @@ -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: diff --git a/test/site/content/posts/links-to-tables.md b/test/site/content/posts/links-to-tables.md index 8727b1b..14df3df 100644 --- a/test/site/content/posts/links-to-tables.md +++ b/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 +++ @@ -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): - + + + + Table 1: + Simple table 1 + | 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 @@ -93,13 +98,18 @@ blandit in. Here's another table: - + + + + Table 2: + Simple table 2 + | e | f | |---|---| | g | h | -**Here we refer to table [1](#org40b5987).** +**Here we refer to table [1](#org44317dc).** --- diff --git a/test/site/content/posts/table-caption.md b/test/site/content/posts/table-caption.md new file mode 100644 index 0000000..ad700f0 --- /dev/null +++ b/test/site/content/posts/table-caption.md @@ -0,0 +1,36 @@ ++++ +title = "Table caption" +tags = ["table", "caption"] +draft = false ++++ + + + Table 1: + Awesome table + + +| h1 | h2 | h3 | +|-----|-----|-----| +| abc | def | ghi | + +Some text. + + + Table 2: + Another awesome table + + +| h1 | h2 | h3 | +|-----|-----|-----| +| jkl | mno | pqr | + +Some more text. + + + Table 3: + Third table + + +| h1 | h2 | h3 | +|-----|-----|----| +| stu | vwx | yz |