Skip to content

Render options ​

Conventions used by the examples on this page

So the same preamble is not repeated everywhere, the examples below assume this setting. Each block then shows only what it is demonstrating.

ts
import { loadReqIfPackage, ReqIfIndex } from "reqif-preview";

// The bytes of your .reqif or .reqifz file.
// See [Getting started](/guide/getting-started) for reading them from an
// <input type="file">, from Node, or from a URL.
declare const bytes: Uint8Array;

const pkg = await loadReqIfPackage(bytes);
const doc = pkg.document; // the first document in the package

// pkg.documents, not pkg.document: this is what resolves relations that cross
// the boundary between two .reqif files inside one .reqifz.
const index = new ReqIfIndex(pkg.documents);

const spec = doc.coreContent.specifications[0];
const obj = index.specObjects.get(spec.children[0].objectRef)!;

RenderOptions ​

The same object is accepted by renderPackageToHtml, renderDocumentToHtml and renderSpecification. Every property is optional.

Presentation ​

OptionTypeDefaultEffect
includeCssbooleantrueIncludes the default stylesheet in a <style> at the top of the output. If false, load it through reqif-preview/style.css or the DEFAULT_CSS export — see Stylesheet.
layout"stacked" | "tabs""stacked"CSS tabs between documents and between specifications. No effect when there is only one. Details
readingModebooleanfalseReading view: hides ID, created/modified and the technical panel; titles as <h3>…<h6>.
chapterNumbersbooleanfalsePrefixes titles with 1, 1.1, 1.1.1…, restarting at 1 per Specification.
chapterNumberAttributesstring[]—Numbers only nodes carrying one of these attributes. No effect without chapterNumbers.
labelsPartial<RenderLabels>EnglishReplaces the interface labels.
dateLocalestring"en-GB"Locale used to format the created/modified dates.

Content ​

OptionTypeDefaultEffect
contentAttributesstring[]—Strict allow-list of the attributes making up the main content, in this order. Details
titleAttributesstring[]—Attributes tried as a title as a last resort, after the LONG-NAMEs.
showTechnicalByDefaultbooleanfalseOpens the "Technical details" panel from the start.
hideEmptyAttributesbooleantrueOmits attributes with no value at all from the technical panel.
preferSimplifiedXhtmlbooleanfalseShows the simplified version rather than the original. Details
showRelationsbooleantrueShows incoming/outgoing links. Visible in readingMode too.
customAttributeRenderersCustomAttributeRenderer[]—Injects HTML of your own before/after the content.

The "(untitled)" / "(empty)" placeholders ​

OptionTypeEffect
suppressEmptyPlaceholdersForChaptersbooleanA shortcut for "chapter" objects. No effect without chapterNumberAttributes.
isTitleless(obj, specType, index) => booleanDecides, by your own criteria, that an empty title is normal for this object.
isContentless(obj, specType, index) => booleanThe same for empty content. Independent of the previous one.

The three compose: the placeholder is suppressed if any says yes. See Choosing exactly which title and content are shown.

Attachments and diagnostics ​

OptionTypeDefaultEffect
attachmentsAttachmentResolverthe package'sReplaces the resolver. Details
maxInlineBytesnumber5 * 1024 * 1024Maximum size inlined as a data: URI, per file.
onDegradationDegradationHandler—Observes everything the render silently degrades. Details

RenderLabels ​

Every interface label, English by default. labels accepts a partial object — only the labels you supply are replaced.

ts
interface RenderLabels {
  noContent: string;              // "(vide)"
  untitled: string;               // "(sans titre)"
  idLabel: string;
  technicalDetails: string;       // "Détails techniques"
  headerTitle: string;
  headerSourceTool: string;
  headerExportedBy: string;
  headerCreationTime: string;
  headerComment: string;
  yes: string;
  no: string;
  createdByLabel: string;
  createdOnLabel: string;
  modifiedByLabel: string;
  modifiedOnLabel: string;
  relationsLabel: string;         // "Liens"
  relationFallbackType: string;
  relationUnresolved: string;
}

FRENCH_LABELS ​

ts
const FRENCH_LABELS: RenderLabels;

The complete set this library shipped as its default until 0.2.0, so the previous rendering is one line away rather than eighteen:

ts
import { FRENCH_LABELS } from "reqif-preview";

const html = await renderPackageToHtml(pkg, {
  labels: FRENCH_LABELS,
  dateLocale: "fr-FR",
});

Any other language is the same shape — labels is partial, so supply only what you need.

CustomAttributeRenderer ​

ts
interface CustomAttributeRenderer {
  attribute: string;                    // long name (case/space-insensitive) or identifier
  position?: "before" | "after";        // default: "before"
  render(value: AttributeValue | undefined, ctx: AttributeRenderContext): RenderOutput;
  hideFromTechnical?: boolean;          // default: false
}

Two safety nets: an exception inside render() is caught (custom-renderer-threw), and unbalanced dangerouslyRawHtml is shown as escaped text (custom-renderer-unbalanced-html) rather than breaking the structure of everything that follows. See Custom renderers.

RenderOutput, RenderNode, RenderElement, RenderRawHtml ​

What a renderer returns. Text is escaped by default; raw markup has to be asked for by name.

ts
type RenderNode = string | RenderElement | RenderRawHtml;

interface RenderElement {
  tag: string;                      // allow-listed, otherwise unwrapped (unwrapped-tag)
  attrs?: Record<string, string>;   // allow-listed, values escaped
  children?: RenderNode[];          // a string here is text
}

interface RenderRawHtml {
  dangerouslyRawHtml: string;       // inserted verbatim — escape it yourself
}

type RenderOutput = RenderElement | RenderRawHtml | RenderNode[] | undefined;
Allowed
Tagsspan div p a code strong b em i small br img ul ol li
Attributesclass id title lang dir, plus href / src through the URL-scheme filter

style is deliberately absent — presentation belongs in your own stylesheet. A bare string is not accepted at the top level: under the previous API it meant raw HTML, so accepting it would silently change what existing renderers produce. From untyped JavaScript it is escaped, with custom-renderer-raw-string.

AttributeRenderContext ​

ts
interface AttributeRenderContext {
  specObject: SpecObject;
  specType: SpecType | undefined;
  index: ReqIfIndex;
  attachments: AttachmentLookup;
  isChapter: boolean;
  getValue(attributeNameOrId: string): AttributeValue | undefined;
  getDefinition(attributeNameOrId: string): AttributeDefinition | undefined;
  formatValue(value: AttributeValue | undefined): string;
}

formatValue reuses exactly the technical panel's formatting: enumeration labels resolved, XHTML sanitised, booleans following labels.yes/labels.no. It is the shortest way to display a value "as the library would" without reimplementing the type logic.

Released under the MIT licence. Conformant to OMG ReqIF v1.2 (formal/2016-07-01).