Files
hopdown/dist/types.d.ts
T
evilchili 965fc09d99 v1 checkpoint
This commit is the initial checkpoint for a functioning converter with
all tests passing.
2026-10-16 13:00:11 -07:00

42 lines
1.3 KiB
TypeScript

export type TokenRole = 'open' | 'close' | 'block';
export interface Token {
role: TokenRole;
value: string;
sequence?: string;
tag?: TagType;
groups?: {
[key: string]: string;
};
/** For link tokens: the href and optional title. */
href?: string;
title?: string;
meta?: Record<string, string>;
}
/**
* A Tag is the core abstraction: it knows how to match markdown syntax,
* convert it to HTML, and convert the HTML back to markdown. Tags are
* registered by HTML selector (e.g. 'STRONG,B') so the converter can
* look them up during HTML→markdown conversion.
*/
export interface TagType {
element: string[];
opener: string[];
closer: string | null;
precedence: number;
isBlock: boolean;
template?: string;
pattern?: RegExp | null;
showDelimitersInEditorNodes?: boolean;
aliases?: string[];
tokenize(role: TokenRole, sequence: string, value: string): Token | null;
toHTML: (token: Token, callback: Function) => string;
toMarkdown: (element: HTMLElement, callback: Function) => string;
toEditorNode: (token: Token, callback: Function) => Node | null;
}
export interface TagCollectionType {
tags: Record<string, TagType>;
ordered: TagType[];
map: Map<string, TagType[]>;
getByElementName(element: string): TagType | undefined;
}