Skip to content

Instantly share code, notes, and snippets.

@hediet hediet/types.ts
Created Jun 14, 2019

Embed
What would you like to do?
import * as remarkAbstract from "remark";
interface Position {}
interface Node<T extends string = string> {
position: Position;
type: T;
}
interface NodeList<T extends string = string, TItem extends Node = Node>
extends Node<T> {
children: TItem[];
}
interface Root extends NodeList<"root", Item> {}
type Item =
| Paragraph
| Emphasis
| Paragraph
| Strong
| Text
| InlineCode
| ThematicBreak
| Code
| List
| Link;
interface Paragraph extends NodeList<"paragraph", Item> {}
interface Emphasis extends NodeList<"emphasis", Item> {}
interface Paragraph extends NodeList<"paragraph", Item> {}
interface Strong extends NodeList<"strong", Item> {}
interface List extends NodeList<"list", ListItem> {
lang: string;
value: string;
ordered: boolean;
spreak: boolean;
}
interface ListItem extends NodeList<"listItem", Item> {
spread: boolean;
checked: null;
}
interface Text extends Node<"text"> {
value: string;
}
interface InlineCode extends Node<"inlineCode"> {}
interface ThematicBreak extends Node<"thematicBreak"> {}
interface Code extends Node<"code"> {
lang: string;
value: string;
}
interface Link extends NodeList<"link", Item> {
title: null | string;
url: string;
}
interface Image extends Node<"image"> {
title: null | string;
url: string;
alt: string;
}
export function toReact(markdown: string) {
const remark = remarkAbstract();
const ast: Root = remark.parse(markdown);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.