UNPKG

@markuplint/ml-spec

Version:

Types and schema that specs of the Markup languages for markuplint

26 lines (25 loc) 800 B
import { getSpec } from './get-spec.js'; const cachesBySpecs = new Map(); export function getContentModel( // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types el, specs) { const cacheByEl = cachesBySpecs.get(specs) ?? new Map(); const cached = cacheByEl.get(el); if (cached !== undefined) { return cached; } const spec = getSpec(el, specs); if (!spec) { cacheByEl.set(el, null); return null; } const conditions = spec.contentModel.conditional ?? []; for (const cond of conditions) { if (el.matches(cond.condition)) { cacheByEl.set(el, cond.contents); return cond.contents; } } cacheByEl.set(el, spec.contentModel.contents); return spec.contentModel.contents; }