summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-08-22 22:07:34 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-08-22 22:07:34 +0200
commit579569cc84fad3991182e4a33cc94eb6099d20c6 (patch)
treeea62381697cf555a3827cc344acb8bf7a81c3795
parent908b3b05cdf2e53dda5bef72d5334686e154bb85 (diff)
downloadorg-mode-579569cc84fad3991182e4a33cc94eb6099d20c6.tar.gz
ox-html: Number source blocks with listings
* 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 <clement.pit@gmail.com> <http://permalink.gmane.org/gmane.emacs.orgmode/108808>
-rw-r--r--etc/ORG-NEWS5
-rw-r--r--lisp/ox-html.el24
2 files changed, 22 insertions, 7 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 27b6ac9..320627a 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.,
~<a href="#name">text</a>~.
+**** 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 5f02f25..beff484 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 "<pre class=\"example\"%s>\n%s</pre>" label code)
- (format
- "<div class=\"org-src-container\">\n%s%s\n</div>"
- (if (not caption) ""
- (format "<label class=\"org-src-name\">%s</label>"
- (org-export-data caption info)))
- (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
+ (format "<div class=\"org-src-container\">\n%s%s\n</div>"
+ ;; Build caption.
+ (let ((caption (org-export-get-caption src-block)))
+ (if (not caption) ""
+ (let ((listing-number
+ (format
+ "<span class=\"listing-number\">%s </span>"
+ (format
+ (org-html--translate "Listing %d:" info)
+ (org-export-get-ordinal
+ src-block info nil #'org-html--has-caption-p)))))
+ (format "<label class=\"org-src-name\">%s%s</label>"
+ listing-number
+ (org-trim (org-export-data caption info))))))
+ ;; Contents.
+ (format "<pre class=\"src src-%s\"%s>%s</pre>"
+ lang label code))))))
;;;; Statistics Cookie