@stencila/jesta
Version:
Stencila plugin for executable documents using JavaScript
47 lines (46 loc) • 1.79 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.export_ = exports.schema = void 0;
const path_1 = __importDefault(require("path"));
const write_1 = require("./write");
const { output, theme } = write_1.schema.properties;
exports.schema = {
title: 'export',
description: 'Export a node to a URL (including a `file://` or `string://` URL).',
required: ['node', 'output'],
properties: {
node: {
description: 'The node to export.',
},
output,
format: {
description: 'Format to export the documents to. Defaults to the file extension.',
type: 'string',
enum: ['json'],
},
downcast: {
description: 'Downcast the document before it is exported?',
type: 'boolean',
// Constant `false` because Jesta does not implement the downcast method
const: false,
},
validate: {
description: 'Validate the document before it is exported?',
type: 'boolean',
const: true,
},
theme,
},
};
async function export_(node, output, format,
// These default to false because Jesta has neither capability
downcast = false, validate = false, theme) {
const downcasted = downcast ? await this.downcast(node) : node;
const validated = validate ? await this.validate(downcasted) : downcasted;
const encoded = await this.encode(validated, format !== null && format !== void 0 ? format : path_1.default.extname(output).slice(1), theme);
return this.write(encoded, output);
}
exports.export_ = export_;