Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/format/epub/format-epub.ts
6451 views
1
/*
2
* format-epub.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
8
import { Format } from "../../config/types.ts";
9
import { ProjectConfig } from "../../project/types.ts";
10
import { kEPubCoverImage, kHtmlMathMethod } from "../../config/constants.ts";
11
12
import { mergeConfigs } from "../../core/config.ts";
13
14
import {
15
bookConfig,
16
BookExtension,
17
kBookCoverImage,
18
} from "../../project/types/book/book-shared.ts";
19
import { createEbookFormat } from "../formats-shared.ts";
20
21
export function epubFormat(to: string): Format {
22
return mergeConfigs(
23
createEbookFormat("ePub", "epub"),
24
{
25
pandoc: {
26
[kHtmlMathMethod]: to === "epub2" ? "webtex" : "mathml",
27
},
28
extensions: {
29
book: epubBookExtension,
30
},
31
},
32
);
33
}
34
35
const epubBookExtension: BookExtension = {
36
selfContainedOutput: true,
37
onSingleFilePreRender: (format: Format, config?: ProjectConfig): Format => {
38
// derive epub-cover-image from cover-image if not explicitly specified
39
if (!format.pandoc[kEPubCoverImage] && !format.metadata[kBookCoverImage]) {
40
// is there a cover-image?
41
const coverImage = bookConfig(kBookCoverImage, config) as
42
| string
43
| undefined;
44
if (coverImage) {
45
format.metadata[kBookCoverImage] = coverImage;
46
}
47
}
48
49
return format;
50
},
51
};
52
53