From 579569cc84fad3991182e4a33cc94eb6099d20c6 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 22 Aug 2016 22:07:34 +0200 Subject: [PATCH] ox-html: Number source blocks with listings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lisp/ox-html.el (org-html-src-block): Number source block if it has a caption. Numbering is done among source blocks with a caption, only. Suggested-by: Clément Pit--Claudel --- etc/ORG-NEWS | 5 +++++ lisp/ox-html.el | 24 +++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 27b6ac964..320627a6b 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -189,6 +189,11 @@ If the block has a =#+NAME:= attribute assigned, then the HTML element will have an ~id~ attribute with that name in the HTML export. This enables one to create links to these elements in other places, e.g., ~text~. +**** Listings with captions are now numbered in HTML export +The class associated to the numbering is "listing-number". If you +don't want these blocks to be numbered, as it was the case until now, +You may want to add ~.listing-number { display: none; }~ to the CSS +used. **** Line Numbering in SRC/EXAMPLE blocks support arbitrary start number The ~-n~ option to ~SRC~ and ~EXAMPLE~ blocks can now take a numeric argument to specify the staring line number for the source or example diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 5f02f2517..beff484ce 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -3319,18 +3319,28 @@ contextual information." (if (org-export-read-attribute :attr_html src-block :textarea) (org-html--textarea-block src-block) (let ((lang (org-element-property :language src-block)) - (caption (org-export-get-caption src-block)) (code (org-html-format-code src-block info)) (label (let ((lbl (and (org-element-property :name src-block) (org-export-get-reference src-block info)))) (if lbl (format " id=\"%s\"" lbl) "")))) (if (not lang) (format "
\n%s
" label code) - (format - "
\n%s%s\n
" - (if (not caption) "" - (format "" - (org-export-data caption info))) - (format "\n
%s
" lang label code)))))) + (format "
\n%s%s\n
" + ;; Build caption. + (let ((caption (org-export-get-caption src-block))) + (if (not caption) "" + (let ((listing-number + (format + "%s " + (format + (org-html--translate "Listing %d:" info) + (org-export-get-ordinal + src-block info nil #'org-html--has-caption-p))))) + (format "" + listing-number + (org-trim (org-export-data caption info)))))) + ;; Contents. + (format "
%s
" + lang label code)))))) ;;;; Statistics Cookie