Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Fix rendering API to handle annotation classes #61

Merged
merged 2 commits into from
Jul 23, 2018

Conversation

tim-evans
Copy link
Collaborator

@tim-evans tim-evans commented Jul 20, 2018

This PR changes the rendering API so annotation classes can be reused in the render hooks.

Previously, when an annotation was rendered, it would be called with the attributes, that stripped all type information:

import Renderer from '@atjson/renderer-hir';
import { HIRNode } from '@atjson/hir';

export default class TestRenderer extends Renderer {
  *image(attrs: any): IterableIterator<any> {
    return `![${attrs.description}](${attrs.src})`;
  }
}

Now, classes can be reused:

import { ObjectAnnotation } from '@atjson/document';
import Renderer from '@atjson/renderer-hir';

class Image extends ObjectAnnotation {
  static vendorPrefix = 'test';
  static type = 'image';
  attributes!: {
    description: string;
    src: string;
  };
}

export default class TestRenderer extends Renderer {
  *image(image: Image): IterableIterator<any> {
    return `![${image.attributes.description}](${image.attributes.src})`;
  }
}

In addition! There is now metadata associated on annotations passed to renderers for tricky rendering scenarios like markdown, which will hopefully remove the need for fully-custom renderers! ✨ (For context, this is currently being done here and used for ambiguous nesting of bold and italic and adjacent lists of the same type)

@tim-evans tim-evans requested review from blaine and bachbui July 20, 2018 19:01
@tim-evans tim-evans merged commit 2b5b08e into annotation-classes Jul 23, 2018
@tim-evans tim-evans deleted the hir-renderer branch July 23, 2018 17:02
tim-evans added a commit that referenced this pull request Aug 17, 2018
🚨 Render hooks now take annotations instead of props
tim-evans added a commit that referenced this pull request Sep 26, 2018
🚨 Render hooks now take annotations instead of props
tim-evans added a commit that referenced this pull request Oct 11, 2018
🚨 Render hooks now take annotations instead of props
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants