Skip to content

JSONSerializer

@blobs/sdk v0.1.0


@blobs/sdk / serializers / JSONSerializer

Defined in: serializers/JSONSerializer.ts:18

Serializer that converts JSON content to and from HTML for editing.

toHTML formats and syntax-highlights the JSON for display inside a contenteditable element; toContent strips the highlight markup, parses the result, and re-emits a canonically-indented JSON string so the round trip preserves structure. Invalid JSON is preserved as-is so users can edit mid-typing without the serializer destroying partial input.

Extends

Constructors

Constructor

new JSONSerializer(config?): JSONSerializer

Defined in: serializers/JSONSerializer.ts:27

Parameters

config?

SerializerConfig

Optional SerializerConfig overrides.

Returns

JSONSerializer

Overrides

BaseSerializer.constructor

Properties

config

protected config: SerializerConfig

Defined in: serializers/BaseSerializer.ts:35

Effective configuration (defaults merged with constructor overrides).

Inherited from

BaseSerializer.config


format

readonly format: ContentFormat = 'json'

Defined in: serializers/JSONSerializer.ts:19

The content format this serializer handles.

Overrides

BaseSerializer.format

Methods

configure()

configure(config): void

Defined in: serializers/BaseSerializer.ts:62

Merges new options into the current configuration.

Parameters

config

SerializerConfig

Partial config to apply.

Returns

void

Inherited from

BaseSerializer.configure


getConfig()

getConfig(): SerializerConfig

Defined in: serializers/BaseSerializer.ts:69

Returns a defensive copy of the current configuration.

Returns

SerializerConfig

Inherited from

BaseSerializer.getConfig


escapeHTML()

protected escapeHTML(text): string

Defined in: serializers/BaseSerializer.ts:76

Escape HTML special characters

Parameters

text

string

Returns

string

Inherited from

BaseSerializer.escapeHTML


unescapeHTML()

protected unescapeHTML(html): string

Defined in: serializers/BaseSerializer.ts:90

Unescape HTML entities back to characters

Parameters

html

string

Returns

string

Inherited from

BaseSerializer.unescapeHTML


createLineBreak()

protected createLineBreak(): string

Defined in: serializers/BaseSerializer.ts:105

Create a line break element based on config

Returns

string

Inherited from

BaseSerializer.createLineBreak


wrapParagraph()

protected wrapParagraph(content, className?): string

Defined in: serializers/BaseSerializer.ts:116

Create a paragraph wrapper

Parameters

content

string

className?

string

Returns

string

Inherited from

BaseSerializer.wrapParagraph


stripTags()

protected stripTags(html): string

Defined in: serializers/BaseSerializer.ts:124

Strip all HTML tags from a string

Parameters

html

string

Returns

string

Inherited from

BaseSerializer.stripTags


normalizeWhitespace()

protected normalizeWhitespace(text): string

Defined in: serializers/BaseSerializer.ts:131

Normalize whitespace in content

Parameters

text

string

Returns

string

Inherited from

BaseSerializer.normalizeWhitespace


divBreaksToNewlines()

protected divBreaksToNewlines(html): string

Defined in: serializers/BaseSerializer.ts:141

Convert contenteditable div breaks to newlines

Parameters

html

string

Returns

string

Inherited from

BaseSerializer.divBreaksToNewlines


parseHTML()

protected parseHTML(html): string

Defined in: serializers/BaseSerializer.ts:161

Parse HTML using DOMParser if available, fallback to regex

Parameters

html

string

Returns

string

Inherited from

BaseSerializer.parseHTML


toContent()

toContent(html): ParsedContent

Defined in: serializers/JSONSerializer.ts:41

Strips syntax-highlight markup from contenteditable HTML and returns a canonically-indented JSON string. Falls back to the raw text when the input is not valid JSON.

Parameters

html

string

HTML emitted by the editor.

Returns

ParsedContent

Overrides

BaseSerializer.toContent


toHTML()

toHTML(content): RenderedHTML

Defined in: serializers/JSONSerializer.ts:78

Renders a JSON string into HTML with syntax highlighting wrapped in a configurable container. Invalid JSON is rendered unchanged so the editor can still display it.

Parameters

content

string

JSON content to render.

Returns

RenderedHTML

Overrides

BaseSerializer.toHTML