Skip to content

Commit 6e5f565

Browse files
committed
books: workaround for docx images in subdirs being removed from ast
1 parent 3f88fe5 commit 6e5f565

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/command/render/pandoc.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
} from "../../config/types.ts";
3737
import {
3838
isBeamerOutput,
39+
isDocxOutput,
3940
isEpubOutput,
4041
isHtmlDocOutput,
4142
isHtmlFileOutput,
@@ -69,7 +70,11 @@ import {
6970
pandocDefaultsMessage,
7071
writeDefaultsFile,
7172
} from "./defaults.ts";
72-
import { filterParamsJson, removeFilterParmas } from "./filters.ts";
73+
import {
74+
filterParamsJson,
75+
quartoInitFilter,
76+
removeFilterParmas,
77+
} from "./filters.ts";
7378
import {
7479
kAbstract,
7580
kAbstractTitle,
@@ -866,6 +871,35 @@ export async function runPandoc(
866871
);
867872
}
868873

874+
// for docx books we need to run a resolveRefs pass
875+
// workaround until this issue is resolved: https://github.com/jgm/pandoc/issues/8099
876+
if (isDocxOutput(options.format.pandoc) && projectIsBook(options.project)) {
877+
const docxCmd = [
878+
pandocBinaryPath(),
879+
inputTemp,
880+
"--to",
881+
"markdown",
882+
"--output",
883+
inputTemp,
884+
"--lua-filter",
885+
quartoInitFilter(),
886+
"--data-dir",
887+
resourcePath("pandoc/datadir"),
888+
];
889+
const docxResult = await execProcess(
890+
{
891+
cmd: docxCmd,
892+
cwd,
893+
env: {
894+
"QUARTO_FILTER_PARAMS": base64Encode(paramsJson),
895+
},
896+
},
897+
);
898+
if (!docxResult.success) {
899+
throw new Error();
900+
}
901+
}
902+
869903
// run pandoc
870904
const result = await execProcess(
871905
{

src/resources/filters/quarto-init/resourcerefs.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
-- Copyright (C) 2020 by RStudio, PBC
33

44
function resourceRefs()
5+
6+
-- for docx single single file books we've already processed the refs
7+
-- as part of a workaround for this issue https://github.com/jgm/pandoc/issues/8099
8+
if param("single-file-book", false) and _quarto.format.isDocxOutput() then
9+
return {}
10+
end
11+
512
return {
613
Image = function(el)
714
local file = currentFileMetadataState().file

0 commit comments

Comments
 (0)