UNPKG

u-wave-parse-chat-markup

Version:

Abstract chat parser for üWave client applications.

73 lines (72 loc) 1.38 kB
/** * A node of italicised text. */ export type ItalicNode = { type: 'italic'; content: MarkupNode[]; }; /** * A node of bold text. */ export type BoldNode = { type: 'bold'; content: MarkupNode[]; }; /** * A code node, containing unstyled text. */ export type CodeNode = { type: 'code'; content: [string]; }; /** * A node of struck-through text. */ export type StrikeNode = { type: 'strike'; content: MarkupNode[]; }; /** * An emoji. */ export type EmojiNode = { type: 'emoji'; name: string; }; /** * A node that mentions a user. */ export type MentionNode = { type: 'mention'; mention: string; raw: string; }; /** * A node that contains a web link. */ export type LinkNode = { type: 'link'; text: string; href: string; }; /** * Markup node types: either raw text or one of the Node types. */ export type MarkupNode = string | ItalicNode | BoldNode | CodeNode | StrikeNode | EmojiNode | MentionNode | LinkNode; /** * Options for the parser. */ export type MarkupOptions = { /** * The names of the available :emoji: shortcodes. */ emojiNames?: string[]; /** * Usernames that can be mentioned. */ mentions?: string[]; }; /** * Parses a chat message into a tree-ish structure. */ export default function parse(message: string, options?: MarkupOptions): MarkupNode[];