Skip to content

Instantly share code, notes, and snippets.

@cainlevy
Last active March 28, 2018 21:49
Show Gist options
  • Save cainlevy/66f76558455f818c2ac3fba878332e48 to your computer and use it in GitHub Desktop.
Save cainlevy/66f76558455f818c2ac3fba878332e48 to your computer and use it in GitHub Desktop.
Mobiledoc 0.3.1 as TypeScript
/**
* 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