GithubHelp home page GithubHelp logo

lelinhtinh / jepub Goto Github PK

View Code? Open in Web Editor NEW
44.0 5.0 21.0 1.17 MB

Simple EPUB builder library, works in modern browsers.

Home Page: https://lelinhtinh.github.io/jEpub/

License: ISC License

JavaScript 45.19% EJS 54.81%
generator epub javascript browser library epub-generation

jepub's Introduction

jEpub

npm version FOSSA Status

Simple EPUB builder library, works in modern browsers.

Demo

  1. /demo
  2. jsfiddle.net/rhov44gg

Installation

npm install --save jepub

You can also use it via a CDN:

<script src="https://unpkg.com/jepub/dist/jepub.min.js"></script>

or:

<script src="https://cdn.jsdelivr.net/npm/jepub/dist/jepub.min.js"></script>

Dependencies

jEpub requires JSZip and EJS. Make sure these libraries are loaded before starting your code.

<script src="jszip.js"></script>
<script src="ejs.js"></script>
<script src="jepub.js"></script>
<script>
    const jepub = new jEpub()
    // jepub.init({
    // do something
</script>

Usage

const jepub = new jEpub()
jepub.init({
    i18n: 'en', // Internationalization
    title: 'Book title',
    author: 'Book author',
    publisher: 'Book publisher',
    description: '<b>Book</b> description', // optional
    tags: [ 'epub', 'tag' ] // optional
})
  • i18n only include the language codes defined in i18n.json
  • description: HTML string.
  • tags: Array.

Set published date

jepub.date(date: object)
  • date: Date Object.

Set identifier

jepub.uuid(id: string | number)
  • id: Unique id.

Add cover

jepub.cover(data: object)
  • data: A Blob or an ArrayBuffer object from XMLHttpRequest.

Add notes

jepub.notes(content: string)
  • content: HTML string.

Add chapter *

jepub.add(title: string, content: string | array, index?:number)
  • title: Plain text.
  • content:
    • string: HTML string.
    • array: Plain text for each item.
  • index: Item index.

Add image

jepub.image(data: object, IMG_ID: string)
  • data: A Blob or an ArrayBuffer object from XMLHttpRequest.
  • IMG_ID: Unique id.

Place <%= image[IMG_ID] %> inside the chapter's content (HTML string only), where you want to display it.

Generate EPUB *

jepub.generate(type = 'blob', onUpdate?: metadata => void)

Static methods +

Convert HTML to text

jEpub.html2text(html: string, noBr = false)
  • html: HTML string.
  • noBr: Boolean. Add line break after Block-level elements.

Development

npm start

Builds are concatenated and minified using Webpack and Babel.

npm run build

License

ISC. Copyright 2018 lelinhtinh

FOSSA Status

jepub's People

Contributors

carlsonsantana avatar dependabot[bot] avatar fameoflight avatar fossabot avatar lelinhtinh 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

jepub's Issues

Metadata for series

@jeffmcneill, since the “new” EPUB3 is mostly a reversion to EPUB 3.0.1, that’s the model to follow. See https://w3c.github.io/publ-epub-revision/epub32/spec/epub-packages.html#sec-belongs-to-collection for the spec, though the examples at https://w3c.github.io/publ-epub-revision/epub32/spec/epub-packages.html#group-position are perhaps a bit more complete. Basically:

<meta id="num" property="belongs-to-collection">Series Name Goes Here</meta>
<meta property="collection-type" refines="#num">series</meta>
<meta property="group-position" refines="#num">1</meta>

Caveats:

  • I’m not clear when you’d use set instead of series. The example shown puts a Harry Potter book in a set, but would that have been the right decision when the books were still being released? How about a book series whose final length is not known at the moment?
  • Note that group-position is “A single xsd:unsignedInt or series of decimal-separated numbers (e.g., 1 or 2.2.1).”)
  • The specs recommend also giving the collection an identifier, e.g.,
    <meta property="belongs-to-collection" id="c02">Harry Potter</meta>
    <meta refines="#c02" property="collection-type">set</meta>
    <meta refines="#c02" property="group-position">2</meta>
    <meta refines="#c02" property="dcterms:identifier">urn:uuid:99999999-8888-7777-6666-555555555555</meta>
    but I have no idea whether any reading system implemented actually cares about that. Probably can’t hurt, though.
  • Supposedly, a book can belong to multiple collections. Good luck getting any reading systems to respect that, though.

