Skip to content

Commit 21c7f4d

Browse files
cscheidcderv
authored andcommitted
communicate single-file source correctly to lua filters
1 parent 77633b3 commit 21c7f4d

3 files changed

Lines changed: 22 additions & 20 deletions

File tree

‎src/command/render/filters.ts‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ import { quartoConfig } from "../../core/quarto.ts";
8585
import { metadataNormalizationFilterActive } from "./normalize.ts";
8686
import { kCodeAnnotations } from "../../format/html/format-html-shared.ts";
8787
import { projectOutputDir } from "../../project/project-shared.ts";
88-
import { relative } from "../../deno_ral/path.ts";
88+
import { basename, relative } from "../../deno_ral/path.ts";
8989
import { citeIndexFilterParams } from "../../project/project-cites.ts";
9090
import { debug } from "../../deno_ral/log.ts";
9191
import { kJatsSubarticle } from "../../format/jats/format-jats-types.ts";
@@ -660,7 +660,11 @@ async function quartoFilterParams(
660660
params[kHasResourcePath] = hasResourcePath;
661661

662662
// The source document
663-
params[kQuartoSource] = options.source;
663+
if (options.project.isSingleFile) {
664+
params[kQuartoSource] = basename(options.source);
665+
} else {
666+
params[kQuartoSource] = options.source;
667+
}
664668

665669
// profile as an array
666670
params[kQuartoProfile.toLowerCase()] = activeProfiles();
@@ -860,7 +864,7 @@ async function resolveFilterExtension(
860864
}
861865

862866
let pathToResolve: string | null = null;
863-
867+
864868
if (typeof filter === "string") {
865869
pathToResolve = filter;
866870
} else if (typeof filter === "object" && filter.path) {
@@ -869,7 +873,9 @@ async function resolveFilterExtension(
869873

870874
if (pathToResolve) {
871875
// The filter string points to an executable file which exists
872-
if (existsSync(pathToResolve) && !Deno.statSync(pathToResolve).isDirectory) {
876+
if (
877+
existsSync(pathToResolve) && !Deno.statSync(pathToResolve).isDirectory
878+
) {
873879
return filter;
874880
}
875881

@@ -896,17 +902,19 @@ async function resolveFilterExtension(
896902
if (typeof filter === "string") {
897903
return extensionFilters;
898904
} else if (isFilterEntryPoint(filter)) {
899-
return extensionFilters.map(extFilter => {
905+
return extensionFilters.map((extFilter) => {
900906
if (typeof extFilter === "string") {
901907
return {
902-
type: extFilter.endsWith(".lua") ? "lua" : "json" as "lua" | "json",
908+
type: extFilter.endsWith(".lua")
909+
? "lua"
910+
: "json" as "lua" | "json",
903911
path: extFilter,
904-
at: filter.at
912+
at: filter.at,
905913
};
906914
} else {
907915
return {
908916
...extFilter,
909-
at: filter.at
917+
at: filter.at,
910918
};
911919
}
912920
});

‎src/resources/filters/quarto-pre/shiny.lua‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ function server_shiny()
112112
end,
113113

114114
Pandoc = function(doc)
115+
print(quarto.doc.output_file)
115116
codeCells["html_file"] = pandoc.path.split_extension(
116117
pandoc.path.filename(quarto.doc.output_file)
117118
) .. ".html"
@@ -123,7 +124,7 @@ function server_shiny()
123124
end
124125

125126
-- Write the code cells to a temporary file.
126-
codeCellsOutfile = pandoc.path.split_extension(quarto.doc.output_file) .. "-cells.tmp.json"
127+
local codeCellsOutfile = pandoc.path.split_extension(quarto.doc.output_file) .. "-cells.tmp.json"
127128
local file = io.open(codeCellsOutfile, "w")
128129
if file == nil then
129130
error("Error opening file: " .. codeCellsOutfile .. " for writing.")
@@ -132,7 +133,7 @@ function server_shiny()
132133
file:close()
133134

134135
-- Convert the json file to app.py by calling `shiny convert-cells`.
135-
appOutfile = pandoc.path.join({
136+
local appOutfile = pandoc.path.join({
136137
pandoc.path.directory(quarto.doc.output_file),
137138
"app.py"
138139
});

‎src/resources/pandoc/datadir/init.lua‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -645,16 +645,9 @@ local function inputFile()
645645
return source
646646
else
647647
local projectDir = projectDirectory()
648-
if projectDir then
649-
return pandoc.path.join({projectDir, source})
650-
else
651-
-- outside of a project, quarto already changes
652-
-- pwd to the file's directory prior to calling pandoc,
653-
-- so we should just use the filename
654-
-- https://github.com/quarto-dev/quarto-cli/issues/7424
655-
local path_parts = pandoc.path.split(source)
656-
return pandoc.path.join({pandoc.system.get_working_directory(), path_parts[#path_parts]})
657-
end
648+
-- we now always have a projectDir, even in single-file settings
649+
assert(projectDir)
650+
return pandoc.path.join({projectDir, source})
658651
end
659652
end
660653

0 commit comments

Comments
 (0)