From mboxrd@z Thu Jan  1 00:00:00 1970
From: Florian Beck <fb@miszellen.de>
Subject: Re: [RFC] About `org-export-with-\(fixed-width\|tables\)'
Date: Wed, 08 Jan 2014 08:23:32 +0100
Message-ID: <52CCFCF4.4060401@miszellen.de>
References: <871u1999rr.fsf@gmail.com>	<87ioukxzn6.fsf@sophokles.streitblatt.de>	<87d2k7g4sp.fsf@ericabrahamsen.net>
	<87vbxvd5c6.fsf@ucl.ac.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Return-path: <emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org>
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49821)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <fb@miszellen.de>) id 1W0nUS-0000X7-0J
	for emacs-orgmode@gnu.org; Wed, 08 Jan 2014 02:23:52 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <fb@miszellen.de>) id 1W0nUN-0003X7-3D
	for emacs-orgmode@gnu.org; Wed, 08 Jan 2014 02:23:47 -0500
Received: from mo6-p04-ob.smtp.rzone.de ([2a01:238:20a:202:5304::8]:47123)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <fb@miszellen.de>) id 1W0nUM-0003Wo-Jj
	for emacs-orgmode@gnu.org; Wed, 08 Jan 2014 02:23:43 -0500
In-Reply-To: <87vbxvd5c6.fsf@ucl.ac.uk>
List-Id: "General discussions about Org-mode." <emacs-orgmode.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-orgmode>,
	<mailto:emacs-orgmode-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/emacs-orgmode>
List-Post: <mailto:emacs-orgmode@gnu.org>
List-Help: <mailto:emacs-orgmode-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-orgmode>,
	<mailto:emacs-orgmode-request@gnu.org?subject=subscribe>
Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org
Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org
To: Eric Abrahamsen <eric@ericabrahamsen.net>, emacs-orgmode@gnu.org

On 07.01.2014 19:17, Eric S Fraga wrote:
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:

>> Hey, are you actually exporting to an epub? How are you doing that?
>
> I'd be curious to know as well.  I export to epub in two ways, both by
> first exporting to HTML.  Then either use calibre to convert the HTML
> document or load the HTML document in firefox and use the "dotepub"
> addon.  I haven't done this enough to say which is better.

If you are copying your file to a device, conversion with calibre is the 
simplest option.

> I would guess that defining an epub exporter, derived from the HTML
> exporter, may not be that difficult.  If only I had the time :-(


(org-export-define-derived-backend 'fb/org-export-epub 'html
   :menu-entry '(?h 99 ((?p "As epub file" fb/org-export-epub))))

(defun fb/convert-html-to-epub (infile)
   (let ((outfile (concat (file-name-sans-extension infile)
			 ".epub"))
	(max-toc-links "0")
	(level1 "//h:h2")
	(level2 "//h:h3")
	(chapter "\"//*[name()='h1' or name()='h2']\"")
	(chapter-mark "pagebreak"))
     (shell-command
      (format "ebook-convert %s %s --max-toc-links=%s --use-auto-toc 
--level1-toc=%s --level2-toc=%s --chapter=%s --chapter-mark=%s 
--input-encoding=utf8 -v -v -v --authors=\"%s\" --title=\"%s\""
	     infile outfile
	     max-toc-links level1 level2 chapter chapter-mark
	     (user-full-name)
	     (file-name-base outfile)))
     outfile))

(defun fb/org-export-epub (&optional async subtreep visible-only
				     body-only ext-plist)
   (interactive)
   (let* ((extension (concat "." org-html-extension))
	 (file (org-export-output-file-name extension subtreep))
	 (org-export-coding-system org-html-coding-system))
     (org-export-to-file 'fb/org-export-epub file
       async subtreep visible-only body-only ext-plist
       (lambda (file) (fb/convert-html-to-epub file)))))