# songstress/prose

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

Page: https://songstress.app/docs/develop/reference/prose/

See [the manifest's prose](/docs/develop/manifest/). 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

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

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

Refers to [ProseSpan](/docs/develop/reference/prose/#type-ProseSpan).

### ProseSpan

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

```ts
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.

```ts
export declare function parseProse(blocks: readonly string[]): ProseBlock[];
```

| Parameter | Type | Description |
|---|---|---|
| `blocks` | `readonly string[]` |  |

Returns `ProseBlock[]`.

Example:

```ts
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](/docs/develop/reference/prose/#type-ProseBlock).

### proseSpans

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

```ts
export declare function proseSpans(line: string): ProseSpan[];
```

| Parameter | Type | Description |
|---|---|---|
| `line` | `string` |  |

Returns `ProseSpan[]`.

Example:

```ts
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](/docs/develop/reference/prose/#type-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.

```ts
export declare function proseToMarkdown(blocks: readonly string[]): string;
```

| Parameter | Type | Description |
|---|---|---|
| `blocks` | `readonly string[]` |  |

Returns `string`.

Example:

```ts
import { proseToMarkdown } from 'songstress/prose'

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