Browse Source

afterTranslate hook added

dev
Ivan Polyakov 2 years ago
parent
commit
f190313fc9
  1. 10
      README.md
  2. 20
      loader.js
  3. 2
      package.json

10
README.md

@ -41,12 +41,16 @@ Options @@ -41,12 +41,16 @@ Options
-------
```
| Option | Description |
| ======= | ============================================================= |
| doctype | The document type at the top of the markup. `html` by default |
| ------- | ------------------------------------------------------------- |
| ============== | ====================================================== |
| doctype | The document type at the top of the markup. |
| | `html` by default |
| -------------- | ------------------------------------------------------ |
| expr | A Scheme expression that processes your markup. |
| | Insert `SXML_LOADER_CONTENT` where you want to process |
| | the markup list. |
| -------------- | ------------------------------------------------------ |
| afterTranslate | A hook called after the SXML to HTML translation |
| | is complete. `afterTranslate(markup: string): string` |
```
License

20
loader.js

@ -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');
@ -14,6 +15,9 @@ const schema = { @@ -14,6 +15,9 @@ const schema = {
type: 'string',
default: '<!DOCTYPE html>',
},
afterTranslate: {
instanceOf: 'Function',
},
},
};
@ -35,7 +39,12 @@ module.exports = function(content, map, meta) { @@ -35,7 +39,12 @@ module.exports = function(content, map, meta) {
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 +54,10 @@ function runScheme(interpreter, flags) { @@ -45,15 +54,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);
});
}

2
package.json

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
{
"name": "sxml-loader",
"version": "0.3.2",
"version": "0.3.3",
"description": "Scheme XML loader for webpack",
"main": "loader.js",
"bugs": "http://git.vilor.one/vilor/sxml-loader/issues",

Loading…
Cancel
Save