emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* colorize html output when batch exporting
@ 2014-01-14 13:45 Alan Schmitt
  2014-01-14 18:25 ` Rick Frankel
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Schmitt @ 2014-01-14 13:45 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I'm trying to batch export a file, and I don't seem to have colorization
working. Reading the documentation a bit, I found this information:

,----
| org-html-htmlize-output-type is a variable defined in `ox-html.el'.
| Its value is inline-css
| 
| Documentation:
| Output type to be used by htmlize when formatting code snippets.
| Choices are `css', to export the CSS selectors only, or `inline-css', to
| export the CSS attribute values inline in the HTML.  We use as default
| `inline-css', in order to make the resulting HTML self-containing.
| 
| However, this will fail when using Emacs in batch mode for export, because
| then no rich font definitions are in place.  It will also not be good if
| people with different Emacs setup contribute HTML files to a website,
| because the fonts will represent the individual setups.  In these cases,
| it is much better to let Org/Htmlize assign classes only, and to use
| a style file to define the look of these classes.
| To get a start for your css file, start Emacs session and make sure that
| all the faces you are interested in are defined, for example by loading files
| in all modes you want.  Then, use the command
| M-x org-html-htmlize-generate-css to extract class definitions.
`----

Following these instructions, I set up this variable in the init.el
called upon batch exporting, among other things:

