Function: org-odt-do-format-code

org-odt-do-format-code is a byte-compiled function defined in ox-odt.el.gz.

Signature

(org-odt-do-format-code CODE INFO &optional LANG REFS RETAIN-LABELS NUM-START)

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-odt.el.gz
(defun org-odt-do-format-code
    (code info &optional lang refs retain-labels num-start)
  (let* ((lang (or (assoc-default lang org-src-lang-modes) lang))
	 (lang-mode (and lang (intern (format "%s-mode" lang))))
	 (code-lines (org-split-string code "\n"))
	 (code-length (length code-lines))
	 (use-htmlfontify-p (and (functionp lang-mode)
				 (plist-get info :odt-fontify-srcblocks)
				 (require 'htmlfontify nil t)
				 (fboundp 'htmlfontify-string)))
	 (code (if (not use-htmlfontify-p) code
		 (with-temp-buffer
		   (insert code)
		   (funcall lang-mode)
                   (font-lock-ensure)
		   (buffer-string))))
	 (fontifier (if use-htmlfontify-p 'org-odt-htmlfontify-string
		      'org-odt--encode-plain-text))
	 (par-style (if use-htmlfontify-p "OrgSrcBlock"
		      "OrgFixedWidthBlock"))
	 (i 0))
    (cl-assert (= code-length (length (org-split-string code "\n"))))
    (setq code
	  (org-export-format-code
	   code
	   (lambda (loc line-num ref)
	     (setq par-style
		   (concat par-style (and (= (cl-incf i) code-length)
					  "LastLine")))

	     (setq loc (concat loc (and ref retain-labels (format " (%s)" ref))))
	     (setq loc (funcall fontifier loc))
	     (when ref
	       (setq loc (org-odt--target loc (concat "coderef-" ref))))
	     (cl-assert par-style)
	     (setq loc (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
			       par-style loc))
	     (if (not line-num) loc
	       (format "\n<text:list-item>%s\n</text:list-item>" loc)))
	   num-start refs))
    (cond
     ((not num-start) code)
     ((= num-start 0)
      (format
       "\n<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>%s</text:list>"
       " text:continue-numbering=\"false\"" code))
     (t
      (format
       "\n<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>%s</text:list>"
       " text:continue-numbering=\"true\"" code)))))