getnikola / plugins

Extra plugins for Nikola
https://plugins.getnikola.com/
MIT License
56 stars 92 forks source link

[orgmode] fontify source block #104

Open bricewge opened 8 years ago

bricewge commented 8 years ago

The present orgmode plugin complain about htmlize.el no being present:

Cannot fontify src block (htmlize.el >= 1.34 required)

Adding something like this to init.el should do the job:

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(setq package-load-list '((htmlize t)))
(package-initialize)

(unless (package-installed-p 'htmlize)
  (package-refresh-contents)
  (package-install 'htmlize))

Now there is no complain about htmlize.el but unfortunatly the HTML produce is broken; here is an example:

# Code to fontify
(setq bwge/blog-src-directory "~/Dropbox/Blog")
# Without htmlize.el
<div class="highlight"><pre><span class="p">(</span><span class="nf">setq</span> <span class="nv">bwge/blog-src-directory</span> <span class="s">"~/Dropbox/Blog"</span><span class="p">)</span>
# With htmlize.el
<div class="highlight"><pre><span class="p">(</span><span class="nf">setq</span> <span class="nv">bwge/blog-src-directory</span> <span class="nv">&lt;span</span> <span class="nv">style=</span><span class="s">"font-style: italic;"</span><span class="nv">&gt;</span><span class="s">"~/Dropbox/Blog"</span><span class="nv">&lt;/span&gt;</span><span class="p">)</span>
bricewge commented 8 years ago

This is caused by the insertion of inline-css code by htmlize, which then parsed by pygments produce some garbage. The current workaround that I have found is to set org-html-htmlize-output-type to nil however this isn't the right way as htmlize isn't used anymore and we loose the fontification but not the colorization of the text.

punchagan commented 7 years ago

Does the org-file export correctly to html using org-export? Can you share a sample post with this problem?

roblem commented 7 years ago

I am getting this too.

Emacs 25.1.1 Org 8.2.10 Nikola v7.8.3

Example org file:

#+BEGIN_COMMENT
.. title: Another Test Post using OrgMode Plugin
.. slug: another-test-post-using-orgmode-plugin
.. date: 2017-02-22 21:30:50 UTC+01:00
.. tags: 
.. category: 
.. link: 
.. description: 
.. type: text
#+END_COMMENT

#+BEGIN_SRC python :results output :exports both
print("Hello World")
#+END_SRC

yields this in the browser

<span style="font-weight: bold;">print</span>(<span style="font-style: italic;">"Hello World"</span>)

rather than

print("Hello World")

I am using a virtual environment for code execution. The contents of conf.el in the nikola orgmode plugin directory:

(when (>= emacs-major-version 24)
  (require 'package)
  (add-to-list
   'package-archives
   '("melpa" . "http://melpa.org/packages/")
   t)
  (package-initialize))

(require `ob-ipython)
(require `pyvenv)
(require `htmlize)

;; pyvenv setup
;; this is required for many code blocks to execute
;; Specifically, R and python
(setenv "WORKON_HOME" "~/anaconda/envs")
(setq pyvenv-workon "python3")
(setenv "WORKON" "python3")
(pyvenv-mode 1)

;; sets up stata execution
(require 'ess-site)
;; turns off prompts
(setq ess-ask-for-ess-directory nil)
;; elisp lib dir
(add-to-list 'load-path "~/.emacs.d/lisp/")
;; load ob-stata
(load "ob-stata")

;; sets up org-babel for code cell execution
(org-babel-do-load-languages
 'org-babel-load-languages
 '((python . t)
   (ipython . t)
   (R . t)
   (sh . t)
   (matlab . t)
   (stata . t)
 ))

;; execute without prompts
(setq org-confirm-babel-evaluate nil) 

Every language I tried known by pygmentize has problems.

Also, I can confirm that the html produced by exporting to html directly from org works fine and highliting is perfect.

Setting org-html-htmlize-output-type to nil in conf.el as suggest by @bricewge causes the build to fail:

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "... /doit/action.py", line 403, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "...  /nikola/post.py", line 540, in compile
    lang)
  File "... nikola/plugin_categories.py", line 304, in compile
    self.compile_html(source, dest, is_two_file)
  File "... blog/plugins/orgmode/orgmode.py", line 97, in compile_html
    source, e.returncode))
Exception: Cannot compile posts/test-post-using-orgmode-plugin.org -- bad org-mode configuration (return code 255)
punchagan commented 7 years ago

@roblem Thank you for filing your report, with your config and an example post. But, it looks like the config you posted is incomplete. Please share the full init.el file and the full build output (on success and failure).

roblem commented 7 years ago

See the files here https://gist.github.com/roblem/76fafbd5194b649d71d7e22b0153a8af

punchagan commented 7 years ago

I will try reproducing the issue with your config, Thanks.

But to begin with can you try fixing these requires? The backtick needs to be a single-quote.

(require `ob-ipython)
(require `pyvenv)
(require `htmlize)
(require 'ob-ipython)
(require 'pyvenv)
(require 'htmlize)
roblem commented 7 years ago

Fixed those 3 things and have the same result.

roblem commented 7 years ago

Fixed it:

Using a fresh install of Fedora in a VM with an Anaconda virtual environment, things work flawlessly even though the following appears when building a simple test site:

Cannot fontify src block (htmlize.el >= 1.34 required)

Despite this message, nikola rendered the site perfectly. If you don't see this "error" message then your site will build but with the problems described above. Be sure you haven't installed htmlize.el manually, via melpa, or via your distribution's package manager (and being loaded in a system emacs init). If your site fails to build, it IS NOT because you haven't installed htmlize.el, you have an error somewhere in conf.el or in your org file.

So, the issue described in #171, is correct: the error above is a bogus error that you want to see when building your site. Perhaps this should be added to the plugin description page.