You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

55 lines
1.4 KiB

// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright 2022 Ivan Polyakov
const { spawn } = require('child_process');
const { validate } = require('schema-utils');
const schema = {
type: 'object',
properties: {
expr: {
type: 'string',
default: '(use-modules (sxml simple))(sxml->xml SXML_LOADER_CONTENT)',
},
doctype: {
type: 'string',
default: '<!DOCTYPE html>',
},
},
};
module.exports = function(content, map, meta) {
const options = this.getOptions();
validate(schema, options, {
name: 'SXML Loader',
baseDataPath: 'options',
});
let doctype = schema.properties.doctype.default;
if (options.doctype)
doctype = options.doctype;
let expr = schema.properties.expr.default;
if (options.expr)
expr = options.expr;
expr = expr.replace('SXML_LOADER_CONTENT', content);
const cb = this.async();
runScheme('guile', ['-c', expr]).then(data => {
cb(null, `${doctype}\n${data}`, map, meta);
}).catch(err => {
console.error(err);
});
}
function runScheme(interpreter, flags) {
return new Promise((resolve, reject) => {
const scheme = spawn(interpreter, flags);
scheme.stdout.on('data', (data) => {
resolve(data);
});
scheme.stderr.on('data', (data) => {
reject(data.toString());
});
});
}