document.respec - speced/respec GitHub Wiki
ReSpec adds a respec object to document when it loads. Use it to wait for processing to complete, inspect errors and warnings, or export the processed HTML.
A Promise that resolves when ReSpec finishes all processing (including postProcess functions).
<script>
document.addEventListener("DOMContentLoaded", async () => {
await document.respec.ready;
console.log("Errors:", document.respec.errors);
console.log("Warnings:", document.respec.warnings);
});
</script>An array of errors found during processing.
An array of warnings found during processing.
Each item in errors and warnings has:
| Property | Type | Description |
|---|---|---|
message |
string |
The error/warning message text |
plugin |
string |
Name of the ReSpec plugin that generated it (e.g. "core/xref") |
hint |
string |
Optional suggestion for how to fix it |
title |
string |
Short form of the message (used as element tooltip) |
elements |
HTMLElement[] |
The offending elements in the document, if applicable |
details |
string |
Additional context or explanation |
cause |
object |
The underlying error that caused this one, if any |
The current ReSpec version string (semver, e.g. "35.8.0").
Returns a Promise that resolves with the fully-processed document markup as a string — the same output as "Save as HTML".
<script>
document.addEventListener("DOMContentLoaded", async () => {
await document.respec.ready;
const html = await document.respec.toHTML();
// Send to a server, save to disk, etc.
await fetch("/save", { method: "POST", body: html });
});
</script>- Always
await document.respec.readybefore readingerrors/warnings— the arrays are populated incrementally during processing - The deprecated
document.respecIsReadywas a bare Promise ondocument; the modern form isdocument.respec.ready