From 4deb9e5ce0051856600972e91fc0aa016f113262 Mon Sep 17 00:00:00 2001 From: Shivani Agrawal Date: Tue, 29 Sep 2020 01:19:10 +0530 Subject: [PATCH 1/2] Update stateToHTML.js blockrenderer: render list children correctly --- packages/draft-js-export-html/src/stateToHTML.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/draft-js-export-html/src/stateToHTML.js b/packages/draft-js-export-html/src/stateToHTML.js index d90b7fac..29a147f4 100644 --- a/packages/draft-js-export-html/src/stateToHTML.js +++ b/packages/draft-js-export-html/src/stateToHTML.js @@ -38,6 +38,7 @@ type StyleMap = {[styleName: string]: RenderConfig}; type BlockStyleFn = (block: ContentBlock) => ?RenderConfig; type EntityStyleFn = (entity: Entity) => ?RenderConfig; type InlineStyleFn = (style: DraftInlineStyle) => ?RenderConfig; +type RenderBlockContentFn = (block: ContentBlock) => string; type Options = { inlineStyles?: StyleMap; @@ -46,6 +47,7 @@ type Options = { blockStyleFn?: BlockStyleFn; entityStyleFn?: EntityStyleFn; defaultBlockTag?: ?string; + renderBlockContentFn?: RenderBlockContentFn; }; const {BOLD, CODE, ITALIC, STRIKETHROUGH, UNDERLINE} = INLINE_STYLE; @@ -215,7 +217,7 @@ class MarkupGenerator { } processBlock() { - let {blockRenderers, defaultBlockTag} = this.options; + let {blockRenderers, defaultBlockTag, renderBlockContentFn} = this.options; let block = this.blocks[this.currentBlock]; let blockType = block.getType(); let newWrapperTag = getWrapperTag(blockType); @@ -242,7 +244,13 @@ class MarkupGenerator { return; } this.writeStartTag(block, defaultBlockTag); - this.output.push(this.renderBlockContent(block)); + let customRenderBlockContentOutput = renderBlockContentFn ? renderBlockContentFn(block) : null; + if (customRenderBlockContentOutput != null) { + this.output.push(customRenderBlockContentOutput); + } + else { + this.output.push(this.renderBlockContent(block)); + } // Look ahead and see if we will nest list. let nextBlock = this.getNextBlock(); if ( From c0b1703fa3de1a83535c15da71aa6089d0e23774 Mon Sep 17 00:00:00 2001 From: Shivani Agrawal Date: Tue, 29 Sep 2020 01:35:03 +0530 Subject: [PATCH 2/2] Update stateToHTML.js --- packages/draft-js-export-html/src/stateToHTML.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/draft-js-export-html/src/stateToHTML.js b/packages/draft-js-export-html/src/stateToHTML.js index 29a147f4..e91b3292 100644 --- a/packages/draft-js-export-html/src/stateToHTML.js +++ b/packages/draft-js-export-html/src/stateToHTML.js @@ -247,8 +247,7 @@ class MarkupGenerator { let customRenderBlockContentOutput = renderBlockContentFn ? renderBlockContentFn(block) : null; if (customRenderBlockContentOutput != null) { this.output.push(customRenderBlockContentOutput); - } - else { + } else { this.output.push(this.renderBlockContent(block)); } // Look ahead and see if we will nest list.