@croct/content-model
Version:
A library for modeling, validating and interpolating structured content.
53 lines (52 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.richTextSchema = exports.richTextTemplate = void 0;
exports.createRichTextSchema = createRichTextSchema;
/**
* A rich text definition template.
*/
exports.richTextTemplate = {
type: 'text',
logicalType: 'richText',
template: true,
};
/**
* A schema for validating the properties of a rich text definition template.
*/
exports.richTextSchema = {
type: 'object',
properties: {
format: {
title: 'Format',
description: 'The format of the rich text.',
examples: ['html', 'markdown'],
type: 'string',
minLength: 1,
},
},
additionalProperties: false,
required: ['format'],
};
/**
* Creates a schema for validating the properties of a rich text definition template.
*
* @param options The options for the schema.
*/
function createRichTextSchema(options = {}) {
return {
type: 'object',
properties: {
format: {
title: 'Format',
description: 'The format of the rich text.',
examples: ['html', 'markdown'],
type: 'string',
minLength: 1,
...(options.allowedFormats !== undefined
? { enum: [...new Set(options.allowedFormats)] }
: {}),
},
},
required: ['format'],
};
}