如何解决如何在 epub xhtml
我有一本电子书 (ebook1.epub),可以像这样加载 javascript 文件 (script1.js):
cat EPUB/xhtml/raw/ch1.xhtml
<!--?xml version='1.0' encoding='UTF-8'?-->
<!DOCTYPE html><html xml:lang="en-us" lang="en-us" xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<script type="text/javascript" src="../../js/script1.js"></script>
...
</head>
...
</html>
# --------------------------------------------------------------
cat EPUB/package.opf
...
<item id="js4" href="js/script1.js" media-type="text/javascript"/>
这行得通。我看这本书:
calibre ebook1.epub
script1 按预期工作(例如,从 script1 中调用 console.log("foo1") 会按预期响应并打印到启动 calibre 的终端)。
现在,我需要使用 Javascript 模块文件 (ES6) (script2.js) javascript 模块文件的加载方式如下:
cat EPUB/xhtml/raw/ch1.xhtml
<!--?xml version='1.0' encoding='UTF-8'?-->
<!DOCTYPE html><html xml:lang="en-us" lang="en-us" xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<script type="module" src="../../js/script2.js"></script>
...
</head>
...
</html>
# --------------------------------------------------------------
cat EPUB/package.opf
...
<item id="js4" href="js/script2.js" media-type="text/javascript"/>
当我运行 calibre 时
calibre ebook2.epub
script2 不起作用。
从 script2 调用函数:
- 不向终端打印任何内容。
- 终端显示错误消息:
ERROR: clbr://internal.sandbox/book/EPUB/js/script2.js:0: Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
如何在 .epub 中加载 javascript 模块 文件?
谢谢, 阿夫纳
解决方法
我从 here 安装了最新的 Calibre 版本 (5.22.1)。
安装后,我能够加载模块 javascript 文件,并在我启动 Calibre 的终端中看到来自 console.log() 的消息。
cat EPUB/xhtml/raw/ch1.xhtml
<!--?xml version='1.0' encoding='UTF-8'?-->
<!DOCTYPE html><html xml:lang="en-us" lang="en-us" xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<script type="module" src="../../js/script2.js"></script>
...
</head>
...
</html>
# --------------------------------------------------------------
cat EPUB/package.opf
...
<item id="js4" href="js/script2.js" media-type="module"/>
当我使用 calibre ebook2.epub
运行 calibre 时,script2.js 工作正常:
我可以在终端中看到来自 Console.log() 的消息。
解决方案来自this post。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。