Giter Site home page Giter Site logo

xhtml2epub's Introduction

xhtml2epub

A simple library for converting ebooks in XHTML format into EPUB.

Synopsis

xhtml2epub --write-template-dir book_directory
xhtml2epub --input-xhtml book_directory/index.xhtml --output-epub converted_book.epub

Description

When writing or editing ebooks, it is often convenient to store them as a single XHTML file which can be viewed with a web browser and edited using a normal text editor, and then converted to EPUB later for reading on other devices such as a phone or ebook reader. This library provides a simple way to do this conversion.

xhtml2epub requires the XHTML source to follow two conventions to be processed properly. First, some basic information about the book should be defined in the form of XML internal entity declarations in the document's DTD. Currently, xhtml2epub recognizes the following entities as book metadata:

  • title
  • author (or authors, but as a single string either way)
  • language (such as "en")
  • uid (a unique identifier, such as a UUID or ISBN)

All of these are optional, but recommended, especially if you want the resulting EPUB file to conform to the EPUB standard. (Why would you want a book without a title, anyway?)

Secondly, in the XHTML file, any <div> element with an id attribute set is assumed to be a separate chapter. If the <div> has a title attribute set, that is used as the title as shown in the book's table of contents. Otherwise, the title will be auto-detected from the contents of any h1, h2, or h3 heading elements immediately after the opening <div>; or if there are no such headings, from the id itself.

Chapter <div> elements may be nested to create sub-chapters, typically shown in ebook readers as hierarchical trees. For example, a book with a body structure like this:

<div id="chapter-1">...</div>
<div id="part-1">
  ...
  <div id="chapter-2">...</div>
  <div id="chapter-3">...</div>
</div>
<div id="chapter-4">...</div>

will show up in the table of contents as something like:

- Chapter 1
- Part 1
  - Chapter 2
  - Chapter 3
- Chapter 4

xhtml2epub's People

Contributors

wisnij avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.