Skip to content

Instantly share code, notes, and snippets.

@roblem
Last active February 24, 2017 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roblem/76fafbd5194b649d71d7e22b0153a8af to your computer and use it in GitHub Desktop.
Save roblem/76fafbd5194b649d71d7e22b0153a8af to your computer and use it in GitHub Desktop.
Let me know if you need something else.
(python3) [user@nuc blog] $ nikola build
[2017-02-23T16:36:28Z] WARNING: Nikola: In order to USE_BUNDLES, you must install the "webassets" Python package.
[2017-02-23T16:36:28Z] WARNING: bundles: Setting USE_BUNDLES to False.
Scanning posts...........done!
. render_taxonomies:output/archive.html
. render_sources:output/posts/test-org-mode.org
. render_posts:timeline_changes
. render_posts:cache/posts/test-org-mode.html
Loading /usr/share/emacs/site-lisp/site-start.d/asy-init.el (source)...
Loading /usr/share/emacs/site-lisp/site-start.d/cmake-init.el (source)...
Loading /usr/share/emacs/site-lisp/site-start.d/desktop-entry-mode-init.el (source)...
Loading /usr/share/emacs/site-lisp/site-start.d/git-init.el (source)...
Loading /usr/share/emacs/site-lisp/site-start.d/htmlize-init.el (source)...
Loading /home/user/Dropbox/blog/plugins/orgmode/conf.el (source)...
Loading /home/user/.emacs.d/lisp/ob-stata.el (source)...
executing Python code block...
Code block evaluation complete.
Can’t guess python-indent-offset, using defaults: 4
. render_taxonomies:output/2017/index.html
. render_taxonomies:output/blog/index.html
. render_pages:output/posts/test-org-mode.html
. render_pages:output/posts/reproducible-research.html
. render_taxonomies:output/rss.xml
. sitemap:output/sitemap.xml
. sitemap:output/sitemapindex.xml
Setting (setq org-html-htmlize-output-type nil) in conf.el, gives me this:
(python3) [user@nuc posts] $ nikola build
[2017-02-23T17:05:23Z] WARNING: Nikola: In order to USE_BUNDLES, you must install the "webassets" Python package.
[2017-02-23T17:05:23Z] WARNING: bundles: Setting USE_BUNDLES to False.
Scanning posts...........done!
. render_sources:output/posts/test-org-mode.org
. render_posts:timeline_changes
. render_posts:cache/posts/test-org-mode.html
Loading /usr/share/emacs/site-lisp/site-start.d/asy-init.el (source)...
Loading /usr/share/emacs/site-lisp/site-start.d/cmake-init.el (source)...
Loading /usr/share/emacs/site-lisp/site-start.d/desktop-entry-mode-init.el (source)...
Loading /usr/share/emacs/site-lisp/site-start.d/git-init.el (source)...
Loading /usr/share/emacs/site-lisp/site-start.d/htmlize-init.el (source)...
Loading /home/user/Dropbox/blog/plugins/orgmode/conf.el (source)...
Loading /home/user/.emacs.d/lisp/ob-stata.el (source)...
executing Python code block...
Code block evaluation complete.
Can’t guess python-indent-offset, using defaults: 4
Symbol’s function definition is void: nil
########################################
TaskError - taskid:render_posts:cache/posts/test-org-mode.html
PythonAction Error
Traceback (most recent call last):
File "/home/user/Dropbox/blog/plugins/orgmode/orgmode.py", line 73, in compile_html
subprocess.check_call(command)
File "/home/user/anaconda/envs/python3/lib/python3.5/subprocess.py", line 581, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['emacs', '--batch', '-l', '/home/user/Dropbox/blog/plugins/orgmode/init.el', '--eval', '(nikola-html-export "/home/user/Dropbox/blog/posts/test-org-mode.org" "/home/user/Dropbox/blog/cache/posts/test-org-mode.html")']' returned non-zero exit status 255
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/user/anaconda/envs/python3/lib/python3.5/site-packages/doit/action.py", line 403, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/user/anaconda/envs/python3/lib/python3.5/site-packages/nikola/post.py", line 540, in compile
lang)
File "/home/user/anaconda/envs/python3/lib/python3.5/site-packages/nikola/plugin_categories.py", line 304, in compile
self.compile_html(source, dest, is_two_file)
File "/home/user/Dropbox/blog/plugins/orgmode/orgmode.py", line 97, in compile_html
source, e.returncode))
Exception: Cannot compile posts/test-org-mode.org -- bad org-mode configuration (return code 255)
(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)
;; Tell emacs where is your personal elisp lib dir
(add-to-list 'load-path "~/.emacs.d/lisp/")
;; load ob-stata
(load "ob-stata")
;; sets up org-babel
(org-babel-do-load-languages
'org-babel-load-languages
'((python . t)
(ipython . t)
(R . t)
(sh . t)
(matlab . t)
(stata . t)
))
(setq org-confirm-babel-evaluate nil) ;; C-c C-c without typing yes
;; work around for bad htmlize
;; (setq org-html-htmlize-output-type nil)
;; Init file to use with the orgmode plugin.
;; Load org-mode
;; Requires org-mode v8.x
;; Uncomment these lines and change the path to your org source to
;; add use it.
;; (let* ((org-lisp-dir "~/.emacs.d/src/org/lisp"))
;; (when (file-directory-p org-lisp-dir)
;; (add-to-list 'load-path org-lisp-dir)
;; (require 'org)))
(require 'ox-html)
;;; Custom configuration for the export. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Add any custom configuration that you would like to 'conf.el'.
(setq
nikola-use-pygments t
org-export-with-toc nil
org-export-with-section-numbers nil
org-startup-folded 'showeverything)
;; Load additional configuration from conf.el
(let ((conf (expand-file-name "conf.el" (file-name-directory load-file-name))))
(if (file-exists-p conf)
(load-file conf)))
;;; Macros ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Load Nikola macros
(setq nikola-macro-templates
(with-current-buffer
(find-file
(expand-file-name "macros.org" (file-name-directory load-file-name)))
(org-macro--collect-macros)))
;;; Code highlighting ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun org-html-decode-plain-text (text)
"Convert HTML character to plain TEXT. i.e. do the inversion of
`org-html-encode-plain-text`. Possible conversions are set in
`org-html-protect-char-alist'."
(mapc
(lambda (pair)
(setq text (replace-regexp-in-string (cdr pair) (car pair) text t t)))
(reverse org-html-protect-char-alist))
text)
;; Use pygments highlighting for code
(defun pygmentize (lang code)
"Use Pygments to highlight the given code and return the output"
(with-temp-buffer
(insert code)
(let ((lang (or (cdr (assoc lang org-pygments-language-alist)) "text")))
(shell-command-on-region (point-min) (point-max)
(format "pygmentize -f html -l %s" lang)
(buffer-name) t))
(buffer-string)))
(defconst org-pygments-language-alist
'(
("asymptote" . "asymptote")
("awk" . "awk")
("C" . "c")
("cpp" . "cpp")
("clojure" . "clojure")
("css" . "css")
("D" . "d")
("emacs-lisp" . "scheme")
("F90" . "fortran")
("gnuplot" . "gnuplot")
("groovy" . "groovy")
("haskell" . "haskell")
("java" . "java")
("js" . "js")
("julia" . "julia")
("latex" . "latex")
("lisp" . "lisp")
("makefile" . "makefile")
("matlab" . "matlab")
("mscgen" . "mscgen")
("ocaml" . "ocaml")
("octave" . "octave")
("perl" . "perl")
("picolisp" . "scheme")
("python" . "python")
("R" . "r")
("ruby" . "ruby")
("sass" . "sass")
("scala" . "scala")
("scheme" . "scheme")
("sh" . "sh")
("sql" . "sql")
("sqlite" . "sqlite3")
("tcl" . "tcl")
)
"Alist between org-babel languages and Pygments lexers.
See: http://orgmode.org/worg/org-contrib/babel/languages.html and
http://pygments.org/docs/lexers/ for adding new languages to the
mapping. ")
;; Override the html export function to use pygments
(defun org-html-src-block (src-block contents info)
"Transcode a SRC-BLOCK element from Org to HTML.
CONTENTS holds the contents of the item. INFO is a plist holding
contextual information."
(if (org-export-read-attribute :attr_html src-block :textarea)
(org-html--textarea-block src-block)
(let ((lang (org-element-property :language src-block))
(code (org-html-format-code src-block info)))
(if nikola-use-pygments
(pygmentize lang (org-html-decode-plain-text code))
code))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Export function used by Nikola.
(defun nikola-html-export (infile outfile)
"Export the body only of the input file and write it to
specified location."
(with-current-buffer (find-file infile)
(org-macro-replace-all nikola-macro-templates)
(org-html-export-as-html nil nil t t)
(write-file outfile nil)))
print("Hello World")
@punchagan
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment