Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/command/render/layout.ts
3584 views
1
/*
2
* layout.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { Document, Element } from "../../core/deno-dom.ts";
8
9
import { kPageWidth } from "../../config/constants.ts";
10
import { Format, FormatPandoc } from "../../config/types.ts";
11
import { Metadata } from "../../config/types.ts";
12
13
import { HtmlPostProcessResult } from "./types.ts";
14
import {
15
hasAdaptiveTheme,
16
hasTextHighlighting,
17
} from "../../quarto-core/text-highlighting.ts";
18
import { kHtmlEmptyPostProcessResult } from "./constants.ts";
19
20
const kAdaptiveTextHighlighting = "adaptive-text-highlighting";
21
const kTextHighlighting = "text-highlighting";
22
23
export function layoutFilterParams(
24
format: Format,
25
defaults: FormatPandoc | undefined,
26
) {
27
const params: Metadata = {};
28
const pageWidth = format.render[kPageWidth];
29
if (pageWidth) {
30
params[kPageWidth] = pageWidth;
31
}
32
if (defaults) {
33
if (hasAdaptiveTheme(defaults)) {
34
params[kAdaptiveTextHighlighting] = true;
35
}
36
37
if (hasTextHighlighting(defaults)) {
38
params[kTextHighlighting] = true;
39
}
40
}
41
42
return params;
43
}
44
45
export function overflowXPostprocessor(
46
doc: Document,
47
): Promise<HtmlPostProcessResult> {
48
// look for cell-output-display (these will have overflow-x set on them which we
49
// will want to disable in some conditions)
50
const outputs = doc.querySelectorAll(".cell-output-display");
51
for (let i = 0; i < outputs.length; i++) {
52
const output = outputs[i] as Element;
53
const noOverflowX =
54
// select inputs end up having their drop down truncated
55
!!output.querySelector("select") ||
56
// shiny can inject select boxes (for example) which will be truncated
57
// see https://github.com/quarto-dev/quarto-cli/issues/8091
58
!!output.querySelector(".shiny-html-output") ||
59
// the rgl htmlwidget barely overflows the container and gets scrollbars
60
// see https://github.com/quarto-dev/quarto-cli/issues/1800
61
!!output.querySelector(".rglWebGL");
62
if (noOverflowX) {
63
output.classList.add("no-overflow-x");
64
}
65
}
66
return Promise.resolve(kHtmlEmptyPostProcessResult);
67
}
68
69