Re: [O] controlling how htmlize fontifies code
Hi Eric, Thanks for looking into this. Eric S Fraga e.fr...@ucl.ac.uk writes: Trying to fix this is definitely beyond my ability unfortunately. I may need to see how onerous it is to set the output type to css globally. Here's a simple fix, though I suspect Nicolas will have a more through solution up his sleeve. Of course, in org-html--build-head the mysterious :html-htmlized-css-url is required so you won't actually get any default colors, which is a bit boring in my opinion. I don't know if I'm misunderstanding :html-htmlized-css-url, a bug or something supposed to be set via a publish project. Rasmus -- This is the kind of tedious nonsense up with which I will not put From dcf2ba74fcfe68c4590f7f71ed8029c72a3c10ac Mon Sep 17 00:00:00 2001 From: Rasmus ras...@gmx.us Date: Tue, 4 Aug 2015 15:52:47 +0200 Subject: [PATCH 4/4] ox-html: Respect local values when formatting code * ox-html.el (org-html-fontify-code): Use local value of org-html-htmlize-output-type parent and org-html-htmlize-font-prefix parent. Reported-by: Eric S Fraga e.fr...@ucl.ac.uk http://permalink.gmane.org/gmane.emacs.orgmode/99450 --- lisp/ox-html.el | 44 +--- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index d454fab..87351a8 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2041,25 +2041,31 @@ is the language used for CODE, as a string, or nil. ;; Case 2: Default. Fontify code. (t ;; htmlize - (setq code (with-temp-buffer - ;; Switch to language-specific mode. - (funcall lang-mode) - (insert code) - ;; Fontify buffer. - (font-lock-ensure) - ;; Remove formatting on newline characters. - (save-excursion - (let ((beg (point-min)) - (end (point-max))) - (goto-char beg) - (while (progn (end-of-line) ( (point) end)) - (put-text-property (point) (1+ (point)) 'face nil) - (forward-char 1 - (org-src-mode) - (set-buffer-modified-p nil) - ;; Htmlize region. - (org-html-htmlize-region-for-paste - (point-min) (point-max + (setq code + (let ((parent (current-buffer))) + (with-temp-buffer + ;; Switch to language-specific mode. + (funcall lang-mode) + (insert code) + ;; Fontify buffer. + (font-lock-ensure) + ;; Remove formatting on newline characters. + (save-excursion + (let ((beg (point-min)) + (end (point-max))) + (goto-char beg) + (while (progn (end-of-line) ( (point) end)) + (put-text-property (point) (1+ (point)) 'face nil) + (forward-char 1 + (org-src-mode) + (set-buffer-modified-p nil) + ;; Htmlize region. + (let ((org-html-htmlize-output-type + (buffer-local-value 'org-html-htmlize-output-type parent)) + (org-html-htmlize-font-prefix + (buffer-local-value 'org-html-htmlize-font-prefix parent))) + (org-html-htmlize-region-for-paste + (point-min) (point-max)) ;; Strip any enclosing pre/pre tags. (let* ((beg (and (string-match \\`pre[^]*\n* code) (match-end 0))) (end (and beg (string-match /pre\\' code -- 2.5.0
Re: [O] controlling how htmlize fontifies code
On Monday, 3 Aug 2015 at 17:08, Rick Frankel wrote: [...] Both should work. Are you sure you have `org-export-allow-bind-keywords' set? Why wouldn't you expect local variables to work? Okay, I have tracked the problem down. Took some effort and boy did this test my not very extensive emacs lisp knowledge! I do need to learn how to use the Emacs debugger. Task for a rainy day... In any case, the problem is that the fontification happens (org-html-htmlize-output-type not nil) in org-html-fontify-code using with-temp-buffer which resets org-html-htmlize-output-type back to inline-css or whatever the global setting for that variable happens to be. So, basically, one can have code fontified with inline-css or not at all unless the output type is set to css globally. I hope this makes sense. Trying to fix this is definitely beyond my ability unfortunately. I may need to see how onerous it is to set the output type to css globally. Thanks again, eric -- : Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3beta-1315-ga3b2b7
Re: [O] controlling how htmlize fontifies code
On Monday, 3 Aug 2015 at 17:08, Rick Frankel wrote: [...] I have tried both setting a local variable and also using #+bind: but neither approach works for some reason. I did not expect the local variable setting to work, of course. Both should work. Are you sure you have `org-export-allow-bind-keywords' set? I do allow bind keywords. Strange. I'll investigate further with emacs -Q etc. I may post an ECM later. Why wouldn't you expect local variables to work? Because, if I understand correctly, the exporter processes the file into a different buffer which is then exported and locally set variables don't transfer to the new buffer. This is why I have used binding in the past. Maybe the new exporter is different? thanks, eric -- : Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3beta-1315-ga3b2b7
Re: [O] controlling how htmlize fontifies code
Hi, Nicolas Goaziou m...@nicolasgoaziou.fr writes: Not really, although I would write it like the following instead: (let ((output-type org-html-htmlize-output-type) (font-prefix org-html-htmlize-font-prefix)) (with-temp-buffer ... ;; Htmlize region. (let ((org-html-htmlize-output-type output-type) (org-html-htmlize-font-prefix font-prefix)) (org-html-htmlize-region-for-paste (point-min) (point-max) That might be ascetically nicer. Of course, in org-html--build-head the mysterious :html-htmlized-css-url is required so you won't actually get any default colors, which is a bit boring in my opinion. I don't know if I'm misunderstanding :html-htmlized-css-url, a bug or something supposed to be set via a publish project. I think there's a bug. `org-org-htmlized-css-url' is defined in ox-org.el, but not attached to any info property. So, at the moment, :html-htmlized-css-url is bogus. Do we have a function that can generate a candidate css file for org-org-htmlized-css-url or :html-htmlize-css-url? Rasmus -- Lasciate ogni speranza o voi che entrate: siete nella mani di'machellaio
Re: [O] controlling how htmlize fontifies code
Hello, Rasmus ras...@gmx.us writes: Here's a simple fix, Thank you. though I suspect Nicolas will have a more through solution up his sleeve. Not really, although I would write it like the following instead: (let ((output-type org-html-htmlize-output-type) (font-prefix org-html-htmlize-font-prefix)) (with-temp-buffer ... ;; Htmlize region. (let ((org-html-htmlize-output-type output-type) (org-html-htmlize-font-prefix font-prefix)) (org-html-htmlize-region-for-paste (point-min) (point-max) Of course, in org-html--build-head the mysterious :html-htmlized-css-url is required so you won't actually get any default colors, which is a bit boring in my opinion. I don't know if I'm misunderstanding :html-htmlized-css-url, a bug or something supposed to be set via a publish project. I think there's a bug. `org-org-htmlized-css-url' is defined in ox-org.el, but not attached to any info property. So, at the moment, :html-htmlized-css-url is bogus. Regards, -- Nicolas Goaziou
Re: [O] controlling how htmlize fontifies code
Rasmus ras...@gmx.us writes: Do we have a function that can generate a candidate css file for org-org-htmlized-css-url or :html-htmlize-css-url? There is `org-html-htmlize-generate-css'. Regards,
Re: [O] controlling how htmlize fontifies code
On Tuesday, 4 Aug 2015 at 17:09, Nicolas Goaziou wrote: [...] Not really, although I would write it like the following instead: (let ((output-type org-html-htmlize-output-type) (font-prefix org-html-htmlize-font-prefix)) (with-temp-buffer ... ;; Htmlize region. (let ((org-html-htmlize-output-type output-type) (org-html-htmlize-font-prefix font-prefix)) (org-html-htmlize-region-for-paste (point-min) (point-max) Thanks Nicolas. This works! (diffs attached) At least with the output type set as a local variable but not with #+bind which is perfectly fine as local variable use is what I would prefer. And thank you to Rasmus as well as I would imagine the suggested code changes would work as well. -- : Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3beta-1315-ga3b2b7 diff --git a/lisp/ox-html.el b/lisp/ox-html.el index d454fab..82e3b76 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2041,25 +2041,29 @@ is the language used for CODE, as a string, or nil. ;; Case 2: Default. Fontify code. (t ;; htmlize - (setq code (with-temp-buffer - ;; Switch to language-specific mode. - (funcall lang-mode) - (insert code) - ;; Fontify buffer. - (font-lock-ensure) - ;; Remove formatting on newline characters. - (save-excursion - (let ((beg (point-min)) - (end (point-max))) - (goto-char beg) - (while (progn (end-of-line) ( (point) end)) - (put-text-property (point) (1+ (point)) 'face nil) - (forward-char 1 - (org-src-mode) - (set-buffer-modified-p nil) - ;; Htmlize region. - (org-html-htmlize-region-for-paste - (point-min) (point-max + (let ((output-type org-html-htmlize-output-type) + (font-prefix org-html-htmlize-font-prefix)) + (setq code (with-temp-buffer + ;; Switch to language-specific mode. + (funcall lang-mode) + (insert code) + ;; Fontify buffer. + (font-lock-ensure) + ;; Remove formatting on newline characters. + (save-excursion + (let ((beg (point-min)) + (end (point-max))) + (goto-char beg) + (while (progn (end-of-line) ( (point) end)) + (put-text-property (point) (1+ (point)) 'face nil) + (forward-char 1 + (org-src-mode) + (set-buffer-modified-p nil) + ;; Htmlize region. + (let ((org-html-htmlize-output-type output-type) + (org-html-htmlize-font-prefix font-prefix)) + (org-html-htmlize-region-for-paste + (point-min) (point-max)) ;; Strip any enclosing pre/pre tags. (let* ((beg (and (string-match \\`pre[^]*\n* code) (match-end 0))) (end (and beg (string-match /pre\\' code
Re: [O] controlling how htmlize fontifies code
Nicolas Goaziou m...@nicolasgoaziou.fr writes: Rasmus ras...@gmx.us writes: Do we have a function that can generate a candidate css file for org-org-htmlized-css-url or :html-htmlize-css-url? There is `org-html-htmlize-generate-css'. The next question is thus, shouldn't the output of this automatically be inserted when css instead of inline-css is used? Rasmus -- I almost cut my hair, it happened just the other day
Re: [O] controlling how htmlize fontifies code
Rasmus ras...@gmx.us writes: Nicolas Goaziou m...@nicolasgoaziou.fr writes: Rasmus ras...@gmx.us writes: Do we have a function that can generate a candidate css file for org-org-htmlized-css-url or :html-htmlize-css-url? There is `org-html-htmlize-generate-css'. The next question is thus, shouldn't the output of this automatically be inserted when css instead of inline-css is used? IIUC, the very existence of `org-org-htmlized-css-url' is because this function is not reliable when using batch mode or when different authors use different Emacs themes. Regards,
Re: [O] controlling how htmlize fontifies code
On Sunday, 2 Aug 2015 at 09:19, Rick Frankel wrote: Check the documentation for the variable `org-html-htmlize-output-type'. Since ox-reveal is derived from ox-html, it should work as specified. I personally use ox-deck (also derived from html), so YMMV. On Sunday, 2 Aug 2015 at 09:41, Kaushal wrote: I export with my custom Leuven theme (a light theme) css and it works fine. I also have my emacs theme as a dark theme by default. ;; (setq org-html-htmlize-output-type 'inline-css) ; default (setq org-html-htmlize-output-type 'css) ;; (setq org-html-htmlize-font-prefix ) ; default (setq org-html-htmlize-font-prefix org-) Thank you Rick and Kaushal. =org-html-htmlize-output-type= does what I want. However, I don't want to set this globally as I use htmlize every now and again to send HTML emacs (yes, I know, bad idea but some colleagues require me to email information in tables and the like every now and again and it's better than using Word... ;-). I have tried both setting a local variable and also using #+bind: but neither approach works for some reason. I did not expect the local variable setting to work, of course. Any suggestions on taking this forward? For now, setting this variable globally to nil is a stop-gap measure. Thanks, eric -- : Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3beta-1303-g3f0398
Re: [O] controlling how htmlize fontifies code
On Sunday, 2 Aug 2015 at 14:17, Rasmus wrote: [...] Check the functions disable-theme and load-theme in Emacs; maybe map custom-enabled-themes over disable-theme. Check the hooks Thanks. Using org-html-htmlize-output-type seems to work for what I want. -- : Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3beta-1303-g3f0398
Re: [O] controlling how htmlize fontifies code
On Mon, Aug 03, 2015 at 02:50:27PM +0100, Eric S Fraga wrote: On Sunday, 2 Aug 2015 at 09:19, Rick Frankel wrote: Check the documentation for the variable `org-html-htmlize-output-type'. Since ox-reveal is derived from ox-html, it should work as specified. I personally use ox-deck (also derived from html), so YMMV. On Sunday, 2 Aug 2015 at 09:41, Kaushal wrote: I export with my custom Leuven theme (a light theme) css and it works fine. I also have my emacs theme as a dark theme by default. ;; (setq org-html-htmlize-output-type 'inline-css) ; default (setq org-html-htmlize-output-type 'css) ;; (setq org-html-htmlize-font-prefix ) ; default (setq org-html-htmlize-font-prefix org-) I have tried both setting a local variable and also using #+bind: but neither approach works for some reason. I did not expect the local variable setting to work, of course. Both should work. Are you sure you have `org-export-allow-bind-keywords' set? Why wouldn't you expect local variables to work? rick
Re: [O] controlling how htmlize fontifies code
I export with my custom Leuven theme (a light theme) css and it works fine. I also have my emacs theme as a dark theme by default. ;; (setq org-html-htmlize-output-type 'inline-css) ; default (setq org-html-htmlize-output-type 'css) ;; (setq org-html-htmlize-font-prefix ) ; default (setq org-html-htmlize-font-prefix org-) Check out this link for the full solution including Leuven theme css: http://emacs.stackexchange.com/a/7633/115 -- Kaushal Modi On Aug 2, 2015 9:19 AM, Rick Frankel r...@rickster.com wrote: On Sun, Aug 02, 2015 at 10:24:25AM +0100, Eric S Fraga wrote: Now, I can simply start up emacs with a light background, export my slides and everything is fine. However, it would be nice to not have to start up a new emacs just for this. Is there an easy way to pretend, for export to HTML, that emacs is using a light background? Maybe a way to advise the exporter? PS - ideally, code export to HTML would make use of CSS instead of hard-coding in the colours but that's a discussion for another day... Check the documentation for the variable `org-html-htmlize-output-type'. Since ox-reveal is derived from ox-html, it should work as specified. I personally use ox-deck (also derived from html), so YMMV. rick
Re: [O] controlling how htmlize fontifies code
On Sun, Aug 02, 2015 at 10:24:25AM +0100, Eric S Fraga wrote: Now, I can simply start up emacs with a light background, export my slides and everything is fine. However, it would be nice to not have to start up a new emacs just for this. Is there an easy way to pretend, for export to HTML, that emacs is using a light background? Maybe a way to advise the exporter? PS - ideally, code export to HTML would make use of CSS instead of hard-coding in the colours but that's a discussion for another day... Check the documentation for the variable `org-html-htmlize-output-type'. Since ox-reveal is derived from ox-html, it should work as specified. I personally use ox-deck (also derived from html), so YMMV. rick
Re: [O] controlling how htmlize fontifies code
Eric S Fraga e.fr...@ucl.ac.uk writes: Now, I can simply start up emacs with a light background, export my slides and everything is fine. However, it would be nice to not have to start up a new emacs just for this. Is there an easy way to pretend, for export to HTML, that emacs is using a light background? Maybe a way to advise the exporter? Check the functions disable-theme and load-theme in Emacs; maybe map custom-enabled-themes over disable-theme. Check the hooks org-export-before-processing-hook and org-export-before-parsing-hook in ox to automate it. Some people on SX seem to have used some JS coloring libraries. PS - ideally, code export to HTML would make use of CSS instead of hard-coding in the colours but that's a discussion for another day... This would also solve the problem when exporting in batch. Patches welcome. Rasmus -- I feel emotional landscapes they puzzle me