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

preProcess

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.

Usage

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],
};

Function signature

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

Notes

  • Functions run in order, and ReSpec awaits each one before proceeding
  • async functions are fully supported
  • preProcess runs 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

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