Skip to content
Marcos Caceres edited this page Mar 27, 2026 · 14 revisions

preProcess

Type: Array<(config: Object, document: Document) => void | Promise<void>> Default: []

An array of functions that run before ReSpec begins processing. Use this to fetch external data, modify the DOM before ReSpec sees it, or set up configuration that depends on async operations.

Usage

async function loadFeatureData(config, document) {
  const res = await fetch("/api/features.json");
  const data = await res.json();
  // Make data available to the spec
  window.featureData = data;
}

var respecConfig = {
  preProcess: [loadFeatureData],
};
function addDynamicSection(config, document) {
  const section = document.createElement("section");
  section.innerHTML = `<h2>Dynamic Content</h2><p>Generated at ${new Date().toISOString()}</p>`;
  document.body.insertAdjacentElement("beforeend", section);
}

var respecConfig = {
  preProcess: [addDynamicSection],
};

Notes

  • Functions are run in order, and ReSpec waits for each to complete before running the next
  • async functions are fully supported — ReSpec awaits each function
  • The function receives (config, document)config is the respecConfig object; document is the HTML document
  • preProcess runs before structure, definitions, xref, and all other ReSpec processing — the document is still in its original source form
  • For post-processing after ReSpec is done, see postProcess

Guides

Configuration options

W3C Configuration options

Linting rules

Internal properties

Handled by ReSpec for you.

Special <section> IDs

HTML elements

Custom Elements

HTML attributes

CSS Classes

Special properties

Clone this wiki locally