#+BEGIN_SRC emacs-lisp
(add-to-list 'load-path (file-name-directory load-file-name))

(require 'local_settings)

(require 'org)
(require 'ox-html)

(setq org-html-postamble nil)
(setq org-html-htmlize-output-type 'css)
(setq org-confirm-babel-evaluate nil)
#+END_SRC

Unfortunately I could not complete the next step (to get a start on the
css file), as `org-html-htmlize-generate-css` results in an error
"face-attribute: Invalid face: font-lock-comment". I tried to toggle
debug on error, but it does nothing.

Are there suggestions on how to generate this css file for a nice
coloring of my code?

Thanks,

Alan

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

* Re: colorize html output when batch exporting
  2014-01-14 13:45 colorize html output when batch exporting Alan Schmitt
@ 2014-01-14 18:25 ` Rick Frankel
  2014-01-15  8:04   ` Alan Schmitt
  0 siblings, 1 reply; 5+ messages in thread
From: Rick Frankel @ 2014-01-14 18:25 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode

On 2014-01-14 08:45, Alan Schmitt wrote:
> Hello,
> 
> I'm trying to batch export a file, and I don't seem to have 
> colorization
> working. Reading the documentation a bit, I found this information:
> 
> Following these instructions, I set up this variable in the init.el
> called upon batch exporting, among other things:

> Unfortunately I could not complete the next step (to get a start on the
> css file), as `org-html-htmlize-generate-css` results in an error
> "face-attribute: Invalid face: font-lock-comment". I tried to toggle
> debug on error, but it does nothing.
> 
> Are there suggestions on how to generate this css file for a nice
> coloring of my code?

Which version of emacs are you using? FWIW, I just had this problem
yesterday (although it choked on a different face) in emacs trunk
(24.4.x). But on my machine @work on (24.3.8) it is working fine.

It seems that htmlize is choking on invalid face definitions.
Somewhere you have a reference to a face "font-lock-comment" which
does not exist (the correct definition in this case is
"font-lock-comment-face"), so if you can find the customization that
refers to "font-lock-comment" and fix it you should be able to
generate the CSS.

rick

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

* Re: colorize html output when batch exporting
  2014-01-14 18:25 ` Rick Frankel
@ 2014-01-15  8:04   ` Alan Schmitt
  2014-01-15 14:39     ` Rick Frankel
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Schmitt @ 2014-01-15  8:04 UTC (permalink / raw)
  To: Rick Frankel; +Cc: emacs-orgmode

Quick summary: I'm now able to generate the css, but I don't understand
how it can change the colors.

Rick Frankel <rick@rickster.com> writes:

> Which version of emacs are you using? FWIW, I just had this problem
> yesterday (although it choked on a different face) in emacs trunk
> (24.4.x). But on my machine @work on (24.3.8) it is working fine.

I'm on 24.3.1.

> It seems that htmlize is choking on invalid face definitions.
> Somewhere you have a reference to a face "font-lock-comment" which
> does not exist (the correct definition in this case is
> "font-lock-comment-face"), so if you can find the customization that
> refers to "font-lock-comment" and fix it you should be able to
> generate the CSS.

Thank you for the suggestion. I had a quick look at what
org-html-htmlize-generate-css is doing, and it starts by building a
face-list which is used in my case. I thought the problem was that I had
been using this instance of emacs for too long (thus many faces where
loaded), but with a fresh emacs, I still have an error (this time for
`font-lock-pseudo-keyword-face`).

Loading an emacs with no configuration (except for org and htmlize), I'm
now able to generate the CSS. After loading the mode of interest, I now
know the names of the classes I should work with.

However, I still find there is a problem. Here is the html source
generated from a snippet of the file:

#+BEGIN_SRC html
<div class="org-src-container">

<pre class="src src-coq">Inductive expr :=
  | expr_this : expr
  | expr_identifier : string -&gt; expr
  | expr_literal : literal -&gt; expr
  | expr_object : list (propname * propbody) -&gt; expr
  | expr_function : option string -&gt; list string -&gt; funcbody -&gt; expr
  | expr_access : expr -&gt; expr -&gt; expr
  | expr_member : expr -&gt; string -&gt; expr
  | expr_new : expr -&gt; list expr -&gt; expr
  | expr_call : expr -&gt; list expr -&gt; expr
  | expr_unary_op : unary_op -&gt; expr -&gt; expr
  | expr_binary_op : expr -&gt; binary_op -&gt; expr -&gt; expr
  | expr_conditional : expr -&gt; expr -&gt; expr -&gt; expr
  | expr_assign : expr -&gt; option binary_op -&gt; expr -&gt; expr
</pre>
</div>
#+END_SRC

I don't understand how things are supposed to be colorized, as there is
no mention in the html of span elements to put color on. For instance,
"Inductive" is a keyword, and in a coq buffer it has face
"font-lock-keyword-face". Shouldn't it have class "org-keyword" in the
generated html?

Thanks,

Alan

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

* Re: colorize html output when batch exporting
  2014-01-15  8:04   ` Alan Schmitt
@ 2014-01-15 14:39     ` Rick Frankel
  2014-01-15 15:24       ` Alan Schmitt
  0 siblings, 1 reply; 5+ messages in thread
From: Rick Frankel @ 2014-01-15 14:39 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode

On 2014-01-15 03:04, Alan Schmitt wrote:
> Quick summary: I'm now able to generate the css, but I don't understand
> how it can change the colors.

> However, I still find there is a problem. Here is the html source
> generated from a snippet of the file:
> 
> #+BEGIN_SRC html
> <div class="org-src-container">
> 
> <pre class="src src-coq">Inductive expr :=
> | expr_this : expr
> | expr_identifier : string -&gt; expr
> | expr_literal : literal -&gt; expr
> | expr_object : list (propname * propbody) -&gt; expr
> | expr_function : option string -&gt; list string -&gt; funcbody -&gt; 
> expr
> | expr_access : expr -&gt; expr -&gt; expr
> | expr_member : expr -&gt; string -&gt; expr
> | expr_new : expr -&gt; list expr -&gt; expr
> | expr_call : expr -&gt; list expr -&gt; expr
> | expr_unary_op : unary_op -&gt; expr -&gt; expr
> | expr_binary_op : expr -&gt; binary_op -&gt; expr -&gt; expr
> | expr_conditional : expr -&gt; expr -&gt; expr -&gt; expr
> | expr_assign : expr -&gt; option binary_op -&gt; expr -&gt; expr
> </pre>
> </div>
> #+END_SRC
> 
> I don't understand how things are supposed to be colorized, as there is
> no mention in the html of span elements to put color on. For instance,
> "Inductive" is a keyword, and in a coq buffer it has face
> "font-lock-keyword-face". Shouldn't it have class "org-keyword" in the
> generated html?

Yes, it should. Something is not right with your output. I'm not
familiar with coq, and i don't have coq-mode.el, but from the above it
looks like a BNF grammar. Are you sure coq-mode was loaded when you
did the export? Could you try a simple example? Here's a mimimal org
file

#+BEGIN_SRC org
,#+OPTIONS: html-postamble:nil html-preamble:nil html-scripts:nil 
html-style:nil
,#+HTML_HEAD_EXTRA:  <link rel="stylesheet" href="org.css" />
,#+HTML_DOCTYPE: xhtml5

,* Test htmlize
,*Note:* =org-html-htmlize-output-type= is  ~css~

,#+BEGIN_SRC perl :exports code
print "foo\n";
,#+END_SRC
#+END_SRC

and the results i get:

#+BEGIN_HTML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>html</title>
<meta  charset="utf-8" />
<meta  name="generator" content="Org-mode" />
<meta  name="author" content="Rick Frankel" />
<link rel="stylesheet" href="org.css" />
</head>
<body>
<div id="content">
<h1 class="title">html</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">Test htmlize</a></li>
</ul>
</div>
</div>

<div id="outline-container-sec-1" class="outline-2">
<h2 id="sec-1">Test htmlize</h2>
<div class="outline-text-2" id="text-1">
<p>
<b>Note:</b> <code>org-html-htmlize-output-type</code> is  
<code>css</code>
</p>
<div class="org-src-container">

<pre class="src src-perl"><span 
class="org-cperl-nonoverridable">print</span> <span 
class="org-string">"foo\n"</span>;
</pre>
</div>
</div>
</div>
</div>
</body>
</html>
#+END_HTML

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

* Re: colorize html output when batch exporting
  2014-01-15 14:39     ` Rick Frankel
@ 2014-01-15 15:24       ` Alan Schmitt
  0 siblings, 0 replies; 5+ messages in thread
From: Alan Schmitt @ 2014-01-15 15:24 UTC (permalink / raw)
  To: Rick Frankel; +Cc: emacs-orgmode

Hi Rick,

Rick Frankel <rick@rickster.com> writes:

> Yes, it should. Something is not right with your output. I'm not
> familiar with coq, and i don't have coq-mode.el, but from the above it
> looks like a BNF grammar. Are you sure coq-mode was loaded when you
> did the export?

This was the problem! I added the code to load the mode, and all is well
now.

Thanks a lot for your help,

Alan

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

end of thread, other threads:[~2014-01-15 15:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-14 13:45 colorize html output when batch exporting Alan Schmitt
2014-01-14 18:25 ` Rick Frankel
2014-01-15  8:04   ` Alan Schmitt
2014-01-15 14:39     ` Rick Frankel
2014-01-15 15:24       ` Alan Schmitt

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