preProcess - speced/respec GitHub Wiki
Type: Array<(config: Object, document: Document, utils: Object) => void | Promise<void>>
Default: []
An array of functions that run before ReSpec begins processing. Use this to fetch external data, inject content into the document, or perform setup that other processing steps depend on.
async function loadTerms(config, document) {
const res = await fetch("https://api.example.org/terms.json");
const terms = await res.json();
// Inject <dfn> elements so xref can resolve them
const section = document.querySelector("#terminology");
for (const { id, label } of terms) {
const p = document.createElement("p");
p.innerHTML = `The <dfn data-export id="${id}">${label}</dfn> is ...`;
section.append(p);
}
}
var respecConfig = {
preProcess: [loadTerms],
};function addGeneratedSection(config, document) {
const section = document.createElement("section");
section.id = "build-info";
section.innerHTML = `
<h2>Build Information</h2>
<p>Built by: <strong>${config.editors[0].name}</strong></p>
`;
document.body.insertAdjacentElement("beforeend", section);
}
var respecConfig = {
preProcess: [addGeneratedSection],
};Each function receives three arguments:
| Argument | Type | Description |
|---|---|---|
config |
Object |
The respecConfig object plus ReSpec internal state |
document |
Document |
The HTML document in its original, unprocessed form |
utils |
Object |
ReSpec utility functions |
- Functions run in order, and ReSpec awaits each one before proceeding
-
asyncfunctions are fully supported -
preProcessruns before any ReSpec transformation — the document is still in its original source form. Definitions, headings, and xrefs have not yet been processed. - For post-processing after ReSpec is done, see
postProcess