UNPKG

@contentstack/utils

Version:
39 lines 1.74 kB
import { findRenderContent } from './helper/find-render-content'; import { findEmbeddedItems } from './helper/find-embeded-object'; import { enumerate, enumerateContents } from './helper/enumerate-entries'; /** * Converts Supercharged RTE (JSON) content to HTML for one or more entries. * Walks the given paths on each entry, finds JSON RTE content, resolves embedded * items from the entry, and renders nodes using the optional renderOption. Mutates * the entry JSON in-place by replacing content with the generated HTML. * * @param option - Configuration for conversion. * @param option.entry - Entry or array of entries that contain Supercharged RTE (JSON) fields. * @param option.paths - Key paths to the JSON RTE fields (e.g. `['rte_field_uid', 'group.rte_uid']`). * @param option.renderOption - Optional render options to customize how nodes and embedded items are rendered to HTML. */ export function jsonToHTML(option) { if (option.entry instanceof Array) { enumerate(option.entry, function (entry) { jsonToHTML({ entry: entry, paths: option.paths, renderOption: option.renderOption }); }); } else { enumerateKeys({ entry: option.entry, paths: option.paths, renderOption: option.renderOption, }); } } function enumerateKeys(option) { for (var _i = 0, _a = option.paths; _i < _a.length; _i++) { var key = _a[_i]; findRenderContent(key, option.entry, (function (content) { return enumerateContents(content, option.renderOption, function (metadata) { return findEmbeddedItems(metadata, option.entry)[0]; }); })); } } //# sourceMappingURL=json-to-html.js.map