Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 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.

The second parameter should be optional.

Suggested change
type BlockRenderer = (block: ContentBlock, generator: MarkupGenerator) => ?string;
type BlockRenderer = (block: ContentBlock, generator?: MarkupGenerator) => ?string;

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

type StyleMap = {[styleName: string]: RenderConfig};
Expand Down Expand Up @@ -215,6 +215,7 @@ class MarkupGenerator {
}

processBlock() {
const generator = this;
let {blockRenderers, defaultBlockTag} = this.options;
let block = this.blocks[this.currentBlock];
let blockType = block.getType();
Expand All @@ -233,7 +234,7 @@ class MarkupGenerator {
blockRenderers != null && blockRenderers.hasOwnProperty(blockType)
? blockRenderers[blockType]
: null;
let customRendererOutput = customRenderer ? customRenderer(block) : null;
let customRendererOutput = customRenderer ? customRenderer(block, generator) : 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");

interface MarkupGenerator {
renderBlockContent(block: draftjs.ContentBlock): string;
}
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;
Copy link
Owner

Choose a reason for hiding this comment

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

Same here.

type RenderConfig = {
element?: string;
attributes?: any;
Expand Down