UNPKG

@spoolcms/nextjs

Version:

The beautiful headless CMS for Next.js developers

73 lines (72 loc) 1.71 kB
"use strict"; /** * MarkdownField class provides an intuitive interface for markdown fields * Defaults to HTML output but allows access to raw markdown */ Object.defineProperty(exports, "__esModule", { value: true }); exports.MarkdownField = void 0; exports.createMarkdownField = createMarkdownField; exports.isMarkdownField = isMarkdownField; class MarkdownField { constructor(markdown, html) { this._markdown = markdown || ''; this._html = html || markdown || ''; } /** * Default behavior: return HTML when field is used directly * This allows: <div dangerouslySetInnerHTML={{ __html: post.body }} /> * Or even simpler: <div>{post.body}</div> (though this won't render HTML) */ toString() { return this._html; } /** * Explicit HTML access */ get html() { return this._html; } /** * Explicit markdown access */ get markdown() { return this._markdown; } /** * For JSON serialization */ toJSON() { return this._html; } /** * For template literal usage */ valueOf() { return this._html; } /** * Check if field has content */ get isEmpty() { return !this._markdown && !this._html; } /** * Get length of HTML content */ get length() { return this._html.length; } } exports.MarkdownField = MarkdownField; /** * Create a MarkdownField instance */ function createMarkdownField(markdown, html) { return new MarkdownField(markdown, html); } /** * Check if a value is a MarkdownField */ function isMarkdownField(value) { return value instanceof MarkdownField; }