From b406e083af930644017d84144554b992cf8a788f Mon Sep 17 00:00:00 2001 From: Yoshinari Nomura Date: Thu, 27 Jun 2013 18:15:36 +0900 Subject: [PATCH] Add figure/table numbers to HTML captions --- lisp/ox-html.el | 29 ++++++++++++++++++++++++++--- lisp/ox.el | 10 ++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index a996b40..7217eab 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2534,6 +2534,15 @@ Inline images can have these attributes: (parent (org-export-get-parent-element link)) (caption (org-export-data (org-export-get-caption parent) info)) (label (org-element-property :name parent))) + (unless (string= caption "") + (let* ((org-html-standalone-image-predicate + (lambda (img) (org-element-property :caption img))) + (number (org-export-get-ordinal + link info nil 'org-html-standalone-image-p))) + (setq caption + (concat + (format (org-html--translate "Figure %d:" info) number) + " " caption)))) ;; Return proper string, depending on DISPOSITION. (org-html-format-inline-image path info caption label @@ -2725,14 +2734,23 @@ INFO is a plist holding contextual information. See (org-export-solidify-link-text href) attributes desc))) ;; Fuzzy link points to a target. Do as above. (t - (let ((path (org-export-solidify-link-text path)) number) + (let ((path (org-export-solidify-link-text path)) number + caption-predicate org-html-standalone-image-predicate) (unless desc + (setq caption-predicate + (if (org-element-property :caption destination) + (lambda (elem &optional info) + (org-element-property :caption elem)) + (lambda (elem &optional info) + (not (org-element-property :caption elem))))) + (setq org-html-standalone-image-predicate caption-predicate) (setq number (cond ((org-html-standalone-image-p destination info) (org-export-get-ordinal (assoc 'link (org-element-contents destination)) info 'link 'org-html-standalone-image-p)) - (t (org-export-get-ordinal destination info)))) + (t (org-export-get-ordinal + destination info nil caption-predicate)))) (setq desc (when number (if (atom number) (number-to-string number) (mapconcat 'number-to-string number "."))))) @@ -3145,6 +3163,9 @@ contextual information." (t (let* ((label (org-element-property :name table)) (caption (org-export-get-caption table)) + (number (org-export-get-ordinal + table info nil + (lambda (tbl info) (org-element-property :caption tbl)))) (attributes (if (org-html-html5-p info) "" (org-html--make-attribute-string @@ -3183,7 +3204,9 @@ contextual information." (format (if org-html-table-caption-above "%s" "%s") - (org-export-data caption info))) + (concat + (format (org-html--translate "Table %d:" info) number) + " " (org-export-data caption info)))) (funcall table-column-specs table info) contents))))) diff --git a/lisp/ox.el b/lisp/ox.el index fb56da4..1133f21 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -5265,7 +5265,12 @@ them." ("fr" :ascii "Equation" :default "Équation")) ("Figure" ("de" :default "Abbildung") - ("es" :default "Figura")) + ("es" :default "Figura") + ("ja" :html "図" :utf-8 "図")) + ("Figure %d:" + ("de" :default "Abbildung %d:") + ("es" :default "Figura %d:") + ("ja" :html "図%d:" :utf-8 "図%d:")) ("Footnotes" ("ca" :html "Peus de pàgina") ("cs" :default "Pozn\xe1mky pod carou") @@ -5312,7 +5317,8 @@ them." ("de" :default "Tabelle %d") ("es" :default "Tabla %d") ("fr" - :ascii "Tableau %d :" :default "Tableau nº %d :" :latin1 "Tableau %d :")) + :ascii "Tableau %d :" :default "Tableau nº %d :" :latin1 "Tableau %d :") + ("ja" :html "表%d:" :utf-8 "表%d:")) ("Table of Contents" ("ca" :html "Índex") ("cs" :default "Obsah") -- 1.8.2.1