Code Monkey home page Code Monkey logo

node-html2epub's Introduction

html2epub

Convert a collection of HTML documents into an IDPF-compliant EPUB3 document.

NPM

Along with an HTML editor, this can be used as a lightweight alternative to EPUB authoring systems (e.g. Calibre, Sigil…) to generate either tables of contents, OPF files, or complete EPUB3 books.

This script can also be used to extract online web content and make a local EPUB archive for offline reading.

Installation

npm install html2epub -g

Basic usage

html2epub
  [ --config=/path/to/config.json      configuration file                          ]
  [ --basedir=/path/to/directory       base directory (default: current directory) ]
  [ --format=txt|json|xhtml|ncx|epub   output format  (default: epub)              ]
  [ --headings="CSS selector"          ToC headings   (default: h1,h2,h3,h4,h5,h6) ]
  [ --depth                            ToC depth      (default: 3)                 ]

Check the examples directory for sample configuration files.

License

  • the code is released under the MIT license
  • in the examples folder, alice is subject to the Gutenberg™ license

Stability

This works quite well but it’s still in a very early stage: the API and the command-line arguments are likely to change in the near future.

Alternatives

Here are a few other HTML-to-EPUB solutions that could suit your needs:

Note: if you only need to store a web page in a single file, wget64 is a good alternative to EPUB documents.

node-html2epub's People

Contributors

fabi1cazenave avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-html2epub's Issues

OPF generation fails

When generating an OPF the following error occurs, however you can successfully build the .epub containing a valid OPF without issue

html2epub --basedir=alice --format=opf
/usr/local/lib/node_modules/html2epub/lib/index.js:377
  var digits = files.length.toString().length;
                    ^
TypeError: Cannot read property 'length' of undefined
    at buildOPF_manifest (/usr/local/lib/node_modules/html2epub/lib/index.js:377:21)
    at html2epub.showOPF (/usr/local/lib/node_modules/html2epub/lib/index.js:433:5)
    at Object.<anonymous> (/usr/local/lib/node_modules/html2epub/index.js:47:20)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

'TypeError: mime.lookup is not a function' for Node 12

can't run - "TypeError: mime.lookup is not a function"

 marcin@pc:~/workspace/sony/helpguide.sony.net/dmp/nwws410/v1$ node --version
v12.17.0
marcin@pc:~/workspace/sony/helpguide.sony.net/dmp/nwws410/v1$ npm --version
6.14.4
marcin@pc:~/workspace/sony/helpguide.sony.net/dmp/nwws410/v1$ ll pl/
total 8
drwxrwxr-x 1 marcin users   70 lis 30 09:30 ./
drwxrwxr-x 1 marcin users   48 lis 30 09:30 ../
drwxrwxr-x 1 marcin users   16 lis 29 14:39 common/
drwxrwxr-x 1 marcin users 3826 lis 29 14:42 contents/
drwxrwxr-x 1 marcin users 1232 lis 29 14:40 cover/
-rw-rw-r-- 1 marcin users 6369 sie 29  2018 index.html
drwxrwxr-x 1 marcin users   26 lis 29 14:39 search/

marcin@pc:~/workspace/sony/helpguide.sony.net/dmp/nwws410/v1$ npx html2epub --config=/home/marcin/Pobrane/epub3.json --basedir=pl
npx: installed 69 in 3.353s
  downloading: http://www.idpf.org/epub/301/spec/epub-publications.html
  downloading: http://www.idpf.org/epub/301/spec/epub-mediaoverlays.html
  downloading: http://www.idpf.org/epub/301/spec/epub-overview.html
  downloading: http://www.idpf.org/epub/301/spec/epub-contentdocs.html
  downloading: http://www.idpf.org/epub/301/spec/epub-ocf.html
/home/marcin/.npm/_npx/29731/lib/node_modules/html2epub/lib/index.js:380
    var type = mime.lookup(href);
                    ^

TypeError: mime.lookup is not a function
    at /home/marcin/.npm/_npx/29731/lib/node_modules/html2epub/lib/index.js:380:21
    at Array.forEach (<anonymous>)
    at buildOPF_manifest (/home/marcin/.npm/_npx/29731/lib/node_modules/html2epub/lib/index.js:378:9)
    at html2epub.showOPF (/home/marcin/.npm/_npx/29731/lib/node_modules/html2epub/lib/index.js:433:5)
    at appendIndex (/home/marcin/.npm/_npx/29731/lib/node_modules/html2epub/lib/index.js:611:25)
    at appendContent (/home/marcin/.npm/_npx/29731/lib/node_modules/html2epub/lib/index.js:619:7)
    at /home/marcin/.npm/_npx/29731/lib/node_modules/html2epub/lib/index.js:670:7
    at IncomingMessage.<anonymous> (/home/marcin/.npm/_npx/29731/lib/node_modules/html2epub/lib/index.js:585:32)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1221:12)
marcin@pc:~/workspace/sony/helpguide.sony.net/dmp/nwws410/v1$ 

.DS_STORE is missing

Generated epub which had images (sub folder /media with png and jags). Validation kicked out error:

ERROR in "XXXXX.epub":
   resource 'EPUB/.DS_Store' is missing

The content.opf file lists the .ds_store file in the manifest, but is not in the archive. The listing in the content.opf file is:

 <item id="res_01" media-type="application/octet-stream" href=".DS_Store" />

If I go and delete the original file and remake the epub, all ok.

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.