|
|
|
@ -1,5 +1,6 @@
@@ -1,5 +1,6 @@
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
// Copyright 2022 Ivan Polyakov
|
|
|
|
|
|
|
|
|
|
const { spawn } = require('child_process'); |
|
|
|
|
const { validate } = require('schema-utils'); |
|
|
|
|
|
|
|
|
@ -8,12 +9,15 @@ const schema = {
@@ -8,12 +9,15 @@ const schema = {
|
|
|
|
|
properties: { |
|
|
|
|
expr: { |
|
|
|
|
type: 'string', |
|
|
|
|
default: '(use-modules (sxml simple))(sxml->xml SXML_LOADER_CONTENT)', |
|
|
|
|
default: '(define loader-context \"SXML_LOADER_CONTEXT\")(use-modules (sxml simple))(sxml->xml SXML_LOADER_CONTENT)', |
|
|
|
|
}, |
|
|
|
|
doctype: { |
|
|
|
|
type: 'string', |
|
|
|
|
default: '<!DOCTYPE html>', |
|
|
|
|
}, |
|
|
|
|
afterTranslate: { |
|
|
|
|
instanceOf: 'Function', |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -32,10 +36,16 @@ module.exports = function(content, map, meta) {
@@ -32,10 +36,16 @@ module.exports = function(content, map, meta) {
|
|
|
|
|
if (options.expr) |
|
|
|
|
expr = options.expr; |
|
|
|
|
expr = expr.replace('SXML_LOADER_CONTENT', content); |
|
|
|
|
expr = expr.replace('SXML_LOADER_CONTEXT', this.context + '/'); |
|
|
|
|
|
|
|
|
|
const cb = this.async(); |
|
|
|
|
runScheme('guile', ['-c', expr]).then(data => { |
|
|
|
|
cb(null, `${doctype}\n${data}`, map, meta); |
|
|
|
|
let markup = `${doctype}\n${data}`; |
|
|
|
|
if (options.afterTranslate) { |
|
|
|
|
markup = options.afterTranslate(markup); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cb(null, markup, map, meta); |
|
|
|
|
}).catch(code => { |
|
|
|
|
console.error(`Guile exited with code ${code}`); |
|
|
|
|
}); |
|
|
|
@ -45,15 +55,10 @@ function runScheme(interpreter, flags) {
@@ -45,15 +55,10 @@ function runScheme(interpreter, flags) {
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
const scheme = spawn(interpreter, flags); |
|
|
|
|
|
|
|
|
|
scheme.stdout.on('data', (data) => { |
|
|
|
|
resolve(data); |
|
|
|
|
}); |
|
|
|
|
scheme.stdout.on('data', resolve); |
|
|
|
|
scheme.stderr.on('data', (data) => { |
|
|
|
|
console.error(data.toString()); |
|
|
|
|
}); |
|
|
|
|
scheme.on('exit', (code) => { |
|
|
|
|
if (code) |
|
|
|
|
reject(code); |
|
|
|
|
}); |
|
|
|
|
scheme.on('exit', reject); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|