Render API reference
Exports of @gramforge/render. Back to the module
Functions
entitiesForNodes
functionRender 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
functionThe 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
functionRender a validated message/caption to Telegram's supported HTML subset.
toHtml(message: MessageText | CaptionText): string
toMarkdownV2
functionRENDER 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
functionCapability-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
typePresence of a `pre` block's language tag, as a DU (no `.optional()`).
type EntityLanguage = | { readonly kind: "known"; readonly value: string }
| { readonly kind: "unknown" }MessageEntity
typeThe Bot API `MessageEntity` union, as produced by {@link toEntities}.
type MessageEntity = SimpleEntity | PreEntity | TextLinkEntity | TextMentionEntity
SimpleEntityType
typeEntity types that carry no extra fields beyond `offset`/`length`.
type SimpleEntityType = | "bold" | "italic" | "underline" | "strikethrough" | "code" | "blockquote" | "expandable_blockquote" | "spoiler" | "mention"
LoweredBlock
typetype LoweredBlock = LoweredHeading | LoweredMath | LoweredTable | LoweredCollapsible
RenderRichMessageResult
typetype RenderRichMessageResult = | { readonly kind: "ok"; readonly value: RichMessagePayload }
| { readonly kind: "unsupported-node"; readonly nodeKind: string }Interfaces
EntitiesPayload
interfaceThe default render payload: the plain text plus its formatting entities.
interface EntitiesPayload
text
propertytext: string
entities
propertyentities: readonly MessageEntity[]
PreEntity
interfaceA `pre` (code block) entity, optionally carrying a language tag.
interface PreEntity
type
propertytype: "pre"
offset
propertyoffset: number
length
propertylength: number
language
propertylanguage: EntityLanguage
SimpleEntity
interfaceA formatting entity with no type-specific payload.
interface SimpleEntity
type
propertytype: SimpleEntityType
offset
propertyoffset: number
length
propertylength: number
TextLinkEntity
interfaceA `text_link` entity — inline text linking to `url`.
interface TextLinkEntity
type
propertytype: "text_link"
offset
propertyoffset: number
length
propertylength: number
url
propertyurl: string
TextMentionEntity
interfaceA `text_mention` entity — a mention of a user by numeric id.
interface TextMentionEntity
type
propertytype: "text_mention"
offset
propertyoffset: number
length
propertylength: number
user
propertyuser: { readonly id: number; }LoweredCollapsible
interfaceinterface LoweredCollapsible
kind
propertykind: "collapsible"
summary
propertysummary: EntitiesPayload
blocks
propertyblocks: readonly LoweredBlock[]
LoweredHeading
interfaceinterface LoweredHeading
kind
propertykind: "heading"
level
propertylevel: 1 | 2 | 3 | 4
content
propertycontent: EntitiesPayload
LoweredMath
interfaceinterface LoweredMath
kind
propertykind: "math"
latex
propertylatex: string
LoweredTable
interfaceinterface LoweredTable
kind
propertykind: "table"
header
propertyheader: readonly EntitiesPayload[]
rows
propertyrows: readonly (readonly EntitiesPayload[])[]
RichMessageCapability
interfaceThe capability token gating access to the 10.1 rich-message surface.
interface RichMessageCapability
kind
propertykind: "rich-message-10-1"
RichMessagePayload
interfaceThe successfully-lowered 10.1 rich message.
interface RichMessagePayload
blocks
propertyblocks: readonly LoweredBlock[]
Constants
EntitiesPayloadSchema
constconst EntitiesPayloadSchema: z.ZodType<EntitiesPayload, z.ZodTypeDef, EntitiesPayload>
MessageEntitySchema
constconst MessageEntitySchema: z.ZodType<MessageEntity, z.ZodTypeDef, MessageEntity>