all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] ox-html: add option to restore old src block behaviour?
@ 2019-09-21 12:15 Jens Lechtenboerger
  2019-10-03  0:16 ` Matt Price
  2019-10-08  9:31 ` Nicolas Goaziou
  0 siblings, 2 replies; 7+ messages in thread
From: Jens Lechtenboerger @ 2019-09-21 12:15 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 906 bytes --]

On 2019-09-19, Matt Price wrote:

> Over the summer, commit ded3d27b1468b878197e5fe55a70c5e13350ea27
> by Nik Clayton was merged to master. It's a one-line change that
> adds new ~<code>~ tags around each lin of code in html export of
> source blocks.  It's useful because it allows individual lines to
> be addressed directly by CSS.
>
> However, at least one very common syntax highlighter,
> https://highlinghtjs.org, expects just a single <code> tag, as do
> other common CSS frameworks.
> [...]

The attached patch adds a new variable org-html-wrap-src-lines to
control whether code tags should be added or not.

I’m not sure whether :package-version 9.3 is correct.  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?

Best wishes
Jens


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html-Control-source-line-wrapping.patch --]
[-- Type: text/x-diff, Size: 1923 bytes --]

From ba3130deb9dbbab3c7d293f901ff08be839a8a9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jens=20Lechtenb=C3=B6rger?= <jens.lechtenboerger@fsfe.org>
Date: Sat, 21 Sep 2019 12:01:59 +0200
Subject: [PATCH] ox-html: Control source line wrapping

* list/ox-html.el (org-html-do-format-code): Use new variable
  org-html-wrap-src-lines to control whether source code lines should
  be wrapped in code elements or not.

Allow to revert to behavior before commit
ded3d27b1468b878197e5fe55a70c5e13350ea27.
---
 lisp/ox-html.el | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 757006321..969e649fc 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -932,6 +932,14 @@ in all modes you want.  Then, use the command
   :group 'org-export-html
   :type 'string)
 
+(defcustom org-html-wrap-src-lines t
+  "If t, 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)
+
 ;;;; Table
 
 (defcustom org-html-table-default-attributes
@@ -2256,11 +2264,13 @@ line of code."
 		(format "<span class=\"linenr\">%s</span>"
 			(format num-fmt line-num)))
 	      ;; Transcoded src line.
-	      (format "<code%s>%s</code>"
-                      (if num-start
-                          (format " data-ox-html-linenr=\"%s\"" line-num)
-                        "")
-                      loc)
+	      (if org-html-wrap-src-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.
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] ox-html: add option to restore old src block behaviour?
  2019-09-21 12:15 [PATCH] ox-html: add option to restore old src block behaviour? Jens Lechtenboerger
@ 2019-10-03  0:16 ` Matt Price
  2019-10-08  9:31 ` Nicolas Goaziou
  1 sibling, 0 replies; 7+ messages in thread
From: Matt Price @ 2019-10-03  0:16 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 1109 bytes --]

So I'm pretty interested in this: what to others thi k?

On Sat., Sep. 21, 2019, 8:16 a.m. Jens Lechtenboerger, <
jens.lechtenboerger@fsfe.org> wrote:

> On 2019-09-19, Matt Price wrote:
>
> > Over the summer, commit ded3d27b1468b878197e5fe55a70c5e13350ea27
> > by Nik Clayton was merged to master. It's a one-line change that
> > adds new ~<code>~ tags around each lin of code in html export of
> > source blocks.  It's useful because it allows individual lines to
> > be addressed directly by CSS.
> >
> > However, at least one very common syntax highlighter,
> > https://highlinghtjs.org, expects just a single <code> tag, as do
> > other common CSS frameworks.
> > [...]
>
> The attached patch adds a new variable org-html-wrap-src-lines to
> control whether code tags should be added or not.
>
> I’m not sure whether :package-version 9.3 is correct.  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?
>
> Best wishes
> Jens
>
>

