Skip to content

Commit 6f7a0ba

Browse files
authored
Merge pull request #5086 from quarto-dev/fix/resource-path
`resource-path` should be taken into account for resource embeding
2 parents b969297 + 303c13d commit 6f7a0ba

File tree

8 files changed

+102
-4
lines changed

8 files changed

+102
-4
lines changed

src/command/render/render.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
kIncludeBeforeBody,
5353
kIncludeInHeader,
5454
kInlineIncludes,
55+
kResourcePath,
5556
} from "../../config/constants.ts";
5657
import { pandocIngestSelfContainedContent } from "../../core/pandoc/self-contained.ts";
5758

@@ -273,7 +274,10 @@ export async function renderPandoc(
273274
// If this is self-contained, run pandoc to 'suck in' the dependencies
274275
// which may have been added in the post processor
275276
if (selfContained && isHtmlFileOutput(format.pandoc)) {
276-
await pandocIngestSelfContainedContent(outputFile);
277+
await pandocIngestSelfContainedContent(
278+
outputFile,
279+
format.pandoc[kResourcePath],
280+
);
277281
}
278282
});
279283

src/config/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ export const kEmbedResources = "embed-resources";
418418
export const kIncludeBeforeBody = "include-before-body";
419419
export const kIncludeAfterBody = "include-after-body";
420420
export const kIncludeInHeader = "include-in-header";
421+
export const kResourcePath = "resource-path";
421422
export const kCiteproc = "citeproc";
422423
export const kCiteMethod = "cite-method";
423424
export const kFilters = "filters";
@@ -562,7 +563,7 @@ export const kPandocDefaultsKeys = [
562563
kIncludeBeforeBody,
563564
kIncludeAfterBody,
564565
kIncludeInHeader,
565-
"resource-path",
566+
kResourcePath,
566567
kCiteproc,
567568
kCiteMethod,
568569
"citation-abbreviations",

src/config/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ import {
153153
kRepoActionLinksEdit,
154154
kRepoActionLinksIssue,
155155
kRepoActionLinksSource,
156+
kResourcePath,
156157
kSearch,
157158
kSearchClearButtonTitle,
158159
kSearchCopyLinkTitle,
@@ -467,6 +468,7 @@ export interface FormatPandoc {
467468
[kIncludeBeforeBody]?: string[];
468469
[kIncludeAfterBody]?: string[];
469470
[kIncludeInHeader]?: string[];
471+
[kResourcePath]?: string[];
470472
[kReferenceLocation]?: string;
471473
[kCiteproc]?: boolean;
472474
[kCiteMethod]?: string;

src/core/pandoc/self-contained.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { basename, dirname } from "path/mod.ts";
88
import { formatResourcePath, pandocBinaryPath } from "../../core/resources.ts";
99
import { execProcess } from "../../core/process.ts";
1010

11-
export const pandocIngestSelfContainedContent = async (file: string) => {
11+
export const pandocIngestSelfContainedContent = async (
12+
file: string,
13+
resourcePath?: string[],
14+
) => {
1215
const filename = basename(file);
1316
const workingDir = dirname(file);
1417

@@ -33,6 +36,9 @@ export const pandocIngestSelfContainedContent = async (file: string) => {
3336
cmd.push("--output", filename);
3437
cmd.push("--metadata", "title=placeholder");
3538
cmd.push("--embed-resources");
39+
if (resourcePath && resourcePath.length) {
40+
cmd.push("--resource-path", resourcePath.join(":"));
41+
}
3642
const result = await execProcess({
3743
cmd,
3844
stdout: "piped",

src/format/reveal/format-reveal-multiplex.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { existsSync } from "fs/mod.ts";
88
import { join } from "path/mod.ts";
99
import { isSelfContainedOutput } from "../../command/render/render-info.ts";
10+
import { kResourcePath } from "../../config/constants.ts";
1011

1112
import { Format, FormatExtras, PandocFlags } from "../../config/types.ts";
1213
import { pandocIngestSelfContainedContent } from "../../core/pandoc/self-contained.ts";
@@ -80,7 +81,10 @@ export function revealMultiplexExtras(
8081

8182
// If this is self contained, we should ingest dependencies
8283
if (selfContained) {
83-
await pandocIngestSelfContainedContent(speakerOutput);
84+
await pandocIngestSelfContainedContent(
85+
speakerOutput,
86+
format.pandoc[kResourcePath],
87+
);
8488
}
8589
}],
8690
};
4.04 KB
Loading
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
format:
3+
html:
4+
embed-resources: true
5+
resource-path: ["dummy"]
6+
_quarto:
7+
tests:
8+
html:
9+
ensureHtmlElements:
10+
- ['img[src^="data:image/png;base64"]']
11+
- ['img[src^="temp.png"]']
12+
---
13+
14+
# show the plot
15+
16+
![alt text](temp.png "tooltip")

tests/new-smoke-all-test.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
smokeAllFolder=./docs/smoke-all
2+
3+
cwd=$(dirname $0)
4+
5+
cd $smokeAllFolder
6+
7+
year=$(date +"%Y")
8+
month=$(date +"%m")
9+
day=$(date +"%d")
10+
11+
CheckCreateAndEnter() {
12+
[[ ! -d "$1" ]] && mkdir -p $1
13+
cd $1
14+
}
15+
16+
CheckCreateAndEnter $year
17+
CheckCreateAndEnter $month
18+
CheckCreateAndEnter $day
19+
20+
file=$1
21+
22+
YAML=$(cat << EOF
23+
---
24+
format: html
25+
_quarto:
26+
tests:
27+
html:
28+
ensureHtmlElements:
29+
- []
30+
- []
31+
ensureFileRegexMatches:
32+
- []
33+
- []
34+
latex:
35+
ensureFileRegexMatches:
36+
- []
37+
- []
38+
pdf:
39+
noErrors: default
40+
fileExists:
41+
supportPath: mediabag/lter_penguins.png
42+
docx:
43+
ensureDocxRegexMatches:
44+
- []
45+
- []
46+
pptx:
47+
ensurePptxRegexMatches:
48+
- []
49+
- []
50+
asciidoc: default
51+
---
52+
EOF
53+
)
54+
55+
if [ ! -f "$file" ]; then
56+
echo "$YAML" > $file
57+
fi
58+
59+
if [[ -z $(command -v code) ]]; then
60+
vscode=true
61+
fi
62+
63+
$vscode && code $file
64+
65+
cd $cwd

0 commit comments

Comments
 (0)