Skip to content

Commit

Permalink
🐛 Add HTML annotations (#66)
Browse files Browse the repository at this point in the history
This defines a subset of the HTML spec as annotations. In the future, we'd like these to be automatically generated from the HTML spec.
  • Loading branch information
tim-evans committed Sep 26, 2018
1 parent e9572bc commit 193a9c1
Show file tree
Hide file tree
Showing 33 changed files with 411 additions and 222 deletions.
137 changes: 77 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/@atjson/document/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ export default class Document {

private createAnnotation(json: AnnotationJSON): Annotation {
let DocumentClass = this.constructor as typeof Document;
let schema = DocumentClass.schema.slice().concat([Parse]);
let schema = [...DocumentClass.schema, Parse];

let ConcreteAnnotation = schema.find(AnnotationClass => {
let fullyQualifiedType = `-${AnnotationClass.vendorPrefix}-${AnnotationClass.type}`;
return json.type === fullyQualifiedType;
Expand Down
11 changes: 11 additions & 0 deletions packages/@atjson/source-html/src/annotations/anchor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { InlineAnnotation } from '@atjson/document';

export default class Anchor extends InlineAnnotation {
static vendorPrefix = 'html';
static type = 'a';
attributes!: {
href: string;
target: string;
rel: string;
};
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/blockquote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BlockAnnotation } from '@atjson/document';

export default class Blockquote extends BlockAnnotation {
static vendorPrefix = 'html';
static type = 'blockquote';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/bold.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { InlineAnnotation } from '@atjson/document';

export default class Bold extends InlineAnnotation {
static vendorPrefix = 'html';
static type = 'b';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/break.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ObjectAnnotation } from '@atjson/document';

export default class Break extends ObjectAnnotation {
static vendorPrefix = 'html';
static type = 'br';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { InlineAnnotation } from '@atjson/document';

export default class Code extends InlineAnnotation {
static vendorPrefix = 'html';
static type = 'code';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/deleted-text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { InlineAnnotation } from '@atjson/document';

export default class DeletedText extends InlineAnnotation {
static vendorPrefix = 'html';
static type = 'del';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/emphasis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { InlineAnnotation } from '@atjson/document';

export default class Emphasis extends InlineAnnotation {
static vendorPrefix = 'html';
static type = 'em';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/heading-1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BlockAnnotation } from '@atjson/document';

export default class Heading1 extends BlockAnnotation {
static vendorPrefix = 'html';
static type = 'h1';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/heading-2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BlockAnnotation } from '@atjson/document';

export default class Heading2 extends BlockAnnotation {
static vendorPrefix = 'html';
static type = 'h2';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/heading-3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BlockAnnotation } from '@atjson/document';

export default class Heading3 extends BlockAnnotation {
static vendorPrefix = 'html';
static type = 'h3';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/heading-4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BlockAnnotation } from '@atjson/document';

export default class Heading4 extends BlockAnnotation {
static vendorPrefix = 'html';
static type = 'h4';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/heading-5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BlockAnnotation } from '@atjson/document';

export default class Heading5 extends BlockAnnotation {
static vendorPrefix = 'html';
static type = 'h5';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/heading-6.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BlockAnnotation } from '@atjson/document';

export default class Heading6 extends BlockAnnotation {
static vendorPrefix = 'html';
static type = 'h6';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ObjectAnnotation } from '@atjson/document';

export default class HorizontalRule extends ObjectAnnotation {
static vendorPrefix = 'html';
static type = 'hr';
}
11 changes: 11 additions & 0 deletions packages/@atjson/source-html/src/annotations/image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ObjectAnnotation } from '@atjson/document';

export default class Image extends ObjectAnnotation {
static vendorPrefix = 'html';
static type = 'img';
attributes!: {
alt?: string;
src: string;
title?: string;
};
}
26 changes: 26 additions & 0 deletions packages/@atjson/source-html/src/annotations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export { default as Anchor } from './anchor';
export { default as Bold } from './bold';
export { default as Blockquote } from './blockquote';
export { default as Break } from './break';
export { default as Code } from './code';
export { default as DeletedText } from './deleted-text';
export { default as Emphasis } from './emphasis';
export { default as Heading1 } from './heading-1';
export { default as Heading2 } from './heading-2';
export { default as Heading3 } from './heading-3';
export { default as Heading4 } from './heading-4';
export { default as Heading5 } from './heading-5';
export { default as Heading6 } from './heading-6';
export { default as HorizontalRule } from './horizontal-rule';
export { default as Image } from './image';
export { default as Italic } from './italic';
export { default as ListItem } from './list-item';
export { default as OrderedList } from './ordered-list';
export { default as Paragraph } from './paragraph';
export { default as PreformattedText } from './preformatted-text';
export { default as Strikethrough } from './strikethrough';
export { default as Strong } from './strong';
export { default as Subscript } from './subscript';
export { default as Superscript } from './superscript';
export { default as UnorderedList } from './unordered-list';
export { default as Underline } from './underline';
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/italic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { InlineAnnotation } from '@atjson/document';

export default class Italic extends InlineAnnotation {
static vendorPrefix = 'html';
static type = 'i';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/list-item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BlockAnnotation } from '@atjson/document';

export default class ListItem extends BlockAnnotation {
static vendorPrefix = 'html';
static type = 'li';
}
9 changes: 9 additions & 0 deletions packages/@atjson/source-html/src/annotations/ordered-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BlockAnnotation } from '@atjson/document';

export default class OrderedList extends BlockAnnotation {
static vendorPrefix = 'html';
static type = 'ol';
attributes!: {
starts: string;
};
}
10 changes: 10 additions & 0 deletions packages/@atjson/source-html/src/annotations/paragraph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { BlockAnnotation } from '@atjson/document';

export default class Paragraph extends BlockAnnotation {
static vendorPrefix = 'html';
static type = 'p';

get rank() {
return super.rank * 3 / 2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { InlineAnnotation } from '@atjson/document';

export default class PreformattedText extends InlineAnnotation {
static vendorPrefix = 'html';
static type = 'pre';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/strikethrough.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { InlineAnnotation } from '@atjson/document';

export default class Strikethrough extends InlineAnnotation {
static vendorPrefix = 'html';
static type = 's';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/strong.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { InlineAnnotation } from '@atjson/document';

export default class Strong extends InlineAnnotation {
static vendorPrefix = 'html';
static type = 'strong';
}
6 changes: 6 additions & 0 deletions packages/@atjson/source-html/src/annotations/subscript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { InlineAnnotation } from '@atjson/document';

export default class Subscript extends InlineAnnotation {
static vendorPrefix = 'html';
static type = 'sub';
}
Loading

0 comments on commit 193a9c1

Please sign in to comment.