>From 961c0b45ff3e5548df11fc3fe9274e913c467c65 Mon Sep 17 00:00:00 2001 From: Jens Lechtenboerger Date: Tue, 8 Oct 2019 20:15:06 +0200 Subject: [PATCH] ox-html: Control wrapping of source lines * lisp/ox-html.el (org-html-format-code, org-html-do-format-code): Use new export option :html-wrap-src-lines with variable org-html-wrap-src-lines to control whether source code lines should be wrapped in code elements or not. * doc/org-manual.org: Document the new option --- doc/org-manual.org | 3 ++- lisp/ox-html.el | 39 +++++++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index f2f059e77..68543d67c 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -10789,7 +10789,7 @@ environments and math templates. Inside Org mode, you can make use of some of the features of CDLaTeX mode. You need to install =cdlatex.el= and =texmathp.el= (the latter comes also with AUCTeX) using [[https://melpa.org/][MELPA]] with the [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Package-Installation.html][Emacs packaging system]] or alternatively from -[[https://staff.fnwi.uva.nl/c.dominik/Tools/cdlatex/]]. Do not use +[[https://staff.fnwi.uva.nl/c.dominik/Tools/cdlatex/]]. Do not use CDLaTeX mode itself under Org mode, but use the special version Org CDLaTeX minor mode that comes as part of Org. Turn it on for the current buffer with {{{kbd(M-x org-cdlatex-mode)}}}, or for all Org @@ -15753,6 +15753,7 @@ Settings]]), however, override everything. | ~:html-use-infojs~ | ~org-html-use-infojs~ | | ~:html-validation-link~ | ~org-html-validation-link~ | | ~:html-viewport~ | ~org-html-viewport~ | +| ~:html-wrap-src-lines~ | ~org-html-wrap-src-lines~ | | ~:html-xml-declaration~ | ~org-html-xml-declaration~ | **** LaTeX specific properties diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 882f82dcb..83d0fd2e9 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -172,6 +172,7 @@ (:html-table-row-open-tag nil nil org-html-table-row-open-tag) (:html-table-row-close-tag nil nil org-html-table-row-close-tag) (:html-xml-declaration nil nil org-html-xml-declaration) + (:html-wrap-src-lines nil nil org-html-wrap-src-lines) (:html-klipsify-src nil nil org-html-klipsify-src) (:html-klipse-css nil nil org-html-klipse-css) (:html-klipse-js nil nil org-html-klipse-js) @@ -932,6 +933,15 @@ in all modes you want. Then, use the command :group 'org-export-html :type 'string) +(defcustom org-html-wrap-src-lines nil + "If non-nil, wrap individual lines of source blocks in \"code\" elements. +In this case, add line number in attribute \"data-ox-html-linenr\" when line +numbers are enabled." + :group 'org-export-html + :package-version '(Org . "9.3") + :type 'boolean + :safe t) + ;;;; Table (defcustom org-html-table-default-attributes @@ -2231,14 +2241,15 @@ is the language used for CODE, as a string, or nil." (if (and beg end) (substring code beg end) code))))))))) (defun org-html-do-format-code - (code &optional lang refs retain-labels num-start) + (code &optional lang refs retain-labels num-start wrap-lines) "Format CODE string as source code. -Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are, -respectively, the language of the source code, as a string, an +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, and the number associated to the first -line of code." +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 @@ -2256,11 +2267,13 @@ line of code." (format "%s" (format num-fmt line-num))) ;; Transcoded src line. - (format "%s" - (if num-start - (format " data-ox-html-linenr=\"%s\"" line-num) - "") - loc) + (if wrap-lines + (format "%s" + (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. @@ -2281,8 +2294,10 @@ used as a communication channel." ;; Does the source block contain labels? (retain-labels (org-element-property :retain-labels element)) ;; Does it have line numbers? - (num-start (org-export-get-loc element info))) - (org-html-do-format-code code lang refs retain-labels num-start))) + (num-start (org-export-get-loc element info)) + ;; Should lines be wrapped in code elements? + (wrap-lines (plist-get info :html-wrap-src-lines))) + (org-html-do-format-code code lang refs retain-labels num-start wrap-lines))) ;;; Tables of Contents -- 2.17.1