From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jens Lechtenboerger Subject: Re: [PATCH] ox-html: add option to restore old src block behaviour? Date: Tue, 08 Oct 2019 20:40:22 +0200 Message-ID: <87wodfozc9.fsf@informationelle-selbstbestimmung-im-internet.de> References: <87h8553kwm.fsf@informationelle-selbstbestimmung-im-internet.de> <87eezneg76.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:40376) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHuPQ-0001YU-NH for emacs-orgmode@gnu.org; Tue, 08 Oct 2019 14:40:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHuPO-0003iy-Qw for emacs-orgmode@gnu.org; Tue, 08 Oct 2019 14:40:32 -0400 Received: from mx2a.mailbox.org ([80.241.60.219]:34147) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iHuPO-0003h4-D8 for emacs-orgmode@gnu.org; Tue, 08 Oct 2019 14:40:30 -0400 Received: from smtp2.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2a.mailbox.org (Postfix) with ESMTPS id 9658FA336B for ; Tue, 8 Oct 2019 20:40:27 +0200 (CEST) Received: from smtp2.mailbox.org ([80.241.60.240]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id nqHKUkBQllwN for ; Tue, 8 Oct 2019 20:40:23 +0200 (CEST) In-Reply-To: <87eezneg76.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Tue, 08 Oct 2019 11:31:41 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2019-10-08, at 11:31, Nicolas Goaziou wrote: > Jens Lechtenboerger writes: > >> The attached patch adds a new variable org-html-wrap-src-lines to >> control whether code tags should be added or not. > > Thank you. > > However, the patch is not right. Exporters do not use defcustoms > directly. Instead, you register them within :options-alist in the the > back-end definition, e.g., under :html-wrap-src-lines and then call > (plist-get info :html-wrap-src-lines) in the function. This allows to > control these options during publishing. Indeed, sorry. Many thanks for the detailed feedback! I had to change the calling function org-html-format-code and add an argument to org-html-do-format-code as info is not available in the latter function. > Also, this would need an entry in the manual, if only in the "options > for the exporters" subsection. Done. >> I=E2=80=99m not sure whether :package-version 9.3 is correct. > > It is correct. You can also use :safe t. Added. >> Also, I set the value to t, which does not change the current >> functionality. However, for backwards compatibility (up to version >> 9.2.6), a value of nil would be preferable. Any thoughts? > > I agree with the nil default value. Done. >> +(defcustom org-html-wrap-src-lines t >> + "If t, wrap individual lines of source blocks in \"code\" elements. > > When non-nil, wrap... Done. Best wishes Jens --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-ox-html-Control-wrapping-of-source-lines.patch >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 --=-=-=--