[-- Attachment #2: Type: text/html, Size: 1578 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] ox-html: add option to restore old src block behaviour?
  2019-09-21 12:15 [PATCH] ox-html: add option to restore old src block behaviour? Jens Lechtenboerger
  2019-10-03  0:16 ` Matt Price
@ 2019-10-08  9:31 ` Nicolas Goaziou
  2019-10-08 18:40   ` Jens Lechtenboerger
  1 sibling, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2019-10-08  9:31 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Jens Lechtenboerger <jens.lechtenboerger@fsfe.org> 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.

Also, this would need an entry in the manual, if only in the "options
for the exporters" subsection.

> I’m not sure whether :package-version 9.3 is correct.

It is correct. You can also use :safe t.

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

> +(defcustom org-html-wrap-src-lines t
> +  "If t, wrap individual lines of source blocks in \"code\" elements.

When non-nil, wrap...


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] ox-html: add option to restore old src block behaviour?
  2019-10-08  9:31 ` Nicolas Goaziou
@ 2019-10-08 18:40   ` Jens Lechtenboerger
  2019-10-13  7:30     ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Jens Lechtenboerger @ 2019-10-08 18:40 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1474 bytes --]

On 2019-10-08, at 11:31, Nicolas Goaziou wrote:

> Jens Lechtenboerger <jens.lechtenboerger@fsfe.org> 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’m 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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html-Control-wrapping-of-source-lines.patch --]
[-- Type: text/x-diff, Size: 5583 bytes --]

From 961c0b45ff3e5548df11fc3fe9274e913c467c65 Mon Sep 17 00:00:00 2001
From: Jens Lechtenboerger <jens.lechtenboerger@fsfe.org>
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 "<span class=\"linenr\">%s</span>"
 			(format num-fmt line-num)))
 	      ;; Transcoded src line.
-	      (format "<code%s>%s</code>"
-                      (if num-start
-                          (format " data-ox-html-linenr=\"%s\"" line-num)
-                        "")
-                      loc)
+	      (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.
@@ -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)))
 
 \f
 ;;; Tables of Contents
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] ox-html: add option to restore old src block behaviour?
  2019-10-08 18:40   ` Jens Lechtenboerger
@ 2019-10-13  7:30     ` Nicolas Goaziou
  2019-10-13 12:16       ` Jens Lechtenboerger
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2019-10-13  7:30 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Jens Lechtenboerger <jens.lechtenboerger@fsfe.org> writes:

> 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

Applied. Would you mind adding an ORG-NEWS entry about it?

Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] ox-html: add option to restore old src block behaviour?
  2019-10-13  7:30     ` Nicolas Goaziou
@ 2019-10-13 12:16       ` Jens Lechtenboerger
  2019-10-16 17:06         ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Jens Lechtenboerger @ 2019-10-13 12:16 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 585 bytes --]

On 2019-10-13, at 09:30, Nicolas Goaziou wrote:

> Jens Lechtenboerger <jens.lechtenboerger@fsfe.org> writes:
>
>> 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
>
> Applied. Would you mind adding an ORG-NEWS entry about it?

Thanks!  A patch is attached.

Best wishes
Jens


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Mention-option-html-wrap-src-lines-in-ORG-NEWS.patch --]
[-- Type: text/x-diff, Size: 950 bytes --]

From f2f93c573fef6a079c2f7f434e6c65d51e2f0906 Mon Sep 17 00:00:00 2001
From: Jens Lechtenboerger <jens.lechtenboerger@fsfe.org>
Date: Sun, 13 Oct 2019 14:06:09 +0200
Subject: [PATCH] Mention option html-wrap-src-lines in ORG-NEWS

* etc/ORG-NEWS: Mention new option html-wrap-src-lines.
---
 etc/ORG-NEWS | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 9fff4ad16..0e07326cb 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -123,6 +123,12 @@ auto-commit attachments to git:
   one need to require the =org-attach-git= module in the startup.
 
 ** New features
+*** New option to wrap source code lines in HTML export
+
+When new option ~html-wrap-src-lines~ (with variable
+~org-html-wrap-src-lines~) is non-nil, HTML export wraps source code
+lines in HTML ~code~ elements.
+
 *** New option to handle schedules and deadlines in iCalendar export
 
 Export ignore done tasks with a deadline when
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] ox-html: add option to restore old src block behaviour?
  2019-10-13 12:16       ` Jens Lechtenboerger
@ 2019-10-16 17:06         ` Nicolas Goaziou
  0 siblings, 0 replies; 7+ messages in thread
From: Nicolas Goaziou @ 2019-10-16 17:06 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Jens Lechtenboerger <jens.lechtenboerger@fsfe.org> writes:

> Thanks!  A patch is attached.

Applied. Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-10-16 17:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-21 12:15 [PATCH] ox-html: add option to restore old src block behaviour? Jens Lechtenboerger
2019-10-03  0:16 ` Matt Price
2019-10-08  9:31 ` Nicolas Goaziou
2019-10-08 18:40   ` Jens Lechtenboerger
2019-10-13  7:30     ` Nicolas Goaziou
2019-10-13 12:16       ` Jens Lechtenboerger
2019-10-16 17:06         ` Nicolas Goaziou

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.