From: "Reviczky, Adam" <adam.reviczky@kcl.ac.uk>
To: "ntg-context@ntg.nl" <ntg-context@ntg.nl>
Cc: Hans Hagen <pragma@wxs.nl>
Subject: dirty epub fixes
Date: Fri, 13 May 2011 20:21:43 +0100 [thread overview]
Message-ID: <7B4626C28B06A7418E938BF73D6DEE18F9F571ED0A@KCL-MAIL05.kclad.ds.kcl.ac.uk> (raw)
[-- Attachment #1: Type: text/plain, Size: 1464 bytes --]
Hans,
Since I didn't got a working epub for the first few tries, I did some further inspections with epubcheck[1].
Using this minimal example:
\setupbackend[export=test.xml,xhtml=test.xhtml,css={test.css,mathml.css}]
\starttext
Test
\stoptext
The main errors are:
* opf: id has to be either "stylesheet" for css or the xhtml filename without the suffix
* opf: itemref needs to be the name of the xhtml without the suffix
Here's a very dirty quick fix I did to get a working epub:
add after line 112 or so:
+ local id = file.removesuffix(filename)
line 116:
- used[#used+1] = format("<item id='%s' href='%s' media-type='%s'/>",i,filename,mime)
+ if suffix == "css" then
+ id = "stylesheet"
+ elseif suffix == "ncx" then
+ id = file.suffix(filename)
+ end
+ used[#used+1] = format("<item id='%s' href='%s' media-type='%s'/>",id,filename,mime)
line 121:
- package = format(package,identifier,identifier,concat(used,"\n"),root)
+ package = format(package,identifier,identifier,concat(used,"\n"),file.removesuffix(root))
I'm sure you make a better fix (I've attached the patched one in case it's easier to diff).
Not sure if you want to do something about the other errors, but it'd be nice to have a valid epub in the end.
Adam
[1] http://code.google.com/p/epubcheck/
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: epub.log --]
[-- Type: text/x-log; name="epub.log", Size: 990 bytes --]
Epubcheck Version 1.2
ERROR: test.tree/test.epub: extra field length for first filename must be 0, but was 28
ERROR: test.tree/test.epub/OPS/test.opf(3): value of attribute "unique-identifier" is invalid; must be an XML name without colons
ERROR: test.tree/test.epub/OPS/test.opf(8): value of attribute "id" is invalid; must be an XML name without colons
ERROR: test.tree/test.epub/OPS/test.opf(13): value of attribute "id" is invalid; must be an XML name without colons
ERROR: test.tree/test.epub/OPS/test.opf(14): value of attribute "id" is invalid; must be an XML name without colons
ERROR: test.tree/test.epub/OPS/test.opf(15): value of attribute "id" is invalid; must be an XML name without colons
ERROR: test.tree/test.epub/OPS/test.opf(18): item with id 'ncx' not found
ERROR: test.tree/test.epub/OPS/test.opf(19): item with id 'test.xhtml' not found
ERROR: test.tree/test.epub/OPS/test.xhtml(12): elements from namespace "" are not allowed
Check finished with warnings or errors!
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: my-mtx-epub.lua --]
[-- Type: text/x-lua; name="my-mtx-epub.lua", Size: 4279 bytes --]
if not modules then modules = { } end modules ['mtx-epub'] = {
version = 1.001,
comment = "companion to mtxrun.lua",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
local format = string.format
local concat = table.concat
local helpinfo = [[
--make create epub zip file
example:
mtxrun --script epub --make mydocument
]]
local application = logs.application {
name = "mtx-epub",
banner = "ConTeXt EPUB Helpers 0.10",
helpinfo = helpinfo,
}
-- script code
scripts = scripts or { }
scripts.epub = scripts.epub or { }
local mimetype = "application/epub+zip"
local container = [[
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="OPS/%s" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
]]
local package = [[
<?xml version="1.0"?>
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="%s">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
<dc:title>My Title</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="%s" />
<dc:creator opf:file-as="Self, My" opf:role="aut">MySelf</dc:creator>
</metadata>
<manifest>
%s
</manifest>
<spine toc="ncx">
<itemref idref="%s" />
</spine>
</package>
]]
local mimetypes = {
xhtml = "application/xhtml+xml",
css = "text/css",
}
-- specification = {
-- name = "document",
-- identifier = "123",
-- root = "a.xhtml",
-- files = {
-- "a.xhtml",
-- "b.css",
-- "c.png",
-- }
-- }
function scripts.epub.make()
local filename = environment.files[1]
if filename and filename ~= "" then
filename = file.basename(filename)
local specfile = file.replacesuffix(filename,"specification")
local specification = lfs.isfile(specfile) and dofile(specfile) or { }
-- inspect(specification)
local name = specification.name or file.removesuffix(filename)
local identifier = specification.identifier or os.uuid()
local files = specification.files or { file.addsuffix(filename,"xhtml") }
local root = specification.root or files[1]
local epubname = name
local epubpath = file.replacesuffix(name,"tree")
local epubfile = file.replacesuffix(name,"epub")
local epubroot = file.replacesuffix(name,"opf")
lfs.mkdir(epubpath)
lfs.mkdir(file.join(epubpath,"META-INF"))
lfs.mkdir(file.join(epubpath,"OPS"))
local used = { }
for i=1,#files do
local filename = files[i]
local suffix = file.suffix(filename)
local id = file.removesuffix(filename)
local mime = mimetypes[suffix]
if mime then
file.copy(filename,file.join(epubpath,"OPS",filename))
if suffix == "css" then
id = "stylesheet"
elseif suffix == "ncx" then
id = file.suffix(filename)
end
used[#used+1] = format("<item id='%s' href='%s' media-type='%s'/>",id,filename,mime)
end
end
container = format(container,epubroot)
package = format(package,identifier,identifier,concat(used,"\n"),file.removesuffix(root))
io.savedata(file.join(epubpath,"mimetype"),mimetype)
io.savedata(file.join(epubpath,"META-INF","container.xml"),container)
io.savedata(file.join(epubpath,"OPS",epubroot),package)
lfs.chdir(epubpath)
os.remove(epubfile)
os.execute(format("zip %s -0 %s",epubfile,"mimetype"))
os.execute(format("zip %s -r %s",epubfile,"META-INF"))
os.execute(format("zip %s -r %s",epubfile,"OPS"))
lfs.chdir("..")
application.report("epub archive: %s",file.join(epubpath,epubfile))
end
end
--
if environment.argument("make") then
scripts.epub.make()
else
application.help()
end
[-- Attachment #4: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
reply other threads:[~2011-05-13 19:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7B4626C28B06A7418E938BF73D6DEE18F9F571ED0A@KCL-MAIL05.kclad.ds.kcl.ac.uk \
--to=adam.reviczky@kcl.ac.uk \
--cc=ntg-context@ntg.nl \
--cc=pragma@wxs.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).