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
This commit is contained in:
Nik Clayton 2019-06-04 12:41:27 +02:00 committed by Nicolas Goaziou
parent ded3d27b14
commit 380e2f7f82

View file

@ -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.