Function: org-html-do-format-code
org-html-do-format-code is a byte-compiled function defined in
ox-html.el.gz.
Signature
(org-html-do-format-code CODE &optional LANG REFS RETAIN-LABELS NUM-START WRAP-LINES)
Documentation
Format CODE string as source code.
Optional arguments LANG, REFS, RETAIN-LABELS, NUM-START, WRAP-LINES
are, respectively, the language of the source code, as a string, an
alist between line numbers and references (as returned by
org-export-unravel-code), a boolean specifying if labels should
appear in the source code, the number associated to the first
line of code, and a boolean specifying if lines of code should be
wrapped in code elements.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ox-html.el.gz
(defun org-html-do-format-code
(code &optional lang refs retain-labels num-start wrap-lines)
"Format CODE string as source code.
Optional arguments LANG, REFS, RETAIN-LABELS, NUM-START, WRAP-LINES
are, respectively, the language of the source code, as a string, an
alist between line numbers and references (as returned by
`org-export-unravel-code'), a boolean specifying if labels should
appear in the source code, the number associated to the first
line of code, and a boolean specifying if lines of code should be
wrapped in code elements."
(let* ((code-lines (split-string code "\n"))
(code-length (length code-lines))
(num-fmt
(and num-start
(format "%%%ds: "
(length (number-to-string (+ code-length num-start))))))
(code (org-html-fontify-code code lang)))
(org-export-format-code
code
(lambda (loc line-num ref)
(setq loc
(concat
;; Add line number, if needed.
(when num-start
(format "<span class=\"linenr\">%s</span>"
(format num-fmt line-num)))
;; Transcoded src line.
(if wrap-lines
(format "<code%s>%s</code>"
(if num-start
(format " data-ox-html-linenr=\"%s\"" line-num)
"")
loc)
loc)
;; Add label, if needed.
(when (and ref retain-labels) (format " (%s)" ref))))
;; Mark transcoded line as an anchor, if needed.
(if (not ref) loc
(format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
ref loc)))
num-start refs)))