Skip to content

Instantly share code, notes, and snippets.

@hediet
Created June 14, 2019 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hediet/1c9d0d44b0238a1b4fb47ab7fa5327f2 to your computer and use it in GitHub Desktop.
Save hediet/1c9d0d44b0238a1b4fb47ab7fa5327f2 to your computer and use it in GitHub Desktop.
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