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

Add generator parameter to custom block renderer #174

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/draft-js-export-html/src/stateToHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type RenderConfig = {
style?: StyleDescr;
};

type BlockRenderer = (block: ContentBlock) => ?string;
type BlockRenderer = (block: ContentBlock, generator?: MarkupGenerator) => ?string;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you will also need to define a type for MarkupGenerator in this file (not to be confused with the typescript definitions which are totally different).

type BlockRendererMap = {[blockType: string]: BlockRenderer};

type StyleMap = {[styleName: string]: RenderConfig};
Expand Down Expand Up @@ -233,7 +233,7 @@ class MarkupGenerator {
blockRenderers != null && blockRenderers.hasOwnProperty(blockType)
? blockRenderers[blockType]
: null;
let customRendererOutput = customRenderer ? customRenderer(block) : null;
let customRendererOutput = customRenderer ? customRenderer(block, this) : null;
// Renderer can return null, which will cause processing to continue as normal.
if (customRendererOutput != null) {
this.output.push(customRendererOutput);
Expand Down
5 changes: 4 additions & 1 deletion packages/draft-js-export-html/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
declare module 'draft-js-export-html' {
import draftjs = require("draft-js");

type MarkupGenerator = {
renderBlockContent(block: draftjs.ContentBlock): string;
}
alexander-zolotykh marked this conversation as resolved.
Show resolved Hide resolved
type BlockStyleFn = (block: draftjs.ContentBlock) => RenderConfig|undefined;
type EntityStyleFn = (entity: draftjs.EntityInstance) => RenderConfig|undefined;
type BlockRenderer = (block: draftjs.ContentBlock) => string;
type BlockRenderer = (block: draftjs.ContentBlock, generator?: MarkupGenerator) => string;
type RenderConfig = {
element?: string;
attributes?: any;
Expand Down