Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/converters/libreoffice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const filters: Record<FileCategories, Record<string, string>> = {
odt: "writer8",
ott: "writer8_template",
pages: "Apple Pages",
// pdf: "writer_pdf_import",
pdf: "writer_pdf_import",
psw: "PocketWord File",
rtf: "Rich Text Format",
sdw: "StarOffice_Writer",
Expand All @@ -124,7 +124,9 @@ const filters: Record<FileCategories, Record<string, string>> = {
};

const getFilters = (fileType: string, converto: string) => {
if (fileType in filters.text && converto in filters.text) {
if (converto === "pdf") {
return [null, null];
} else if (fileType in filters.text && converto in filters.text) {
return [filters.text[fileType], filters.text[converto]];
} else if (fileType in filters.calc && converto in filters.calc) {
return [filters.calc[fileType], filters.calc[converto]];
Expand All @@ -148,7 +150,7 @@ export function convert(
const [inFilter, outFilter] = getFilters(fileType, convertTo);

if (inFilter) {
args.push(`--infilter="${inFilter}"`);
args.push("--infilter=${inFilter}");
}

if (outFilter) {
Expand Down
13 changes: 10 additions & 3 deletions tests/converters/libreoffice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test("invokes soffice with --headless and outdir derived from targetPath", async
expect(cmd).toBe("soffice");
expect(args).toEqual([
"--headless",
`--infilter="MS Word 2007 XML"`,
"--infilter=MS Word 2007 XML",
"--convert-to",
"odt:writer8",
"--outdir",
Expand All @@ -77,8 +77,15 @@ test("uses only outFilter when input has no filter (e.g., pdf -> txt)", async ()

const { args } = requireDefined(calls[0], "Expected at least one execFile call");

expect(args).not.toContainEqual(expect.stringMatching(/^--infilter=/));
expect(args).toEqual(["--headless", "--convert-to", "txt", "--outdir", "out", "in.pdf"]);
expect(args).toEqual([
"--headless",
"--infilter=writer_pdf_import",
"--convert-to",
"txt:Text",
"--outdir",
"out",
"in.pdf",
]);
});

test("uses only infilter when convertTo has no out filter (e.g., docx -> pdf)", async () => {
Expand Down