From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yoshinari Nomura Subject: Re: Add figure/table numbers to HTML captions Date: Sat, 29 Jun 2013 16:01:15 +0900 (JST) Message-ID: <20130629.160115.263707471452837649.nom@quickhack.net> References: <87li5vsjb8.fsf@gmail.com> <20130628.101530.1683355082328893107.nom@quickhack.net> <87ppv6r3ky.fsf@gmail.com> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sat_Jun_29_16_01_15_2013_448)--" Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UspA6-0002BK-LU for emacs-orgmode@gnu.org; Sat, 29 Jun 2013 03:01:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UspA3-0004QC-Ck for emacs-orgmode@gnu.org; Sat, 29 Jun 2013 03:01:34 -0400 Received: from vintage.swlab.cs.okayama-u.ac.jp ([150.46.8.117]:62113) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UspA2-0004Px-Jg for emacs-orgmode@gnu.org; Sat, 29 Jun 2013 03:01:31 -0400 In-Reply-To: <87ppv6r3ky.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: n.goaziou@gmail.com Cc: emacs-orgmode@gnu.org ----Next_Part(Sat_Jun_29_16_01_15_2013_448)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello Nicolas, >> I'll revise my patch in this weekend. thanks. I've split my work into these three commits: 0001-ox-html-add-figure-and-table-numbers-to-HTML-caption.patch 0002-ox-add-dictionary-entry-for-numbered-figures.patch 0003-ox-add-Japanese-translations-for-figures-and-tables.patch (enclosed in the attachments) I've also pushed them to my github repository: git@github.com:yoshinari-nomura/org-mode.git branch: tab-and-fig-number-to-ox-html Please check the commits. I'm willing to revise them again if needed. Thanks for your great effort to tidy-up my rough work. Regards, -- Yoshinari Nomura https://github.com/yoshinari-nomura commit a82e712c3d60d8b58e2cffe13d5cbcdfa25ede24 Author: Yoshinari Nomura Date: Sat Jun 29 15:06:49 2013 +0900 ox: add Japanese translations for figures and tables * lisp/ox.el: (org-export-dictionary): Add Japanese translations for figures and tables commit faced47cb6d049cbb4b6323556543bd86e32884d Author: Yoshinari Nomura Date: Sat Jun 29 15:02:41 2013 +0900 ox: add dictionary entry for numbered figures * lisp/ox.el: (org-export-dictionary): Add "Figure %d:" entry in the same manner with "Table %d:". commit 793f69627fa290c95d41c0af9792fdafdda98b06 Author: Yoshinari Nomura Date: Sat Jun 29 14:44:52 2013 +0900 ox-html: add figure and table numbers to HTML captions * lisp/ox-html.el: (org-html--has-caption-p): New function. (org-html-link--inline-image), (org-html-table): Prepend ordinal number to caption. (org-html-link): Make numbered link by counting captioned figures and tables. ----Next_Part(Sat_Jun_29_16_01_15_2013_448)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0001-ox-html-add-figure-and-table-numbers-to-HTML-caption.patch" >From 793f69627fa290c95d41c0af9792fdafdda98b06 Mon Sep 17 00:00:00 2001 From: Yoshinari Nomura Date: Sat, 29 Jun 2013 14:44:52 +0900 Subject: [PATCH 1/3] ox-html: add figure and table numbers to HTML captions * lisp/ox-html.el: (org-html--has-caption-p): New function. (org-html-link--inline-image), (org-html-table): Prepend ordinal number to caption. (org-html-link): Make numbered link by counting captioned figures and tables. --- lisp/ox-html.el | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index a996b40..30b23ca 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1370,6 +1370,13 @@ (defun org-html--textarea-block (element) (or (plist-get attr :height) (org-count-lines code)) code))) +(defun org-html--has-caption-p (element &optional info) + "Non-nil when ELEMENT has a caption affiliated keyword. +INFO is a plist used as a communication channel. This function +is meant to be used as a predicate for `org-export-get-ordinal' or +a value to `org-html-standalone-image-predicate'." + (org-element-property :caption element)) + ;;;; Table (defun org-html-htmlize-region-for-paste (beg end) @@ -2532,7 +2539,15 @@ (defun org-html-link--inline-image (link desc info) (expand-file-name raw-path)) (t raw-path))) (parent (org-export-get-parent-element link)) - (caption (org-export-data (org-export-get-caption parent) info)) + (caption + (let ((raw (org-export-data (org-export-get-caption parent) info)) + (org-html-standalone-image-predicate 'org-html--has-caption-p)) + (if (org-string-nw-p raw) + (concat (format (org-html--translate "Figure %d:" info) + (org-export-get-ordinal + link info nil 'org-html-standalone-image-p)) + " " raw) + raw))) (label (org-element-property :name parent))) ;; Return proper string, depending on DISPOSITION. (org-html-format-inline-image @@ -2725,14 +2740,19 @@ (defun org-html-link (link desc info) (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 + (if (org-html--has-caption-p destination) + 'org-html--has-caption-p)) + (org-html-standalone-image-predicate caption-predicate)) (unless desc (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 +3165,8 @@ (defun org-html-table (table contents info) (t (let* ((label (org-element-property :name table)) (caption (org-export-get-caption table)) + (number (org-export-get-ordinal + table info nil 'org-html--has-caption-p)) (attributes (if (org-html-html5-p info) "" (org-html--make-attribute-string @@ -3183,7 +3205,9 @@ (defun org-html-table (table contents info) (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))))) -- 1.8.2.1 ----Next_Part(Sat_Jun_29_16_01_15_2013_448)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0002-ox-add-dictionary-entry-for-numbered-figures.patch" >From faced47cb6d049cbb4b6323556543bd86e32884d Mon Sep 17 00:00:00 2001 From: Yoshinari Nomura Date: Sat, 29 Jun 2013 15:02:41 +0900 Subject: [PATCH 2/3] ox: add dictionary entry for numbered figures * lisp/ox.el: (org-export-dictionary): Add "Figure %d:" entry in the same manner with "Table %d:". --- lisp/ox.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lisp/ox.el b/lisp/ox.el index fb56da4..e50e888 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -5266,6 +5266,9 @@ (defconst org-export-dictionary ("Figure" ("de" :default "Abbildung") ("es" :default "Figura")) + ("Figure %d:" + ("de" :default "Abbildung %d:") + ("es" :default "Figura %d:")) ("Footnotes" ("ca" :html "Peus de pàgina") ("cs" :default "Pozn\xe1mky pod carou") -- 1.8.2.1 ----Next_Part(Sat_Jun_29_16_01_15_2013_448)-- Content-Type: Text/X-Patch; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="0003-ox-add-Japanese-translations-for-figures-and-tables.patch" From=20a82e712c3d60d8b58e2cffe13d5cbcdfa25ede24 Mon Sep 17 00:00:00 200= 1 From: Yoshinari Nomura Date: Sat, 29 Jun 2013 15:06:49 +0900 Subject: [PATCH 3/3] ox: add Japanese translations for figures and tabl= es * lisp/ox.el: (org-export-dictionary): Add Japanese translations for figures and tables --- lisp/ox.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index e50e888..1133f21 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -5265,10 +5265,12 @@ (defconst org-export-dictionary ("fr" :ascii "Equation" :default "=C3=89quation")) ("Figure" ("de" :default "Abbildung") - ("es" :default "Figura")) + ("es" :default "Figura") + ("ja" :html "図" :utf-8 "=E5=9B=B3")) ("Figure %d:" ("de" :default "Abbildung %d:") - ("es" :default "Figura %d:")) + ("es" :default "Figura %d:") + ("ja" :html "図%d:" :utf-8 "=E5=9B=B3%d:")) ("Footnotes" ("ca" :html "Peus de pàgina") ("cs" :default "Pozn\xe1mky pod carou") @@ -5315,7 +5317,8 @@ (defconst org-export-dictionary ("de" :default "Tabelle %d") ("es" :default "Tabla %d") ("fr" - :ascii "Tableau %d :" :default "Tableau n=C2=BA %d :" :latin1 "T= ableau %d :")) + :ascii "Tableau %d :" :default "Tableau n=C2=BA %d :" :latin1 "T= ableau %d :") + ("ja" :html "表%d:" :utf-8 "=E8=A1=A8%d:")) ("Table of Contents" ("ca" :html "Índex") ("cs" :default "Obsah") -- = 1.8.2.1 ----Next_Part(Sat_Jun_29_16_01_15_2013_448)----