emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ox-html.el: Fix display of language indicators for source blocks
@ 2017-06-06 15:20 N. Raghavendra
  2017-06-06 20:08 ` N. Raghavendra
  2017-06-08 18:57 ` N. Raghavendra
  0 siblings, 2 replies; 11+ messages in thread
From: N. Raghavendra @ 2017-06-06 15:20 UTC (permalink / raw)
  To: emacs-orgmode

CSS rules like

pre.src-awk:before { content: 'Awk'; }

in `org-html-style-default' don't work in the current Org version,
because the class attribute has been moved from the `pre' element to a
`code' child of that element.  As a result, the name of the language
isn't dipslayed when hovering over a source block in the HTML file.  I
am currently doing

(setq org-html-keep-old-src t)

but I think it's a kludge.

A better way out would be to move back the `class' attribute from the
`code' element to its `pre' parent in `org-src-html-block', or to change
the CSS selectors in `org-html-style-default'.  This patch does the
former.  (As for the latter, AFAIK there is no CSS selector which picks
precisely those `pre' elements that have `code' children with attributes
`src' and `src-LANG'.)

Cheers,
Raghu.

----------------------------------------------------------------------

* lisp/ox-html.el (org-html-src-block): Move the `class' attribute of
  the `code' element to its parent `pre' element.

TINYCHANGE
---
 lisp/ox-html.el | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 3ad3ffe..857775b 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -3394,12 +3394,17 @@ contextual information."
 			      listing-number
 			      (org-trim (org-export-data caption info))))))
 		;; Contents.
-		(let ((open (if org-html-keep-old-src "<pre" "<pre><code"))
+		(let ((open (format "<pre class=\"src src-%s\"%s>%s"
+				    lang label
+				    (if org-html-keep-old-src
+					""
+				      (format "<code%s>"
+					      (if (and klipsify
+						       (string= lang "html"))
+						  " data-editor-type=\"html\""
+						"")))))
 		      (close (if org-html-keep-old-src "</pre>" "</code></pre>")))
-		  (format "%s class=\"src src-%s\"%s%s>%s%s"
-			  open lang label (if (and klipsify (string= lang "html"))
-					      " data-editor-type=\"html\"" "")
-			  code close)))))))
+		  (concat open code close)))))))
 
 ;;;; Statistics Cookie
 
-- 
2.7.4

----------------------------------------------------------------------
-- 
N. Raghavendra <raghu@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/

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

end of thread, other threads:[~2017-09-19 20:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-06 15:20 [PATCH] ox-html.el: Fix display of language indicators for source blocks N. Raghavendra
2017-06-06 20:08 ` N. Raghavendra
2017-06-08 18:57 ` N. Raghavendra
2017-06-08 19:24   ` Nicolas Goaziou
2017-06-08 19:42     ` N. Raghavendra
2017-06-12 16:45       ` Matt Price
2017-06-14 17:32         ` N. Raghavendra
2017-09-19  0:54           ` N. Raghavendra
2017-09-19 17:18             ` N. Raghavendra
2017-09-19 20:02               ` Nicolas Goaziou
2017-06-08 20:15     ` Matt Price

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).