Last active
March 28, 2018 21:49
-
-
Save cainlevy/66f76558455f818c2ac3fba878332e48 to your computer and use it in GitHub Desktop.
Mobiledoc 0.3.1 as TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Mobiledoc 0.3.1 | |
* https://github.com/bustlelabs/mobiledoc-kit/blob/master/MOBILEDOC.md#specification | |
*/ | |
interface Mobiledoc { | |
version: '0.3.1'; | |
markups: Markup[]; | |
atoms: Atom[]; | |
cards: Card[]; | |
sections: Section[]; | |
} | |
/** | |
* Markups | |
* https://github.com/bustle/mobiledoc-kit/blob/master/MOBILEDOC.md#signatures | |
* https://github.com/bustle/mobiledoc-kit/blob/master/MOBILEDOC.md#markup | |
*/ | |
type MarkupTagName = 'a' | 'b' | 'code' | 'em' | 'i' | 's' | 'strong' | 'sub' | 'sup' | 'u'; | |
type Markup = [MarkupTagName] | [MarkupTagName, string[]]; | |
/** | |
* Atoms | |
* https://github.com/bustle/mobiledoc-kit/blob/master/MOBILEDOC.md#signatures | |
*/ | |
type Atom<Payload extends JSONSerializable = JSONSerializable> = [ | |
string, // name | |
string, // text value | |
Payload | |
]; | |
/** | |
* Cards | |
* https://github.com/bustle/mobiledoc-kit/blob/master/MOBILEDOC.md#signatures | |
*/ | |
type Card<Payload extends JSONSerializable = JSONSerializable> = [ | |
string, // name | |
Payload | |
]; | |
/** | |
* Sections | |
* https://github.com/bustle/mobiledoc-kit/blob/master/MOBILEDOC.md#signatures | |
* https://github.com/bustle/mobiledoc-kit/blob/master/MOBILEDOC.md#sections | |
*/ | |
type MarkupSectionTagName = 'aside' | 'blockquote' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p'; | |
type MarkupSection = [ | |
1, | |
MarkupSectionTagName, | |
Marker[] | |
]; | |
type ImageSection = [ | |
2, | |
string // src | |
]; | |
type ListSectionTagName = 'ul' | 'ol'; | |
type ListSection = [ | |
3, | |
ListSectionTagName, | |
Marker[] | |
]; | |
type CardSection = [ | |
10, | |
number // cardIndex | |
]; | |
type Section = MarkupSection | ImageSection | ListSection | CardSection; | |
/** | |
* Markers | |
* https://github.com/bustle/mobiledoc-kit/blob/master/MOBILEDOC.md#signatures | |
* https://github.com/bustle/mobiledoc-kit/blob/master/MOBILEDOC.md#markers | |
*/ | |
type TextMarker = [ | |
0, | |
number[], // openMarkupsIndexes | |
number, // numberOfClosedMarkups | |
string // value | |
]; | |
type AtomMarker = [ | |
1, | |
number[], // openMarkupsIndexes | |
number, // numberOfClosedMarkups | |
number // atomIndex | |
]; | |
type Marker = TextMarker | AtomMarker; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment