Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/format/formats-shared.ts
6449 views
1
/*
2
* formats-shared.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { mergeConfigs } from "../core/config.ts";
8
9
import {
10
kCache,
11
kCodeFold,
12
kCodeLineNumbers,
13
kCodeLink,
14
kCodeOverflow,
15
kCodeTools,
16
kDefaultImageExtension,
17
kDfPrint,
18
kDisplayName,
19
kEcho,
20
kError,
21
kEval,
22
kExecuteDaemon,
23
kExecuteDaemonRestart,
24
kExecuteDebug,
25
kExecuteEnabled,
26
kExecuteIpynb,
27
kFigAlign,
28
kFigAsp,
29
kFigDpi,
30
kFigEnv,
31
kFigFormat,
32
kFigHeight,
33
kFigPos,
34
kFigResponsive,
35
kFigWidth,
36
kFormatResources,
37
kFreeze,
38
kInclude,
39
kIncludeInHeader,
40
kInlineIncludes,
41
kIpynbFilters,
42
kIpynbShellInteractivity,
43
kKeepHidden,
44
kKeepIpynb,
45
kKeepMd,
46
kKeepSource,
47
kKeepTex,
48
kKeepTyp,
49
kLang,
50
kLatexAutoInstall,
51
kLatexAutoMk,
52
kLatexClean,
53
kLatexInputPaths,
54
kLatexMakeIndex,
55
kLatexMakeIndexOpts,
56
kLatexMaxRuns,
57
kLatexMinRuns,
58
kLatexOutputDir,
59
kLatexTlmgrOpts,
60
kLinkExternalIcon,
61
kLinkExternalNewwindow,
62
kMergeIncludes,
63
kMermaidFormat,
64
kOutput,
65
kOutputDivs,
66
kOutputExt,
67
kPageWidth,
68
kPlotlyConnected,
69
kPreferHtml,
70
kPreserveYaml,
71
kQuartoVersion,
72
kSelfContainedMath,
73
kStandalone,
74
kTblColwidths,
75
kVariant,
76
kWarning,
77
kWrap,
78
} from "../config/constants.ts";
79
80
import { Format } from "../config/types.ts";
81
82
import { formatResourcePath } from "../core/resources.ts";
83
import { quartoConfig } from "../core/quarto.ts";
84
85
export function createFormat(
86
displayName: string,
87
ext: string,
88
...formats: Array<unknown>
89
): Format {
90
return mergeConfigs(
91
defaultFormat(displayName),
92
...formats,
93
{
94
render: {
95
[kOutputExt]: ext,
96
},
97
},
98
);
99
}
100
101
export function createHtmlFormat(
102
displayName: string,
103
figwidth: number,
104
figheight: number,
105
) {
106
return createFormat(displayName, "html", {
107
metadata: {
108
[kLang]: "en",
109
[kFigResponsive]: true,
110
[kQuartoVersion]: quartoConfig.version(),
111
},
112
execute: {
113
[kFigFormat]: "retina",
114
[kFigWidth]: figwidth,
115
[kFigHeight]: figheight,
116
},
117
render: {
118
[kTblColwidths]: "auto",
119
},
120
pandoc: {
121
[kStandalone]: true,
122
[kWrap]: "none",
123
[kDefaultImageExtension]: "png",
124
},
125
});
126
}
127
128
export function createHtmlPresentationFormat(
129
displayName: string,
130
figwidth: number,
131
figheight: number,
132
): Format {
133
return mergeConfigs(
134
createHtmlFormat(displayName, figwidth, figheight),
135
{
136
metadata: {
137
[kFigResponsive]: false,
138
},
139
execute: {
140
[kEcho]: false,
141
[kWarning]: false,
142
},
143
},
144
);
145
}
146
147
export function createEbookFormat(displayName: string, ext: string): Format {
148
return createFormat(displayName, ext, {
149
formatExtras: () => {
150
return {
151
[kIncludeInHeader]: [
152
formatResourcePath("html", "styles-callout.html"),
153
formatResourcePath("epub", "styles.html"),
154
],
155
};
156
},
157
render: {
158
[kMergeIncludes]: false,
159
},
160
execute: {
161
[kFigWidth]: 5,
162
[kFigHeight]: 4,
163
},
164
pandoc: {
165
[kDefaultImageExtension]: "png",
166
},
167
});
168
}
169
170
export function createWordprocessorFormat(
171
displayName: string,
172
ext: string,
173
): Format {
174
return createFormat(displayName, ext, {
175
render: {
176
[kPageWidth]: 6.5,
177
},
178
execute: {
179
[kFigWidth]: 5,
180
[kFigHeight]: 4,
181
},
182
pandoc: {
183
[kDefaultImageExtension]: "png",
184
},
185
});
186
}
187
188
export function plaintextFormat(displayName: string, ext: string): Format {
189
return createFormat(displayName, ext, {
190
pandoc: {
191
standalone: true,
192
[kDefaultImageExtension]: "png",
193
},
194
});
195
}
196
197
function defaultFormat(displayName: string): Format {
198
return {
199
identifier: {
200
[kDisplayName]: displayName,
201
},
202
execute: {
203
[kFigWidth]: 7,
204
[kFigHeight]: 5,
205
[kFigFormat]: "png",
206
[kFigDpi]: 96,
207
[kFigAsp]: undefined,
208
[kMermaidFormat]: undefined,
209
[kDfPrint]: "default",
210
[kError]: false,
211
[kEval]: true,
212
[kCache]: null,
213
[kFreeze]: false,
214
[kEcho]: true,
215
[kOutput]: true,
216
[kWarning]: true,
217
[kInclude]: true,
218
[kKeepMd]: false,
219
[kKeepIpynb]: false,
220
[kExecuteIpynb]: null,
221
[kExecuteEnabled]: null,
222
[kExecuteDaemon]: null,
223
[kExecuteDaemonRestart]: false,
224
[kExecuteDebug]: false,
225
[kIpynbFilters]: [],
226
[kIpynbShellInteractivity]: null,
227
[kPlotlyConnected]: true,
228
},
229
render: {
230
[kKeepTex]: false,
231
[kKeepTyp]: false,
232
[kKeepSource]: false,
233
[kKeepHidden]: false,
234
[kPreferHtml]: false,
235
[kOutputDivs]: true,
236
[kOutputExt]: "html",
237
[kFigAlign]: "default",
238
[kFigPos]: null,
239
[kFigEnv]: null,
240
[kCodeFold]: "none",
241
[kCodeOverflow]: "scroll",
242
[kCodeLink]: false,
243
[kCodeLineNumbers]: false,
244
[kCodeTools]: false,
245
[kTblColwidths]: true,
246
[kMergeIncludes]: true,
247
[kInlineIncludes]: false,
248
[kPreserveYaml]: false,
249
[kLatexAutoMk]: true,
250
[kLatexAutoInstall]: true,
251
[kLatexClean]: true,
252
[kLatexMinRuns]: 1,
253
[kLatexMaxRuns]: 10,
254
[kLatexMakeIndex]: "makeindex",
255
[kLatexMakeIndexOpts]: [],
256
[kLatexTlmgrOpts]: [],
257
[kLatexInputPaths]: [],
258
[kLatexOutputDir]: null,
259
[kLinkExternalIcon]: false,
260
[kLinkExternalNewwindow]: false,
261
[kSelfContainedMath]: false,
262
[kFormatResources]: [],
263
[kVariant]: "",
264
},
265
pandoc: {},
266
language: {},
267
metadata: {},
268
};
269
}
270
271