forked from stencila/encoda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
36 lines (31 loc) · 1.01 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* [[include:src/codecs/odt/README.md]]
*
* @module codecs/odt
*/
import stencila from '@stencila/schema'
import * as vfile from '../../util/vfile'
import { InputFormat, OutputFormat, PandocCodec } from '../pandoc'
import { Codec, CommonDecodeOptions, CommonEncodeOptions } from '../types'
const pandoc = new PandocCodec()
export class ODTCodec extends Codec implements Codec {
public readonly mediaTypes = ['application/vnd.oasis.opendocument.text']
public readonly decode = async (
file: vfile.VFile,
options: CommonDecodeOptions = this.commonDecodeDefaults
): Promise<stencila.Node> => {
return pandoc.decode(file, options, {
pandocFormat: InputFormat.odt,
pandocArgs: [`--extract-media=${file.path}.media`],
})
}
public readonly encode = async (
node: stencila.Node,
options: CommonEncodeOptions = this.commonEncodeDefaults
): Promise<vfile.VFile> => {
return pandoc.encode(node, options, {
pandocFormat: OutputFormat.odt,
ensureFile: true,
})
}
}