diff --git a/ox-blackfriday.el b/ox-blackfriday.el
index 57088d6..162033b 100644
--- a/ox-blackfriday.el
+++ b/ox-blackfriday.el
@@ -418,6 +418,41 @@ Details: https://github.com/kaushalmodi/ox-hugo/issues/57."
;; It's not visible (because zero width), but it's there.
code))
+;;;; Get Reference
+(defun org-blackfriday--get-reference (elem info)
+ "Return a reference for ELEM using its ordinal if available.
+
+INFO is a plist used as a communication channel.
+
+If the ELEM doesn't have its `name' defined, nil is returned.
+
+Else, if the ELEM has its `caption' defined, a reference of the
+kind \"org-ELEM-ORDINAL\" is returned.
+
+Else, the random reference generated using
+`org-export-get-reference' is returned.
+
+The return value, if non-nil, is a string."
+ (let ((name-exists (org-element-property :name elem)))
+ ;; Reference cannot be created if #+name does not exist.
+ (when name-exists
+ (let ((elem-ordinal (org-export-get-ordinal ;This is nil if a code snippet has no caption
+ elem info
+ nil #'org-html--has-caption-p)))
+ (if elem-ordinal
+ (let* ((elem-type (org-element-type elem))
+ (prefix (cond
+ ((eq 'src-block elem-type)
+ "code-snippet")
+ ((eq 'table elem-type)
+ "table")
+ (t
+ (format "org-%s" (symbol-name elem-type))))))
+ (format "%s-%d" prefix elem-ordinal))
+ ;; Return the randomly generated Org reference if the
+ ;; element ordinal is nil.
+ (org-export-get-reference elem info))))))
+
;;; Transcode Functions
@@ -936,16 +971,15 @@ contextual information."
;; (message "[ox-bf-table DBG] In contents: %s" contents)
(let* ((rows (org-element-map table 'table-row 'identity info))
(no-header (= (length rows) 1)) ;No header if table has just 1 row
- (label (let ((lbl (and (org-element-property :name table)
- (org-export-get-reference table info))))
- (if lbl
- (format "\n\n" lbl)
- "")))
+ (table-ref (org-blackfriday--get-reference table info))
+ (table-anchor (if table-ref
+ (format "\n" table-ref)
+ ""))
(caption (org-export-get-caption table))
table-num
(caption-html (if (not caption)
""
- (let ((caption-prefix-fmt-str (org-html--translate "Table %d:" info))
+ (let ((caption-prefix (org-html--translate "Table" info))
(caption-str
(org-html-convert-special-strings ;Interpret em-dash, en-dash, etc.
(org-export-data-with-backend caption 'html info))))
@@ -953,10 +987,14 @@ contextual information."
table info
nil #'org-html--has-caption-p))
(format (concat "
\n"
- " %s\n"
+ " %s:\n"
" %s\n"
"
\n\n")
- (format caption-prefix-fmt-str table-num)
+ (if table-ref ;Hyperlink the table prefix + number
+ (format "%s %s"
+ table-ref caption-prefix table-num)
+ (format "%s %s"
+ caption-prefix table-num))
caption-str))))
(attr (org-export-read-attribute :attr_html table))
;; At the moment only the `class' attribute is supported in
@@ -1011,7 +1049,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 table-pre label caption-html tbl table-post)))
+ (concat table-pre table-anchor caption-html tbl table-post)))
;;;; Verse Block
(defun org-blackfriday-verse-block (_verse-block contents info)
diff --git a/ox-hugo.el b/ox-hugo.el
index adfc525..bb2c885 100644
--- a/ox-hugo.el
+++ b/ox-hugo.el
@@ -1075,9 +1075,7 @@ contents according to the current headline."
(org-export-toc-entry-backend 'hugo)
info)
(or (org-element-property :CUSTOM_ID headline)
- (org-hugo-slug title)
- ;; (org-export-get-reference headline info)
- )))
+ (org-hugo-slug title))))
(tags (and (plist-get info :with-tags)
(not (eq 'not-in-toc (plist-get info :with-tags)))
(let ((tags (org-export-get-tags headline info)))
@@ -1567,39 +1565,6 @@ INFO is a plist used as a communication channel."
;; (message "[ox-hugo DBG pandoc-enabled-bool] %S" pandoc-enabled-bool)
pandoc-enabled-bool))
-;;;; Get Reference
-(defun org-hugo--get-reference (elem info)
- "Return a reference for ELEM using its ordinal if available.
-
-INFO is a plist used as a communication channel.
-
-If the ELEM doesn't have its `name' defined, nil is returned.
-
-Else, if the ELEM has its `caption' defined, a reference of the
-kind \"org-ELEM-ORDINAL\" is returned.
-
-Else, the random reference generated using
-`org-export-get-reference' is returned.
-
-The return value, if non-nil, is a string."
- (let ((name-exists (org-element-property :name elem)))
- ;; Reference cannot be created if #+name does not exist.
- (when name-exists
- (let ((elem-ordinal (org-export-get-ordinal ;This is nil if a code snippet has no caption
- elem info
- nil #'org-html--has-caption-p)))
- (if elem-ordinal
- (let* ((elem-type (org-element-type elem))
- (prefix (cond
- ((eq 'src-block elem-type)
- "code-snippet")
- (t
- (format "org-%s" (symbol-name elem-type))))))
- (format "%s-%d" prefix elem-ordinal))
- ;; Return the randomly generated Org reference if the
- ;; element ordinal is nil.
- (org-export-get-reference elem info))))))
-
;;; Transcode Functions
@@ -1738,9 +1703,7 @@ a communication channel."
(t
(let ((anchor (format "{#%s}" ;https://gohugo.io/extras/crossreferences/
(or (org-element-property :CUSTOM_ID headline)
- (org-hugo-slug title)
- ;; (org-export-get-reference headline info)
- )))
+ (org-hugo-slug title))))
(loffset (string-to-number (plist-get info :hugo-level-offset))) ;"" -> 0, "0" -> 0, "1" -> 1, ..
(todo (when todo
(concat (org-hugo--todo todo info) " "))))
@@ -1948,9 +1911,7 @@ and rewrite link paths to make blogging more seamless."
title))
;; Reference
(or (org-element-property :CUSTOM_ID destination)
- (org-hugo-slug title)
- ;; (org-export-get-reference destination info)
- ))))
+ (org-hugo-slug title)))))
(_
(let ((description
(or (org-string-nw-p desc)
@@ -1968,8 +1929,8 @@ and rewrite link paths to make blogging more seamless."
(when description
(format "[%s](#%s)"
description
- (if (eq 'src-block (org-element-type destination))
- (org-hugo--get-reference destination info)
+ (if (memq (org-element-type destination) '(src-block table))
+ (org-blackfriday--get-reference destination info)
(org-export-get-reference destination info)))))))))
((org-export-inline-image-p link org-html-inline-image-rules)
;; (message "[ox-hugo-link DBG] Inline image: %s" raw-path)
@@ -2375,7 +2336,7 @@ channel."
(replace-regexp-in-string "," " " hl-lines)) ;"1,3-4" -> "1 3-4"
((numberp hl-lines)
(number-to-string hl-lines))))
- (src-ref (org-hugo--get-reference src-block info))
+ (src-ref (org-blackfriday--get-reference src-block info))
(src-anchor (if src-ref
(format "\n" src-ref)
""))
diff --git a/test/site/content/posts/links-to-tables.md b/test/site/content/posts/links-to-tables.md
index e4c7b48..24adcbb 100644
--- a/test/site/content/posts/links-to-tables.md
+++ b/test/site/content/posts/links-to-tables.md
@@ -31,10 +31,9 @@ Here's another table:
will output below (_lorem-ipsum_ added to increase page content so
that the link jump is evident):
-
-
+
-
Table 1:
+
Table 1:
Simple table 1
@@ -42,7 +41,7 @@ that the link jump is evident):
|---|---|
| c | d |
-**Here we refer to table [2](#org8cdb51c).**
+**Here we refer to table [2](#table-2).**
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque et
quam metus. Etiam in iaculis mi, sit amet pretium magna. Donec ut dui
@@ -98,10 +97,9 @@ blandit in.
Here's another table:
-
-
+
-
Table 2:
+
Table 2:
Simple table 2
@@ -109,7 +107,7 @@ Here's another table:
|---|---|
| g | h |
-**Here we refer to table [1](#orgc7b6804).**
+**Here we refer to table [1](#table-1).**
---
diff --git a/test/site/content/posts/table-caption.md b/test/site/content/posts/table-caption.md
index 332c5ff..f678520 100644
--- a/test/site/content/posts/table-caption.md
+++ b/test/site/content/posts/table-caption.md
@@ -8,7 +8,7 @@ The caption can contain be emphasized using the usual markup
characters too.
- Table 1:
+ Table 1:
Awesome table
@@ -19,7 +19,7 @@ characters too.
Some text.
- Table 2:
+ Table 2:
Another awesome table
@@ -30,7 +30,7 @@ Some text.
Some more text.
- Table 3:
+ Table 3:
Third table — Caption with em-dash – and – en-dash
diff --git a/test/site/content/posts/table-styling.md b/test/site/content/posts/table-styling.md
index 5a71149..2927f3e 100644
--- a/test/site/content/posts/table-styling.md
+++ b/test/site/content/posts/table-styling.md
@@ -81,7 +81,7 @@ specified CSS attribute is auto-set for `.my-table-2 table`.
- Table 1:
+ Table 1:
Table with caption, with left-aligned text
@@ -101,7 +101,7 @@ specified CSS attribute is auto-set for `.table-1 table`.
- Table 2:
+ Table 2:
Table with caption, with right-aligned text
@@ -117,7 +117,7 @@ specified CSS attribute is auto-set for `.table-1 table`.
- Table 3:
+ Table 3:
Table with caption, with center-aligned text
@@ -136,7 +136,7 @@ specified CSS attribute is auto-set for `.table-1 table`.
- Table 4:
+ Table 4:
Table with caption, class and CSS attributes specified
@@ -184,7 +184,7 @@ block.
- Table 5:
+ Table 5:
Table with verbatim CSS
@@ -217,7 +217,7 @@ block.
- Table 6:
+ Table 6:
Table with uncollapsed borders
@@ -242,7 +242,7 @@ block.
- Table 7:
+ Table 7:
Table with collapsed borders
@@ -280,7 +280,7 @@ block.
- Table 8:
+ Table 8:
Table with 1st row and 1st column highlighted
@@ -315,7 +315,7 @@ block.
- Table 9:
+ Table 9:
Sane Table — with minimal styling
@@ -340,7 +340,7 @@ block.
- Table 10:
+ Table 10:
Table with zebra striping
@@ -369,7 +369,7 @@ block.
- Table 11:
+ Table 11:
Table where the hovered-upon cell highlights
@@ -395,7 +395,7 @@ block.
- Table 12:
+ Table 12:
Table where the hovered-upon row highlights
@@ -525,7 +525,7 @@ _Let's-go-ballistic-with-CSS_ Edition :smile:
- Table 13:
+ Table 13:
Table where rows except the hovered-upon get blurred