Originally posted by @jcsalomon in w3c/epub-specs#326 (comment)

Tuỳ chọn bỏ dấu Tiếng Việt

Bỏ dấu Tiếng Việt ở các phần như tiêu đề, giới thiệu, mục lục*, ... trừ nội dung chương. Việc này sẽ giúp tránh lỗi phông chữ ở các phần đấy trên Kobo, Mobipocket Reader Desktop.

Puzzling ejs error in production

Everything is working fine locally, but as soon as I deploy the project, it seems that ejs has an issue with a template. I couldn't figure out what's wrong and can't reproduce locally... any ideas?

Uncaught (in promise) ReferenceError: ejs:3
    1| <?xml version="1.0" encoding="UTF-8" ?>
    2| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 >> 3| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%= i18n.code %>">
    4| 
    5| <head>
    6| 	<title><%= i18n.info %></title>

i is not defined
    at escapeFn (eval at compile (e2bc53435618f67931716dd55169ffaa66bb2a34.js?meteor_js_resource=true:formatted:21840), <anonymous>:4:72)
    at eval (eval at compile (e2bc53435618f67931716dd55169ffaa66bb2a34.js?meteor_js_resource=true:formatted:21840), <anonymous>:26:16)
    at Object.n.render (e2bc53435618f67931716dd55169ffaa66bb2a34.js?meteor_js_resource=true:formatted:21768)
    at b.init (e2bc53435618f67931716dd55169ffaa66bb2a34.js?meteor_js_resource=true:formatted:21246)
    at generateEPUB (e2bc53435618f67931716dd55169ffaa66bb2a34.js?meteor_js_resource=true:formatted:230087)
    at e2bc53435618f67931716dd55169ffaa66bb2a34.js?meteor_js_resource=true:formatted:229997
    at e2bc53435618f67931716dd55169ffaa66bb2a34.js?meteor_js_resource=true:formatted:493

The code up to that point is as simple as it gets:

var author_name = "xyz";
  var story_name = "abc";
  const options = {
    i18n: 'en',
    title: story_name,
    author: author_name,
    publisher: "somePublisher",
    tags: [ 'epub' ]
  }

  //generate epub
  import ejs from "ejs";
  import jEpub from "jepub/dist/jepub";
  const jepub = new jEpub()
  jepub.init(options);

images in content

Hello, how to add a or what is the way for add images in a section content?

Can't Generate File

So I'm using Cordova to build an android app and it acts as a browser-side I believe. Now the code runs fine. but jepub.generate(type = 'blob'); doesn't generate any file.

Type definition file

Hi folks, Is there any plan to provide a type definition file for this package?

Unable to use in Project

When doing import I am running into ./node_modules/jepub/src/jepub.js
Module not found: Can't resolve './tpl/OEBPS/front-cover.html' in '/Users/hemantv/workspace/tellado/tellado-webapp/node_modules/jepub/src'

any ideas what might be going on here?

Usage of jEpub in UserLibrary (userscript)

Hello,

In my case, I require jEpub in an UserLibrary then I require that UserLibrary into a normal UserScript.

E.g:

// ==UserScript==
// @name         TangThuVien downloader
// @match        http://truyen.tangthuvien.vn/doc-truyen/*
// @match        https://truyen.tangthuvien.vn/doc-truyen/*
// @require      https://greasyfork.org/scripts/383027-mb-downloader-library/code/MB%20Downloader%20Library.js?version=698206
// @connect      self
// @run-at       document-idle
// @noframes
// ==/UserScript==

But it is showing this

Screenshot 2019-05-15 12 42 49

It will work if I changed from UserLibrary to UserScript. Do you know why this happening?

P/s: Thank you so much for creating TruyenCV_downloader, I steal lots of code from you :) 👍 👍 💯 💯

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.