aubade
Version:
markdown, orchestrated.
1,049 lines (1,033 loc) • 24.1 kB
TypeScript
declare module 'aubade' {
export function assemble(source: string): {
doc: ReturnType<typeof engrave>;
manifest: Record<string, any>;
meta: {
head: string;
body: string;
readonly table: Array<{
id: string;
title: string;
level: number;
}>;
readonly words: number;
};
};
type Director = (panel: {
data: Extract<Token, {
type: 'aubade:directive';
}>['meta']['data'];
annotate(source: string): string;
print(...lines: Array<string | false>): string;
sanitize: typeof escape_1;
}) => string;
type Resolver<T extends Token['type'] = Token['type']> = (panel: {
token: Extract<Token, {
type: T;
}>;
render(token: Token): string;
sanitize: typeof escape_1;
}) => string;
interface Options {
directive?: {
[key: string]: Director;
};
renderer?: {
[T in Token as T['type']]?: Resolver<T['type']>;
};
transform?: {
[T in Token as T['type']]?: (token: T) => T;
};
}
const engrave: (input: string) => {
tokens: Block[];
html(overrides?: Options["renderer"]): string;
visit(visitors: Options["transform"]): Block[];
};
type Registry = [
typeof directive_1,
typeof comment,
typeof markup,
typeof table,
typeof figure,
typeof divider,
typeof heading,
typeof codeblock,
typeof quote,
typeof list,
() => {
type: 'block:item';
meta: {
wrapped: boolean;
};
children: Token[];
},
() => {
type: 'block:paragraph';
children: Annotation[];
text?: string;
},
typeof escape,
typeof autolink,
typeof codespan,
typeof image,
typeof link,
() => {
type: 'inline:strong';
children: Annotation[];
},
() => {
type: 'inline:emphasis';
children: Annotation[];
},
() => {
type: 'inline:strike';
children: Annotation[];
},
() => {
type: 'inline:text';
text: string;
},
() => {
type: 'inline:break';
}
][number];
type Token = Registry extends (ctx: any) => infer R ? NonNullable<R> : never;
type Annotation = Exclude<Token, {
type: `block:${string}`;
}>;
type Block = Exclude<Token, {
type: `inline:${string}`;
}>;
function comment({ cursor }: Context): null | {
type: 'aubade:comment';
text: string;
};
function directive_1({ cursor }: Context): null | {
type: 'aubade:directive';
meta: {
type: string;
data: Record<string, string>;
};
};
function markup({ compose, cursor }: Context): null | {
type: 'aubade:html';
meta: {
tag: string;
};
attr: Record<string, string>;
children: Block[];
};
function table({ cursor, annotate }: Context): null | {
type: 'block:table';
meta: {
align: Array<'left' | 'center' | 'right'>;
head?: Annotation[][];
rows: Annotation[][][];
};
};
function codeblock({ cursor }: Context): null | {
type: 'block:code';
meta: {
code: string;
info: string;
};
attr: {
'data-language': string;
};
};
function divider({ cursor }: Context): null | {
type: 'block:break';
};
function figure(context: Context): null | {
type: 'block:image';
attr: {
src: string;
alt: string;
};
children: Annotation[];
};
function heading({ annotate, extract, cursor, stack, util }: Context): null | {
type: 'block:heading';
meta: {
level: number;
text: string;
};
attr: {
id: string;
};
children: Annotation[];
};
function list({ compose, cursor, stack, util }: Context): null | {
type: 'block:list';
meta: {
marker: string;
ordered: false | number;
};
children: Extract<Token, {
type: 'block:item';
}>[];
};
function quote({ compose, cursor }: Context): null | {
type: 'block:quote';
children: Block[];
};
function autolink({ cursor }: Context): null | {
type: 'inline:autolink';
attr: {
href: string;
};
text: string;
};
function codespan({ cursor }: Context): null | {
type: 'inline:code';
text: string;
};
function escape({ cursor }: Context): null | {
type: 'inline:escape';
text: string;
};
function image({ cursor }: Context): null | {
type: 'inline:image';
attr: {
src: string;
alt: string;
title: string;
};
};
function link({ annotate, extract, cursor }: Context): null | {
type: 'inline:link';
attr: {
href: string;
title: string;
};
children: Annotation[];
};
function escape_1(source: string): string;
function contextualize(source: string): {
/** current index in the source */
index: number;
/** consume the input if it matches */
eat(text: string): boolean;
/** read a fixed number of characters */
read(length: number): string;
/** eat until `pattern` is found */
locate(pattern: RegExp): string;
/** see the `pattern` ahead */
peek(pattern: string | RegExp): string;
/** see the `n`-th character before/after */
see(n: number): string;
trim(): void;
};
function extract_1(token: Token): string;
const util_1: {
commit<T>(array: T[], item: T): T;
last<T>(array: T[]): T;
is: {
alphanumeric(char: string): boolean;
punctuation(char: string): boolean;
whitespace(char: string): boolean;
'left-flanking'(before: string, after: string): boolean;
'right-flanking'(before: string, after: string): boolean;
};
};
interface Context {
annotate: typeof annotate_1;
compose: typeof compose_1;
extract: typeof extract_1;
cursor: ReturnType<typeof contextualize>;
stack: {
[T in Token as T['type']]: T[];
};
util: typeof util_1;
}
/** create the root document from the source */
function compose_1(source: string): {
type: ':document';
children: Block[];
};
/** construct inline tokens from the source */
function annotate_1(source: string): Annotation[];
export {};
}
declare module 'aubade/artisan' {
export type Director = (panel: {
data: Extract<Token, {
type: 'aubade:directive';
}>['meta']['data'];
annotate(source: string): string;
print(...lines: Array<string | false>): string;
sanitize: typeof escape_1;
}) => string;
export type Resolver<T extends Token['type'] = Token['type']> = (panel: {
token: Extract<Token, {
type: T;
}>;
render(token: Token): string;
sanitize: typeof escape_1;
}) => string;
export interface Options {
directive?: {
[key: string]: Director;
};
renderer?: {
[T in Token as T['type']]?: Resolver<T['type']>;
};
transform?: {
[T in Token as T['type']]?: (token: T) => T;
};
}
export const engrave: (input: string) => {
tokens: Block[];
html(overrides?: Options["renderer"]): string;
visit(visitors: Options["transform"]): Block[];
};
export function forge({ directive, renderer, transform }?: Options): (input: string) => {
tokens: Block[];
html(overrides?: Options["renderer"]): string;
visit(visitors: Options["transform"]): Block[];
};
export function typography(text: string): string;
type Registry = [
typeof directive_1,
typeof comment,
typeof markup,
typeof table,
typeof figure,
typeof divider,
typeof heading,
typeof codeblock,
typeof quote,
typeof list,
() => {
type: 'block:item';
meta: {
wrapped: boolean;
};
children: Token[];
},
() => {
type: 'block:paragraph';
children: Annotation[];
text?: string;
},
typeof escape,
typeof autolink,
typeof codespan,
typeof image,
typeof link,
() => {
type: 'inline:strong';
children: Annotation[];
},
() => {
type: 'inline:emphasis';
children: Annotation[];
},
() => {
type: 'inline:strike';
children: Annotation[];
},
() => {
type: 'inline:text';
text: string;
},
() => {
type: 'inline:break';
}
][number];
type Token = Registry extends (ctx: any) => infer R ? NonNullable<R> : never;
type Annotation = Exclude<Token, {
type: `block:${string}`;
}>;
type Block = Exclude<Token, {
type: `inline:${string}`;
}>;
function comment({ cursor }: Context): null | {
type: 'aubade:comment';
text: string;
};
function directive_1({ cursor }: Context): null | {
type: 'aubade:directive';
meta: {
type: string;
data: Record<string, string>;
};
};
function markup({ compose, cursor }: Context): null | {
type: 'aubade:html';
meta: {
tag: string;
};
attr: Record<string, string>;
children: Block[];
};
function table({ cursor, annotate }: Context): null | {
type: 'block:table';
meta: {
align: Array<'left' | 'center' | 'right'>;
head?: Annotation[][];
rows: Annotation[][][];
};
};
function codeblock({ cursor }: Context): null | {
type: 'block:code';
meta: {
code: string;
info: string;
};
attr: {
'data-language': string;
};
};
function divider({ cursor }: Context): null | {
type: 'block:break';
};
function figure(context: Context): null | {
type: 'block:image';
attr: {
src: string;
alt: string;
};
children: Annotation[];
};
function heading({ annotate, extract, cursor, stack, util }: Context): null | {
type: 'block:heading';
meta: {
level: number;
text: string;
};
attr: {
id: string;
};
children: Annotation[];
};
function list({ compose, cursor, stack, util }: Context): null | {
type: 'block:list';
meta: {
marker: string;
ordered: false | number;
};
children: Extract<Token, {
type: 'block:item';
}>[];
};
function quote({ compose, cursor }: Context): null | {
type: 'block:quote';
children: Block[];
};
function autolink({ cursor }: Context): null | {
type: 'inline:autolink';
attr: {
href: string;
};
text: string;
};
function codespan({ cursor }: Context): null | {
type: 'inline:code';
text: string;
};
function escape({ cursor }: Context): null | {
type: 'inline:escape';
text: string;
};
function image({ cursor }: Context): null | {
type: 'inline:image';
attr: {
src: string;
alt: string;
title: string;
};
};
function link({ annotate, extract, cursor }: Context): null | {
type: 'inline:link';
attr: {
href: string;
title: string;
};
children: Annotation[];
};
function escape_1(source: string): string;
function contextualize(source: string): {
/** current index in the source */
index: number;
/** consume the input if it matches */
eat(text: string): boolean;
/** read a fixed number of characters */
read(length: number): string;
/** eat until `pattern` is found */
locate(pattern: RegExp): string;
/** see the `pattern` ahead */
peek(pattern: string | RegExp): string;
/** see the `n`-th character before/after */
see(n: number): string;
trim(): void;
};
function extract_1(token: Token): string;
const util_1: {
commit<T>(array: T[], item: T): T;
last<T>(array: T[]): T;
is: {
alphanumeric(char: string): boolean;
punctuation(char: string): boolean;
whitespace(char: string): boolean;
'left-flanking'(before: string, after: string): boolean;
'right-flanking'(before: string, after: string): boolean;
};
};
interface Context {
annotate: typeof annotate_1;
compose: typeof compose_1;
extract: typeof extract_1;
cursor: ReturnType<typeof contextualize>;
stack: {
[T in Token as T['type']]: T[];
};
util: typeof util_1;
}
/** create the root document from the source */
function compose_1(source: string): {
type: ':document';
children: Block[];
};
/** construct inline tokens from the source */
function annotate_1(source: string): Annotation[];
export {};
}
declare module 'aubade/browser' {
export function hydrate(signal?: any): (node: HTMLElement) => () => void;
export {};
}
declare module 'aubade/conductor' {
import * as fs from 'fs/promises';
interface Chunk {
assemble: typeof assemble;
buffer: Buffer;
engrave: typeof engrave;
siblings: Array<{
filename: string;
buffer: Promise<Buffer>;
}>;
/** register an async task to be executed in parallel with the traversal. */
task(fn: (tools: {
fs: typeof fs;
}) => Promise<void>): void;
}
interface Options {
breadcrumb: string[];
depth: number;
parent: string;
path: string;
}
type Falsy = false | null | undefined;
interface Inspect<Output extends Record<string, any>> {
(options: Options): Falsy | ((chunk: Chunk) => Promise<Falsy | Output>);
}
export function orchestrate<Output extends Record<string, any>>(entry: string, inspect?: Inspect<Output>): Promise<Output[]>;
type Director = (panel: {
data: Extract<Token, {
type: 'aubade:directive';
}>['meta']['data'];
annotate(source: string): string;
print(...lines: Array<string | false>): string;
sanitize: typeof escape_1;
}) => string;
type Resolver<T extends Token['type'] = Token['type']> = (panel: {
token: Extract<Token, {
type: T;
}>;
render(token: Token): string;
sanitize: typeof escape_1;
}) => string;
interface Options_1 {
directive?: {
[key: string]: Director;
};
renderer?: {
[T in Token as T['type']]?: Resolver<T['type']>;
};
transform?: {
[T in Token as T['type']]?: (token: T) => T;
};
}
const engrave: (input: string) => {
tokens: Block[];
html(overrides?: Options_1["renderer"]): string;
visit(visitors: Options_1["transform"]): Block[];
};
function assemble(source: string): {
doc: ReturnType<typeof engrave>;
manifest: Record<string, any>;
meta: {
head: string;
body: string;
readonly table: Array<{
id: string;
title: string;
level: number;
}>;
readonly words: number;
};
};
type Registry = [
typeof directive_1,
typeof comment,
typeof markup,
typeof table,
typeof figure,
typeof divider,
typeof heading,
typeof codeblock,
typeof quote,
typeof list,
() => {
type: 'block:item';
meta: {
wrapped: boolean;
};
children: Token[];
},
() => {
type: 'block:paragraph';
children: Annotation[];
text?: string;
},
typeof escape,
typeof autolink,
typeof codespan,
typeof image,
typeof link,
() => {
type: 'inline:strong';
children: Annotation[];
},
() => {
type: 'inline:emphasis';
children: Annotation[];
},
() => {
type: 'inline:strike';
children: Annotation[];
},
() => {
type: 'inline:text';
text: string;
},
() => {
type: 'inline:break';
}
][number];
type Token = Registry extends (ctx: any) => infer R ? NonNullable<R> : never;
type Annotation = Exclude<Token, {
type: `block:${string}`;
}>;
type Block = Exclude<Token, {
type: `inline:${string}`;
}>;
function comment({ cursor }: Context): null | {
type: 'aubade:comment';
text: string;
};
function directive_1({ cursor }: Context): null | {
type: 'aubade:directive';
meta: {
type: string;
data: Record<string, string>;
};
};
function markup({ compose, cursor }: Context): null | {
type: 'aubade:html';
meta: {
tag: string;
};
attr: Record<string, string>;
children: Block[];
};
function table({ cursor, annotate }: Context): null | {
type: 'block:table';
meta: {
align: Array<'left' | 'center' | 'right'>;
head?: Annotation[][];
rows: Annotation[][][];
};
};
function codeblock({ cursor }: Context): null | {
type: 'block:code';
meta: {
code: string;
info: string;
};
attr: {
'data-language': string;
};
};
function divider({ cursor }: Context): null | {
type: 'block:break';
};
function figure(context: Context): null | {
type: 'block:image';
attr: {
src: string;
alt: string;
};
children: Annotation[];
};
function heading({ annotate, extract, cursor, stack, util }: Context): null | {
type: 'block:heading';
meta: {
level: number;
text: string;
};
attr: {
id: string;
};
children: Annotation[];
};
function list({ compose, cursor, stack, util }: Context): null | {
type: 'block:list';
meta: {
marker: string;
ordered: false | number;
};
children: Extract<Token, {
type: 'block:item';
}>[];
};
function quote({ compose, cursor }: Context): null | {
type: 'block:quote';
children: Block[];
};
function autolink({ cursor }: Context): null | {
type: 'inline:autolink';
attr: {
href: string;
};
text: string;
};
function codespan({ cursor }: Context): null | {
type: 'inline:code';
text: string;
};
function escape({ cursor }: Context): null | {
type: 'inline:escape';
text: string;
};
function image({ cursor }: Context): null | {
type: 'inline:image';
attr: {
src: string;
alt: string;
title: string;
};
};
function link({ annotate, extract, cursor }: Context): null | {
type: 'inline:link';
attr: {
href: string;
title: string;
};
children: Annotation[];
};
function escape_1(source: string): string;
function contextualize(source: string): {
/** current index in the source */
index: number;
/** consume the input if it matches */
eat(text: string): boolean;
/** read a fixed number of characters */
read(length: number): string;
/** eat until `pattern` is found */
locate(pattern: RegExp): string;
/** see the `pattern` ahead */
peek(pattern: string | RegExp): string;
/** see the `n`-th character before/after */
see(n: number): string;
trim(): void;
};
function extract_1(token: Token): string;
const util_1: {
commit<T>(array: T[], item: T): T;
last<T>(array: T[]): T;
is: {
alphanumeric(char: string): boolean;
punctuation(char: string): boolean;
whitespace(char: string): boolean;
'left-flanking'(before: string, after: string): boolean;
'right-flanking'(before: string, after: string): boolean;
};
};
interface Context {
annotate: typeof annotate_1;
compose: typeof compose_1;
extract: typeof extract_1;
cursor: ReturnType<typeof contextualize>;
stack: {
[T in Token as T['type']]: T[];
};
util: typeof util_1;
}
/** create the root document from the source */
function compose_1(source: string): {
type: ':document';
children: Block[];
};
/** construct inline tokens from the source */
function annotate_1(source: string): Annotation[];
export {};
}
declare module 'aubade/legacy' {
import type { default as markdown } from 'markdown-it';
export const marker: markdown;
export {};
}
declare module 'aubade/manifest' {
type Primitives = string | boolean | null;
export interface FrontMatter {
[key: string]: Primitives | Primitives[] | FrontMatter | FrontMatter[];
}
export function parse(raw: string, memo?: Record<string, any>): FrontMatter[string];
export function stringify(data: object, indent?: number): string;
export {};
}
declare module 'aubade/palette' {
interface Dataset {
file?: string | undefined;
language?: string | undefined;
[data: string]: string | undefined;
}
export const shiki: import("shiki").HighlighterGeneric<import("shiki").BundledLanguage, import("shiki").BundledTheme>;
export function highlight(source: string, dataset: Dataset): string;
export const codeblock: Resolver<'block:code'>;
type Resolver<T extends Token['type'] = Token['type']> = (panel: {
token: Extract<Token, {
type: T;
}>;
render(token: Token): string;
sanitize: typeof escape_1;
}) => string;
type Registry = [
typeof directive_1,
typeof comment,
typeof markup,
typeof table,
typeof figure,
typeof divider,
typeof heading,
typeof codeblock_1,
typeof quote,
typeof list,
() => {
type: 'block:item';
meta: {
wrapped: boolean;
};
children: Token[];
},
() => {
type: 'block:paragraph';
children: Annotation[];
text?: string;
},
typeof escape,
typeof autolink,
typeof codespan,
typeof image,
typeof link,
() => {
type: 'inline:strong';
children: Annotation[];
},
() => {
type: 'inline:emphasis';
children: Annotation[];
},
() => {
type: 'inline:strike';
children: Annotation[];
},
() => {
type: 'inline:text';
text: string;
},
() => {
type: 'inline:break';
}
][number];
type Token = Registry extends (ctx: any) => infer R ? NonNullable<R> : never;
type Annotation = Exclude<Token, {
type: `block:${string}`;
}>;
type Block = Exclude<Token, {
type: `inline:${string}`;
}>;
function comment({ cursor }: Context): null | {
type: 'aubade:comment';
text: string;
};
function directive_1({ cursor }: Context): null | {
type: 'aubade:directive';
meta: {
type: string;
data: Record<string, string>;
};
};
function markup({ compose, cursor }: Context): null | {
type: 'aubade:html';
meta: {
tag: string;
};
attr: Record<string, string>;
children: Block[];
};
function table({ cursor, annotate }: Context): null | {
type: 'block:table';
meta: {
align: Array<'left' | 'center' | 'right'>;
head?: Annotation[][];
rows: Annotation[][][];
};
};
function codeblock_1({ cursor }: Context): null | {
type: 'block:code';
meta: {
code: string;
info: string;
};
attr: {
'data-language': string;
};
};
function divider({ cursor }: Context): null | {
type: 'block:break';
};
function figure(context: Context): null | {
type: 'block:image';
attr: {
src: string;
alt: string;
};
children: Annotation[];
};
function heading({ annotate, extract, cursor, stack, util }: Context): null | {
type: 'block:heading';
meta: {
level: number;
text: string;
};
attr: {
id: string;
};
children: Annotation[];
};
function list({ compose, cursor, stack, util }: Context): null | {
type: 'block:list';
meta: {
marker: string;
ordered: false | number;
};
children: Extract<Token, {
type: 'block:item';
}>[];
};
function quote({ compose, cursor }: Context): null | {
type: 'block:quote';
children: Block[];
};
function autolink({ cursor }: Context): null | {
type: 'inline:autolink';
attr: {
href: string;
};
text: string;
};
function codespan({ cursor }: Context): null | {
type: 'inline:code';
text: string;
};
function escape({ cursor }: Context): null | {
type: 'inline:escape';
text: string;
};
function image({ cursor }: Context): null | {
type: 'inline:image';
attr: {
src: string;
alt: string;
title: string;
};
};
function link({ annotate, extract, cursor }: Context): null | {
type: 'inline:link';
attr: {
href: string;
title: string;
};
children: Annotation[];
};
function escape_1(source: string): string;
function contextualize(source: string): {
/** current index in the source */
index: number;
/** consume the input if it matches */
eat(text: string): boolean;
/** read a fixed number of characters */
read(length: number): string;
/** eat until `pattern` is found */
locate(pattern: RegExp): string;
/** see the `pattern` ahead */
peek(pattern: string | RegExp): string;
/** see the `n`-th character before/after */
see(n: number): string;
trim(): void;
};
function extract_1(token: Token): string;
const util_1: {
commit<T>(array: T[], item: T): T;
last<T>(array: T[]): T;
is: {
alphanumeric(char: string): boolean;
punctuation(char: string): boolean;
whitespace(char: string): boolean;
'left-flanking'(before: string, after: string): boolean;
'right-flanking'(before: string, after: string): boolean;
};
};
interface Context {
annotate: typeof annotate_1;
compose: typeof compose_1;
extract: typeof extract_1;
cursor: ReturnType<typeof contextualize>;
stack: {
[T in Token as T['type']]: T[];
};
util: typeof util_1;
}
/** create the root document from the source */
function compose_1(source: string): {
type: ':document';
children: Block[];
};
/** construct inline tokens from the source */
function annotate_1(source: string): Annotation[];
export {};
}
declare module 'aubade/transform' {
export function chain<Item extends Record<string, any>, Key extends string = 'flank', Group extends string = 'default', Output = {
slug?: string;
title?: any;
}, Processed = Item & {
[P in Key]: {
back?: Output;
next?: Output;
};
}, Finalized = Processed>(items: Item[], options: {
key?: Key;
group?(item: Item): Group;
sorter?(group: Group): (x: Item, y: Item) => number;
breakpoint?(next: Item): boolean;
transform?(item: Item): Output;
finalize?(groups: Record<string, Processed[]>): Finalized[];
}): Finalized[];
export {};
}
//# sourceMappingURL=index.d.ts.map