Gramforge

Render API reference

Exports of @gramforge/render. Back to the module

Functions

entitiesForNodes

function

Render an arbitrary RichText node sequence to `{ text, entities }`. Internal: shared by {@link toEntities} and the RichBlock lowering in `./richmessage`.

entitiesForNodes(nodes: readonly RichTextNode[]): EntitiesPayload

toEntities

function

The DEFAULT renderer. Lowers a validated `MessageText`/`CaptionText` to the Bot API `{ text, entities }` payload with UTF-16 code-unit offsets.

toEntities(message: MessageText | CaptionText): EntitiesPayload

toHtml

function

Render a validated message/caption to Telegram's supported HTML subset.

toHtml(message: MessageText | CaptionText): string

toMarkdownV2

function

RENDER FALLBACK ONLY — see the file header. Render a validated message/caption to Telegram MarkdownV2 wire text with all reserved characters escaped.

toMarkdownV2(message: MessageText | CaptionText): string

toRichMessage

function

Capability-flagged partial renderer for the Bot API 10.1 block subset. The `capability` token is a REQUIRED parameter — omitting it is a type error.

toRichMessage(nodes: readonly RichBlockNode[], capability: RichMessageCapability): RenderRichMessageResult

Types

EntityLanguage

type

Presence of a `pre` block's language tag, as a DU (no `.optional()`).

type EntityLanguage = | { readonly kind: "known"; readonly value: string }
  | { readonly kind: "unknown" }

MessageEntity

type

The Bot API `MessageEntity` union, as produced by {@link toEntities}.

type MessageEntity = SimpleEntity | PreEntity | TextLinkEntity | TextMentionEntity

SimpleEntityType

type

Entity types that carry no extra fields beyond `offset`/`length`.

type SimpleEntityType = | "bold"
  | "italic"
  | "underline"
  | "strikethrough"
  | "code"
  | "blockquote"
  | "expandable_blockquote"
  | "spoiler"
  | "mention"

LoweredBlock

type
type LoweredBlock = LoweredHeading | LoweredMath | LoweredTable | LoweredCollapsible

RenderRichMessageResult

type
type RenderRichMessageResult = | { readonly kind: "ok"; readonly value: RichMessagePayload }
  | { readonly kind: "unsupported-node"; readonly nodeKind: string }

Interfaces

EntitiesPayload

interface

The default render payload: the plain text plus its formatting entities.

interface EntitiesPayload

text

property
text: string

entities

property
entities: readonly MessageEntity[]

PreEntity

interface

A `pre` (code block) entity, optionally carrying a language tag.

interface PreEntity

type

property
type: "pre"

offset

property
offset: number

length

property
length: number

language

property
language: EntityLanguage

SimpleEntity

interface

A formatting entity with no type-specific payload.

interface SimpleEntity

type

property
type: SimpleEntityType

offset

property
offset: number

length

property
length: number

TextLinkEntity

interface

A `text_link` entity — inline text linking to `url`.

interface TextLinkEntity

type

property
type: "text_link"

offset

property
offset: number

length

property
length: number

url

property
url: string

TextMentionEntity

interface

A `text_mention` entity — a mention of a user by numeric id.

interface TextMentionEntity

type

property
type: "text_mention"

offset

property
offset: number

length

property
length: number

user

property
user: { readonly id: number; }

LoweredCollapsible

interface
interface LoweredCollapsible

kind

property
kind: "collapsible"

summary

property
summary: EntitiesPayload

blocks

property
blocks: readonly LoweredBlock[]

LoweredHeading

interface
interface LoweredHeading

kind

property
kind: "heading"

level

property
level: 1 | 2 | 3 | 4

content

property
content: EntitiesPayload

LoweredMath

interface
interface LoweredMath

kind

property
kind: "math"

latex

property
latex: string

LoweredTable

interface
interface LoweredTable

kind

property
kind: "table"

header

property
header: readonly EntitiesPayload[]

rows

property
rows: readonly (readonly EntitiesPayload[])[]

RichMessageCapability

interface

The capability token gating access to the 10.1 rich-message surface.

interface RichMessageCapability

kind

property
kind: "rich-message-10-1"

RichMessagePayload

interface

The successfully-lowered 10.1 rich message.

interface RichMessagePayload

blocks

property
blocks: readonly LoweredBlock[]

Constants

EntitiesPayloadSchema

const
const EntitiesPayloadSchema: z.ZodType<EntitiesPayload, z.ZodTypeDef, EntitiesPayload>

MessageEntitySchema

const
const MessageEntitySchema: z.ZodType<MessageEntity, z.ZodTypeDef, MessageEntity>