Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An example using elnode.el
;;; elnode-org-export-as.el --- An example using elnode.el.
;; Copyright (C) 2011 Takumi KINJO
;; Author: Takumi KINJO <>
;; Created: 5th May 2011
;; Version: 0
;; Keywords: lisp
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <>.
;;; Commentary:
;; This is an example using elnode.el and is tested on
;; org-mode 7.5. (check M-x org-version)
;; About elnode.el, see
;; To run this, follow instructions.
;; This uses auto-install. If you have had already it, skip Step1.
;; Step1. Install auto-install
;; Type below commands in your shell.
;; (about auto-install, see
;; (cd ~/.emacs.d; curl -O
;; Step2. Install elnode.el and org-html5presentation
;; Eval below expressions.
;; (add-to-list 'load-path "~/.emacs.d") ; if needed
;; (require 'auto-install) ; if needed
;; (auto-install-from-url "") ;; small fix version
;; (auto-install-from-url "")
;; Step3. Setup
;; Eval below all expressions or write in your ~/.emacs.
;; Step4. Browse your org file from your web browser
;; http://localhost:8000/,
;; http://localhost:8000/ or
;; http://localhost:8000/
(require 'elnode)
(require 'org-html5presentation)
(defvar elnode-example-docroot "~/")
(defun elnode-example-chop-ext (path ext)
(and (string-match (format "\.%s$" ext) path)
(substring path 0 (match-beginning 0)))))
(defun elnode-example-handler (httpcon)
"Demonstration function"
(let* ((path (concat elnode-example-docroot (elnode-http-pathinfo httpcon)))
(ext (file-name-extension path)))
(if (or (string-equal ext "html") (string-equal ext "txt") (string-equal ext "presentation"))
(let ((path (elnode-example-chop-ext path ext)))
(find-file-noselect path)
(let ((buf (get-buffer-create "*org-export-as-html-buffer*")))
((string-equal ext "txt")
(elnode-http-start httpcon "200" '("Content-type" . "text/plain"))
(org-export-as-ascii nil nil nil buf))
((string-equal ext "html")
(elnode-http-start httpcon "200" '("Content-type" . "text/html"))
(org-export-as-html nil nil nil buf))
((string-equal ext "presentation")
(elnode-http-start httpcon "200" '("Content-type" . "text/html"))
(org-export-as-html5presentation nil nil nil buf)))
(elnode-http-start httpcon "200" '("Content-type" . "text/html"))
(if (file-regular-p path)
(find-file-noselect path)
(let ((buf (get-buffer-create "*org-export-as-html-buffer*")))
(org-export-as-html nil nil nil buf) buf)
(elnode-http-return httpcon (format "<html>
<body><p>Browse your org file.</p><p>Specify URL by a relative path from %s.<br />For example, use http://localhost:8000/test/ or http://localhost:8000/ when your org file is %stest/</p></body>
</html>" elnode-example-docroot elnode-example-docroot)))))))
(setq elnode-hostpath-default-table '(("[^/]+/.*" . elnode-example-handler)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment