aubade
Version:
filesystem-based content processor
946 lines (932 loc) • 21.4 kB
TypeScript
declare module 'aubade' {
export function parse(source: string): {
body: string;
frontmatter?: {
[key: string]: any;
estimate: number;
table: Array<{
id: string;
title: string;
level: number;
}>;
};
};
export function assemble(source: string): {
manifest?: Record<string, any>;
md: ReturnType<typeof engrave>;
meta: {
body: string;
words: number;
};
};
const engrave: (input: string) => {
tokens: NonNullable<{
type: "inline:autolink";
text: string;
attr: {
href: string;
};
} | {
type: "inline:code";
text: string;
} | {
type: "inline:comment";
text: string;
} | {
type: "inline:text";
text: string;
} | {
type: "parent:html";
text: string;
attr: Record<string, string>;
children: Token[];
} | {
type: "block:break";
} | {
type: "parent:heading";
text: string;
attr: {
id: string;
};
meta: {
level: number;
};
children: Token[];
} | {
type: "parent:quote";
children: Token[];
} | {
type: "block:list";
children: [];
} | {
type: "block:code";
attr: {
"data-language": string;
};
children: NonNullable<ReturnType<code_1>>[];
} | {
type: "parent:paragraph";
text: string;
children: Token[];
} | {
type: "inline:image";
attr: {
src: string;
alt: string;
title: string;
};
} | {
type: "inline:link";
attr: {
href: string;
title: string;
};
children: Token[];
} | {
type: "modifier:strong";
children: Token[];
} | {
type: "modifier:emphasis";
children: Token[];
} | {
type: "modifier:strike";
children: Token[];
} | null>[];
html: () => string;
};
type Registry = [
typeofhtml,
typeoflinebreak,
typeofheading,
typeofquote,
typeoflist,
typeofcode,
typeofparagraph,
typeofcomment,
typeofescape,
typeofautolink,
typeofcode_1,
typeofimage,
typeoflink,
typeofstrong,
typeofemphasis,
typeofstrike,
typeoftext
][number];
type Token = Registry extends (...args: any[]) => infer R ? NonNullable<R> : never;
interface Context {
cursor: {
/** current index in the source */
index: number;
/** greedily consume until the last matching character */
consume(delimiter: string, update: (i: number) => boolean): string;
/** 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;
};
is: {
'left-flanking'(before: string, after: string): boolean;
'right-flanking'(before: string, after: string): boolean;
alphanumeric(char: string): boolean;
punctuation(char: string): boolean;
whitespace(char: string): boolean;
};
stack: {
push<T extends Token>(token: T): T;
pop(): Token | undefined;
find<T extends Token['type']>(type: T, predicate?: (token: Extract<Token, {
type: T;
}>) => boolean): Extract<Token, {
type: T;
}> | undefined;
remove(token: Token): Token | undefined;
peek(): Token | undefined;
};
compose: typeof compose_1;
annotate: typeof annotate_1;
}
/** create the root document from the source */
function compose_1(source: string): {
type: ':document';
children: Token[];
};
/** construct inline tokens from the source */
function annotate_1(source: string): Token[];
function autolink({ cursor }: Context): null | {
type: 'inline:autolink';
text: string;
attr: {
href: string;
};
};
function code_1({ cursor }: Context): null | {
type: 'inline:code';
text: string;
};
function comment({ cursor }: Context): null | {
type: 'inline:comment';
text: string;
};
function escape({ cursor, stack }: Context): null | {
type: 'inline:text';
text: string;
};
function image({ cursor }: Context): null | {
type: 'inline:image';
attr: {
src: string;
alt: string;
title: string;
};
};
function link({ cursor, annotate }: Context): null | {
type: 'inline:link';
attr: {
href: string;
title: string;
};
children: Token[];
};
function text({ cursor, stack }: Context): null | {
type: 'inline:text';
text: string;
};
function code({ cursor }: Context): null | {
type: 'block:code';
attr: {
'data-language': string;
};
children: NonNullable<ReturnType<typeof code_1>>[];
};
function linebreak({ cursor }: Context): null | {
type: 'block:break';
};
function list({ cursor, compose }: Context): null | {
type: 'block:list';
children: [];
};
function emphasis({ cursor, is, annotate }: Context): null | {
type: 'modifier:emphasis';
children: Token[];
};
function strike({ cursor, is, annotate }: Context): null | {
type: 'modifier:strike';
children: Token[];
};
function strong({ cursor, is, annotate }: Context): null | {
type: 'modifier:strong';
children: Token[];
};
function heading({ cursor, stack }: Context): null | {
type: 'parent:heading';
text: string;
attr: {
id: string;
};
meta: {
level: number;
};
children: Token[];
};
function html({ cursor, compose }: Context): null | {
type: 'parent:html';
text: string;
attr: Record<string, string>;
children: Token[];
};
function paragraph({ cursor, stack }: Context): null | {
type: 'parent:paragraph';
text: string;
children: Token[];
};
function quote({ cursor, stack, compose }: Context): null | {
type: 'parent:quote';
children: Token[];
};
export {};
}
declare module 'aubade/artisan' {
import type { default as markdown_1 } from 'markdown-it';
interface Resolver<T extends Token = Token> {
(panel: {
token: T;
render(token: Token): string;
sanitize(text: string): string;
}): string;
}
interface Options {
renderer?: {
[T in Token as T['type']]?: Resolver<T>;
};
}
export function markdown({ renderer }?: Options): (input: string) => {
tokens: NonNullable<{
type: "inline:autolink";
text: string;
attr: {
href: string;
};
} | {
type: "inline:code";
text: string;
} | {
type: "inline:comment";
text: string;
} | {
type: "inline:text";
text: string;
} | {
type: "parent:html";
text: string;
attr: Record<string, string>;
children: Token[];
} | {
type: "block:break";
} | {
type: "parent:heading";
text: string;
attr: {
id: string;
};
meta: {
level: number;
};
children: Token[];
} | {
type: "parent:quote";
children: Token[];
} | {
type: "block:list";
children: [];
} | {
type: "block:code";
attr: {
"data-language": string;
};
children: NonNullable<ReturnType<code_1>>[];
} | {
type: "parent:paragraph";
text: string;
children: Token[];
} | {
type: "inline:image";
attr: {
src: string;
alt: string;
title: string;
};
} | {
type: "inline:link";
attr: {
href: string;
title: string;
};
children: Token[];
} | {
type: "modifier:strong";
children: Token[];
} | {
type: "modifier:emphasis";
children: Token[];
} | {
type: "modifier:strike";
children: Token[];
} | null>[];
html: () => string;
};
export const engrave: (input: string) => {
tokens: NonNullable<{
type: "inline:autolink";
text: string;
attr: {
href: string;
};
} | {
type: "inline:code";
text: string;
} | {
type: "inline:comment";
text: string;
} | {
type: "inline:text";
text: string;
} | {
type: "parent:html";
text: string;
attr: Record<string, string>;
children: Token[];
} | {
type: "block:break";
} | {
type: "parent:heading";
text: string;
attr: {
id: string;
};
meta: {
level: number;
};
children: Token[];
} | {
type: "parent:quote";
children: Token[];
} | {
type: "block:list";
children: [];
} | {
type: "block:code";
attr: {
"data-language": string;
};
children: NonNullable<ReturnType<code_1>>[];
} | {
type: "parent:paragraph";
text: string;
children: Token[];
} | {
type: "inline:image";
attr: {
src: string;
alt: string;
title: string;
};
} | {
type: "inline:link";
attr: {
href: string;
title: string;
};
children: Token[];
} | {
type: "modifier:strong";
children: Token[];
} | {
type: "modifier:emphasis";
children: Token[];
} | {
type: "modifier:strike";
children: Token[];
} | null>[];
html: () => string;
};
export const marker: markdown_1;
interface Dataset {
file?: string;
language?: string;
[data: string]: string | undefined;
}
export const highlighter: import("shiki").HighlighterGeneric<import("shiki").BundledLanguage, import("shiki").BundledTheme>;
export function transform(source: string, dataset: Dataset): string;
type Primitives = string | boolean | null;
export interface FrontMatter {
[key: string]: Primitives | Primitives[] | FrontMatter | FrontMatter[];
}
export function matter(raw: string, memo?: Record<string, any>): FrontMatter[string];
type Registry = [
typeofhtml,
typeoflinebreak,
typeofheading,
typeofquote,
typeoflist,
typeofcode,
typeofparagraph,
typeofcomment,
typeofescape,
typeofautolink,
typeofcode_1,
typeofimage,
typeoflink,
typeofstrong,
typeofemphasis,
typeofstrike,
typeoftext
][number];
type Token = Registry extends (...args: any[]) => infer R ? NonNullable<R> : never;
interface Context {
cursor: {
/** current index in the source */
index: number;
/** greedily consume until the last matching character */
consume(delimiter: string, update: (i: number) => boolean): string;
/** 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;
};
is: {
'left-flanking'(before: string, after: string): boolean;
'right-flanking'(before: string, after: string): boolean;
alphanumeric(char: string): boolean;
punctuation(char: string): boolean;
whitespace(char: string): boolean;
};
stack: {
push<T extends Token>(token: T): T;
pop(): Token | undefined;
find<T extends Token['type']>(type: T, predicate?: (token: Extract<Token, {
type: T;
}>) => boolean): Extract<Token, {
type: T;
}> | undefined;
remove(token: Token): Token | undefined;
peek(): Token | undefined;
};
compose: typeof compose_1;
annotate: typeof annotate_1;
}
/** create the root document from the source */
function compose_1(source: string): {
type: ':document';
children: Token[];
};
/** construct inline tokens from the source */
function annotate_1(source: string): Token[];
function autolink({ cursor }: Context): null | {
type: 'inline:autolink';
text: string;
attr: {
href: string;
};
};
function code_1({ cursor }: Context): null | {
type: 'inline:code';
text: string;
};
function comment({ cursor }: Context): null | {
type: 'inline:comment';
text: string;
};
function escape({ cursor, stack }: Context): null | {
type: 'inline:text';
text: string;
};
function image({ cursor }: Context): null | {
type: 'inline:image';
attr: {
src: string;
alt: string;
title: string;
};
};
function link({ cursor, annotate }: Context): null | {
type: 'inline:link';
attr: {
href: string;
title: string;
};
children: Token[];
};
function text({ cursor, stack }: Context): null | {
type: 'inline:text';
text: string;
};
function code({ cursor }: Context): null | {
type: 'block:code';
attr: {
'data-language': string;
};
children: NonNullable<ReturnType<typeof code_1>>[];
};
function linebreak({ cursor }: Context): null | {
type: 'block:break';
};
function list({ cursor, compose }: Context): null | {
type: 'block:list';
children: [];
};
function emphasis({ cursor, is, annotate }: Context): null | {
type: 'modifier:emphasis';
children: Token[];
};
function strike({ cursor, is, annotate }: Context): null | {
type: 'modifier:strike';
children: Token[];
};
function strong({ cursor, is, annotate }: Context): null | {
type: 'modifier:strong';
children: Token[];
};
function heading({ cursor, stack }: Context): null | {
type: 'parent:heading';
text: string;
attr: {
id: string;
};
meta: {
level: number;
};
children: Token[];
};
function html({ cursor, compose }: Context): null | {
type: 'parent:html';
text: string;
attr: Record<string, string>;
children: Token[];
};
function paragraph({ cursor, stack }: Context): null | {
type: 'parent:paragraph';
text: string;
children: Token[];
};
function quote({ cursor, stack, compose }: Context): null | {
type: 'parent:quote';
children: Token[];
};
export {};
}
declare module 'aubade/browser' {
export function hydrate(signal?: any): (node: HTMLElement) => () => void;
export {};
}
declare module 'aubade/compass' {
import type { default as markdown } from 'markdown-it';
import * as fs from 'fs/promises';
interface Chunk {
buffer: Buffer;
marker: typeof marker;
parse: typeof parse;
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 traverse<Output extends Record<string, any>>(entry: string, inspect?: Inspect<Output>): Promise<Output[]>;
function parse(source: string): {
body: string;
frontmatter?: {
[key: string]: any;
estimate: number;
table: Array<{
id: string;
title: string;
level: number;
}>;
};
};
const marker: markdown;
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[]>;
function assemble(source: string): {
manifest?: Record<string, any>;
md: ReturnType<typeof engrave>;
meta: {
body: string;
words: number;
};
};
const engrave: (input: string) => {
tokens: NonNullable<{
type: "inline:autolink";
text: string;
attr: {
href: string;
};
} | {
type: "inline:code";
text: string;
} | {
type: "inline:comment";
text: string;
} | {
type: "inline:text";
text: string;
} | {
type: "parent:html";
text: string;
attr: Record<string, string>;
children: Token[];
} | {
type: "block:break";
} | {
type: "parent:heading";
text: string;
attr: {
id: string;
};
meta: {
level: number;
};
children: Token[];
} | {
type: "parent:quote";
children: Token[];
} | {
type: "block:list";
children: [];
} | {
type: "block:code";
attr: {
"data-language": string;
};
children: NonNullable<ReturnType<code_1>>[];
} | {
type: "parent:paragraph";
text: string;
children: Token[];
} | {
type: "inline:image";
attr: {
src: string;
alt: string;
title: string;
};
} | {
type: "inline:link";
attr: {
href: string;
title: string;
};
children: Token[];
} | {
type: "modifier:strong";
children: Token[];
} | {
type: "modifier:emphasis";
children: Token[];
} | {
type: "modifier:strike";
children: Token[];
} | null>[];
html: () => string;
};
type Registry = [
typeofhtml,
typeoflinebreak,
typeofheading,
typeofquote,
typeoflist,
typeofcode,
typeofparagraph,
typeofcomment,
typeofescape,
typeofautolink,
typeofcode_1,
typeofimage,
typeoflink,
typeofstrong,
typeofemphasis,
typeofstrike,
typeoftext
][number];
type Token = Registry extends (...args: any[]) => infer R ? NonNullable<R> : never;
interface Context {
cursor: {
/** current index in the source */
index: number;
/** greedily consume until the last matching character */
consume(delimiter: string, update: (i: number) => boolean): string;
/** 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;
};
is: {
'left-flanking'(before: string, after: string): boolean;
'right-flanking'(before: string, after: string): boolean;
alphanumeric(char: string): boolean;
punctuation(char: string): boolean;
whitespace(char: string): boolean;
};
stack: {
push<T extends Token>(token: T): T;
pop(): Token | undefined;
find<T extends Token['type']>(type: T, predicate?: (token: Extract<Token, {
type: T;
}>) => boolean): Extract<Token, {
type: T;
}> | undefined;
remove(token: Token): Token | undefined;
peek(): Token | undefined;
};
compose: typeof compose_1;
annotate: typeof annotate_1;
}
/** create the root document from the source */
function compose_1(source: string): {
type: ':document';
children: Token[];
};
/** construct inline tokens from the source */
function annotate_1(source: string): Token[];
function autolink({ cursor }: Context): null | {
type: 'inline:autolink';
text: string;
attr: {
href: string;
};
};
function code_1({ cursor }: Context): null | {
type: 'inline:code';
text: string;
};
function comment({ cursor }: Context): null | {
type: 'inline:comment';
text: string;
};
function escape({ cursor, stack }: Context): null | {
type: 'inline:text';
text: string;
};
function image({ cursor }: Context): null | {
type: 'inline:image';
attr: {
src: string;
alt: string;
title: string;
};
};
function link({ cursor, annotate }: Context): null | {
type: 'inline:link';
attr: {
href: string;
title: string;
};
children: Token[];
};
function text({ cursor, stack }: Context): null | {
type: 'inline:text';
text: string;
};
function code({ cursor }: Context): null | {
type: 'block:code';
attr: {
'data-language': string;
};
children: NonNullable<ReturnType<typeof code_1>>[];
};
function linebreak({ cursor }: Context): null | {
type: 'block:break';
};
function list({ cursor, compose }: Context): null | {
type: 'block:list';
children: [];
};
function emphasis({ cursor, is, annotate }: Context): null | {
type: 'modifier:emphasis';
children: Token[];
};
function strike({ cursor, is, annotate }: Context): null | {
type: 'modifier:strike';
children: Token[];
};
function strong({ cursor, is, annotate }: Context): null | {
type: 'modifier:strong';
children: Token[];
};
function heading({ cursor, stack }: Context): null | {
type: 'parent:heading';
text: string;
attr: {
id: string;
};
meta: {
level: number;
};
children: Token[];
};
function html({ cursor, compose }: Context): null | {
type: 'parent:html';
text: string;
attr: Record<string, string>;
children: Token[];
};
function paragraph({ cursor, stack }: Context): null | {
type: 'parent:paragraph';
text: string;
children: Token[];
};
function quote({ cursor, stack, compose }: Context): null | {
type: 'parent:quote';
children: Token[];
};
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/transform' {
export function chain<Item extends Record<string, any>, Key extends string = 'flank', Output = {
slug?: string;
title?: any;
}>(items: Item[], options: {
breakpoint?(next: Item): boolean;
key?: Key;
sort?(x: Item, y: Item): number;
transform?(item: Item): Output;
}): Array<Item & {
[P in Key]: {
back?: Output;
next?: Output;
};
}>;
export {};
}
//# sourceMappingURL=index.d.ts.map