Skip to content

CodeSerializer

@blobs/sdk v0.1.0


@blobs/sdk / serializers / CodeSerializer

Defined in: serializers/PlainTextSerializer.ts:115

Serializer for source-code content.

Extends PlainTextSerializer with a monospace container, exact whitespace preservation, and a configurable wrapping CSS class. Code is never modified — the serializer only adjusts how it is wrapped for display.

Extends

Constructors

Constructor

new CodeSerializer(config?): CodeSerializer

Defined in: serializers/PlainTextSerializer.ts:122

Parameters

config?

SerializerConfig

Optional SerializerConfig overrides; whitespace preservation is forced on regardless of the input.

Returns

CodeSerializer

Overrides

PlainTextSerializer.constructor

Properties

config

protected config: SerializerConfig

Defined in: serializers/BaseSerializer.ts:35

Effective configuration (defaults merged with constructor overrides).

Inherited from

PlainTextSerializer.config


format

readonly format: ContentFormat = 'code'

Defined in: serializers/PlainTextSerializer.ts:116

The content format this serializer handles.

Overrides

PlainTextSerializer.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

PlainTextSerializer.configure


getConfig()

getConfig(): SerializerConfig

Defined in: serializers/BaseSerializer.ts:69

Returns a defensive copy of the current configuration.

Returns

SerializerConfig

Inherited from

PlainTextSerializer.getConfig


escapeHTML()

protected escapeHTML(text): string

Defined in: serializers/BaseSerializer.ts:76

Escape HTML special characters

Parameters

text

string

Returns

string

Inherited from

PlainTextSerializer.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

PlainTextSerializer.unescapeHTML


createLineBreak()

protected createLineBreak(): string

Defined in: serializers/BaseSerializer.ts:105

Create a line break element based on config

Returns

string

Inherited from

PlainTextSerializer.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

PlainTextSerializer.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

PlainTextSerializer.stripTags


normalizeWhitespace()

protected normalizeWhitespace(text): string

Defined in: serializers/BaseSerializer.ts:131

Normalize whitespace in content

Parameters

text

string

Returns

string

Inherited from

PlainTextSerializer.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

PlainTextSerializer.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

PlainTextSerializer.parseHTML


toHTML()

toHTML(content): RenderedHTML

Defined in: serializers/PlainTextSerializer.ts:134

Renders code content into a monospace contenteditable container.

Parameters

content

string

Source-code text.

Returns

RenderedHTML

Overrides

PlainTextSerializer.toHTML


toContent()

toContent(html): ParsedContent

Defined in: serializers/PlainTextSerializer.ts:152

Strips the monospace wrapper div (if present) before delegating to the plain-text round-trip.

Parameters

html

string

HTML emitted by the editor.

Returns

ParsedContent

Overrides

PlainTextSerializer.toContent