Skip to content

Commit f42ddbb

Browse files
committed
extract title from file name and fix for simple file import
1 parent 72e2736 commit f42ddbb

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

fiduswriter/pandoc/static/js/modules/pandoc/importer.js

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,42 @@ import {formats} from "./constants"
55
import {fileToString, flattenDirectory} from "./helpers"
66

77
export class PandocConversionImporter extends PandocImporter {
8-
init() {
9-
return this.getTemplate().then(() => {
10-
if (
11-
formats
12-
.map(format => format[1])
13-
.flat()
14-
.includes(this.file.name.split(".").pop())
15-
) {
16-
return this.convertAndImport()
17-
} else {
18-
this.output.statusText = gettext("Unknown file type")
19-
return Promise.resolve(this.output)
20-
}
21-
})
8+
async init() {
9+
await this.getTemplate()
10+
if (
11+
formats
12+
.map(format => format[1])
13+
.flat()
14+
.includes(this.file.name.split(".").pop())
15+
) {
16+
return await this.convertAndImport()
17+
} else {
18+
this.output.statusText = gettext("Unknown file type")
19+
return this.output
20+
}
2221
}
2322

24-
convertAndImport() {
25-
const fromExtension = this.file.name.split(".").pop()
23+
async convertAndImport() {
24+
const nameParts = this.file.name.split(".")
25+
const fromExtension = nameParts.pop()
26+
this.title = nameParts.join(".")
2627
const format = formats.find(format => format[1].includes(fromExtension))
2728
const from = format[2]
2829
const binaryZip = format[3]
29-
const inData = binaryZip ? this.file : fileToString(this.file)
30-
31-
return import("wasm-pandoc")
32-
.then(({pandoc}) =>
33-
pandoc(`-s -f ${from} -t json --extract-media=.`, inData)
34-
)
35-
.then(({out, mediaFiles}) => {
36-
const images = Object.assign(
37-
this.additionalFiles?.images || {},
38-
flattenDirectory(mediaFiles)
39-
)
40-
return this.handlePandocJson(
41-
out,
42-
images,
43-
this.additionalFiles?.bibliography
44-
)
45-
})
30+
const inData = binaryZip ? this.file : await fileToString(this.file)
31+
const {pandoc} = await import("wasm-pandoc")
32+
const {out, mediaFiles} = await pandoc(
33+
`-s -f ${from} -t json --extract-media=.`,
34+
inData
35+
)
36+
const images = Object.assign(
37+
this.additionalFiles?.images || {},
38+
flattenDirectory(mediaFiles)
39+
)
40+
return this.handlePandocJson(
41+
out,
42+
images,
43+
this.additionalFiles?.bibliography
44+
)
4645
}
4746
}

0 commit comments

Comments
 (0)