Skip to Content
Documentation

songstress/prose

The reader of a manifest's prose, for an app that draws an extension's page.

See the manifest's prose. An app imports songstress/prose alone: it carries these three functions and nothing else, where songstress/manifest brings the validator and its schemas too.

What it exports is the SDK's own record of its public surface, which the SDK's tests hold to the code. Each type's fields, every description and every function's usage example are read from the SDK's source when the site is built, and each example is compiled against the SDK by its tests.

ProseBlock · ProseSpan · parseProse · proseSpans · proseToMarkdown

ProseBlock

A block of a page's text: a paragraph, a heading of the second or third level, or a list (the items that followed one another).

export type ProseBlock = {
    kind: 'paragraph';
    spans: ProseSpan[];
} | {
    kind: 'heading';
    level: 2 | 3;
    spans: ProseSpan[];
} | {
    kind: 'list';
    items: ProseSpan[][];
};

Refers to ProseSpan.

ProseSpan

A run of a block's text: plain, bold, emphasis, code, or a link to an https address.

export type ProseSpan = {
    kind: 'text' | 'strong' | 'emphasis' | 'code';
    text: string;
} | {
    kind: 'link';
    text: string;
    href: string;
};

parseProse

The blocks of a manifest's prose as a page draws them: a block that starts with ## or ### is a heading, blocks that start with - and follow one another are one list, and every other block is a paragraph.

export declare function parseProse(blocks: readonly string[]): ProseBlock[];
ParameterTypeDescription
blocksreadonly string[]

Returns ProseBlock[].

Example
import { parseProse } from 'songstress/prose'

parseProse(['## Sources', '- Search', '- Links', 'Both are **off** until an admin turns them on.'])
// a heading, a list of two items, a paragraph

Refers to ProseBlock.

proseSpans

A line of prose as its runs, in order: every character of the line is in exactly one of them.

export declare function proseSpans(line: string): ProseSpan[];
ParameterTypeDescription
linestring

Returns ProseSpan[].

Example
import { proseSpans } from 'songstress/prose'

proseSpans('Set `mode` to **collapse**.')
// [{ kind: 'text', text: 'Set ' }, { kind: 'code', text: 'mode' }, { kind: 'text', text: ' to ' },
//  { kind: 'strong', text: 'collapse' }, { kind: 'text', text: '.' }]

Refers to ProseSpan.

proseToMarkdown

A manifest's prose as Markdown, for a page's copy as text: the blocks as written, a blank line between them, and the items of one list on lines that follow one another.

export declare function proseToMarkdown(blocks: readonly string[]): string;
ParameterTypeDescription
blocksreadonly string[]

Returns string.

Example
import { proseToMarkdown } from 'songstress/prose'

proseToMarkdown(['Finds lyrics.', '- Synced', '- Plain'])
// 'Finds lyrics.\n\n- Synced\n- Plain'