@@ -5,43 +5,42 @@ import {formats} from "./constants"
55import { fileToString , flattenDirectory } from "./helpers"
66
77export 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