summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNik Clayton <nik@ngo.org.uk>2019-06-04 12:41:27 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2019-06-07 23:32:11 +0200
commit380e2f7f82377a35c38618f68c4cd9073dc2b029 (patch)
tree2617bb19650fe396ab3bfc87e479e3be1ddabe12
parentded3d27b1468b878197e5fe55a70c5e13350ea27 (diff)
downloadorg-mode-380e2f7f82377a35c38618f68c4cd9073dc2b029.tar.gz
ox-html: Include the line number as a data attribute
* lisp/ox-html.el (org-html-do-format-code): If line numbers are enabled then include a data-ox-html-linenr attribute that contains this line's line number. This allows you to have more control over line number formatting and placement. For example, the following CSS hides the span that contains the line number, and uses a CSS :before property to position and format the line number with a border instead of a semi-colon separating content and line number. span.linenr { display: none; } code[data-ox-html-linenr]:before { content: attr(data-ox-html-linenr); display: inline-block; border-right: 1px solid; width: 1rem; text-align: right; } TINYCHANGE
-rw-r--r--lisp/ox-html.el6
1 files changed, 5 insertions, 1 deletions
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 157905e..f1c06e0 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2255,7 +2255,11 @@ line of code."
(format "<span class=\"linenr\">%s</span>"
(format num-fmt line-num)))
;; Transcoded src line.
- (format "<code>%s</code>" loc)
+ (format "<code%s>%s</code>"
+ (if num-start
+ (format " data-ox-html-linenr=\"%s\"" line-num)
+ "")
+ loc)
;; Add label, if needed.
(when (and ref retain-labels) (format " (%s)" ref))))
;; Mark transcoded line as an anchor, if needed.