diff --git a/packages/draft-js-export-html/src/__tests__/stateToHTML-test.js b/packages/draft-js-export-html/src/__tests__/stateToHTML-test.js
index 36fb0ac3..b971109b 100644
--- a/packages/draft-js-export-html/src/__tests__/stateToHTML-test.js
+++ b/packages/draft-js-export-html/src/__tests__/stateToHTML-test.js
@@ -206,6 +206,39 @@ describe('stateToHTML', () => {
);
});
+ it('blockStyleFn should support setting custom element', () => {
+ let options = {
+ blockStyleFn: () => ({
+ element: 'li',
+ }),
+ };
+
+ let contentState1 = convertFromRaw(
+ //
Hello world.
+ {
+ entityMap: {},
+ blocks: [
+ {
+ key: 'dn025',
+ text: 'Hello world.',
+ type: 'unstyled',
+ depth: 0,
+ inlineStyleRanges: [{offset: 6, length: 5, style: 'ITALIC'}],
+ entityRanges: [],
+ },
+ ],
+ }, // eslint-disable-line
+ );
+
+ expect(stateToHTML(contentState1)).toBe(
+ 'Hello world.
',
+ );
+
+ expect(stateToHTML(contentState1, options)).toBe(
+ 'Hello world.',
+ );
+ });
+
it('should support custom entity styles', () => {
let options = {
entityStyleFn: (entity) => {
diff --git a/packages/draft-js-export-html/src/stateToHTML.js b/packages/draft-js-export-html/src/stateToHTML.js
index d90b7fac..89991247 100644
--- a/packages/draft-js-export-html/src/stateToHTML.js
+++ b/packages/draft-js-export-html/src/stateToHTML.js
@@ -285,7 +285,7 @@ class MarkupGenerator {
let attrString;
if (this.options.blockStyleFn) {
- let {attributes, style} = this.options.blockStyleFn(block) || {};
+ let {attributes, style, element} = this.options.blockStyleFn(block) || {};
// Normalize `className` -> `class`, etc.
attributes = normalizeAttributes(attributes);
if (style != null) {
@@ -295,6 +295,9 @@ class MarkupGenerator {
? {style: styleAttr}
: {...attributes, style: styleAttr};
}
+ if (element != null) {
+ tags = [element];
+ }
attrString = stringifyAttrs(attributes);
} else {
attrString = '';
@@ -307,6 +310,14 @@ class MarkupGenerator {
writeEndTag(block, defaultBlockTag) {
let tags = getTags(block.getType(), defaultBlockTag);
+
+ if (this.options.blockStyleFn) {
+ let {element} = this.options.blockStyleFn(block) || {};
+ if (element != null) {
+ tags = [element];
+ }
+ }
+
if (tags.length === 1) {
this.output.push(`${tags[0]}>\n`);
} else {