diff --git a/js/__test__/blockTest.js b/js/__test__/blockTest.js
index fc11063..1b63b68 100644
--- a/js/__test__/blockTest.js
+++ b/js/__test__/blockTest.js
@@ -130,7 +130,7 @@ describe('addInlineStyleMarkup test suite', () => {
markup = addInlineStyleMarkup('ITALIC', 'test');
assert.equal(markup, 'test');
markup = addInlineStyleMarkup('UNDERLINE', 'test');
- assert.equal(markup, 'test');
+ assert.equal(markup, 'test');
markup = addInlineStyleMarkup('STRIKETHROUGH', 'test');
assert.equal(markup, 'test');
markup = addInlineStyleMarkup('CODE', 'test');
diff --git a/js/__test__/mainTest.js b/js/__test__/mainTest.js
index 6767685..7b57d6e 100644
--- a/js/__test__/mainTest.js
+++ b/js/__test__/mainTest.js
@@ -32,15 +32,15 @@ describe('draftToHtml test suite', () => {
assert.equal(output, result);
html = '
- 1
\n- 2
\n
\n- 3
\n
\n';
- output = '\n- 1
\n\n- 2
\n
\n- 3
\n
\n';
+ output = '\n- 1
\n- 2
\n
\n \n- 3
\n
\n';
arrContentBlocks = convertFromHTML(html);
contentState = ContentState.createFromBlockArray(arrContentBlocks);
result = draftToHtml(convertToRaw(contentState));
assert.equal(output, result);
html = '- 1
\n- 2
\n- 3
\n
\n- 4
\n
\n';
- output = '\n- 1
\n\n- 2
\n- '
- + '3
\n
\n- 4
\n
\n';
+ output = '\n- 1
\n- 2
\n- '
+ + '3
\n
\n \n- 4
\n
\n';
arrContentBlocks = convertFromHTML(html);
contentState = ContentState.createFromBlockArray(arrContentBlocks);
result = draftToHtml(convertToRaw(contentState));
@@ -48,8 +48,8 @@ describe('draftToHtml test suite', () => {
html = '- 1
\n- 2
\n- 3
\n
'
+ '\n
\n- 3
\n
\n';
- output = '\n- 1
\n\n- 2
\n\n- 3'
- + '
\n
\n
\n- 3
\n
\n';
+ output = '\n- 1
\n- 2
\n- 3'
+ + '
\n
\n \n
\n \n- 3
\n
\n';
arrContentBlocks = convertFromHTML(html);
contentState = ContentState.createFromBlockArray(arrContentBlocks);
result = draftToHtml(convertToRaw(contentState));
@@ -72,15 +72,15 @@ describe('draftToHtml test suite', () => {
assert.equal(output, result);
html = '- 1
\n- 2
\n
\n- 3
\n
\n';
- output = '\n- 1
\n\n- 2
\n
\n- 3
\n
\n';
+ output = '\n- 1
\n- 2
\n
\n \n- 3
\n
\n';
arrContentBlocks = convertFromHTML(html);
contentState = ContentState.createFromBlockArray(arrContentBlocks);
result = draftToHtml(convertToRaw(contentState));
assert.equal(output, result);
html = '- 1
\n- 2
\n- 3
\n
\n- 4
\n
\n';
- output = '\n- 1
\n\n- 2
\n- 3'
- + '
\n
\n- 4
\n
\n';
+ output = '\n- 1
\n- 2
\n- 3'
+ + '
\n
\n \n- 4
\n
\n';
arrContentBlocks = convertFromHTML(html);
contentState = ContentState.createFromBlockArray(arrContentBlocks);
result = draftToHtml(convertToRaw(contentState));
@@ -88,8 +88,8 @@ describe('draftToHtml test suite', () => {
html = '- 1
\n- 2
\n- 3
\n
'
+ '\n
\n- 3
\n
\n';
- output = '\n- 1
\n\n- 2
\n\n- 3'
- + '
\n
\n
\n- 3
\n
\n';
+ output = '\n- 1
\n- 2
\n- 3'
+ + '
\n
\n \n
\n \n- 3
\n
\n';
arrContentBlocks = convertFromHTML(html);
contentState = ContentState.createFromBlockArray(arrContentBlocks);
result = draftToHtml(convertToRaw(contentState));
diff --git a/js/block.js b/js/block.js
index 7e127e4..2b3f55a 100644
--- a/js/block.js
+++ b/js/block.js
@@ -247,7 +247,7 @@ export function addInlineStyleMarkup(style, content) {
} if (style === 'ITALIC') {
return `${content}`;
} if (style === 'UNDERLINE') {
- return `${content}`;
+ return `${content}`;
} if (style === 'STRIKETHROUGH') {
return `${content}`;
} if (style === 'CODE') {
diff --git a/js/list.js b/js/list.js
index df86c8c..1892353 100644
--- a/js/list.js
+++ b/js/list.js
@@ -1,22 +1,17 @@
-import {
- getBlockTag,
- getBlockStyle,
- getBlockInnerMarkup,
-} from './block';
+import { getBlockTag, getBlockStyle, getBlockInnerMarkup } from './block';
/**
-* Function to check if a block is of type list.
-*/
+ * Function to check if a block is of type list.
+ */
export function isList(blockType) {
return (
- blockType === 'unordered-list-item'
- || blockType === 'ordered-list-item'
+ blockType === 'unordered-list-item' || blockType === 'ordered-list-item'
);
}
/**
-* Function will return html markup for a list block.
-*/
+ * Function will return html markup for a list block.
+ */
export function getListMarkup(
listBlocks,
entityMap,
@@ -36,13 +31,17 @@ export function getListMarkup(
listHtml.push(`<${getBlockTag(block.type)}>\n`);
} else if (previousBlock.depth === block.depth) {
if (nestedListBlock && nestedListBlock.length > 0) {
- listHtml.push(getListMarkup(
- nestedListBlock,
- entityMap,
- hashtagConfig,
- directional,
- customEntityTransform,
- ));
+ listHtml.splice(
+ listHtml.length - 1,
+ 0,
+ getListMarkup(
+ nestedListBlock,
+ entityMap,
+ hashtagConfig,
+ directional,
+ customEntityTransform,
+ ),
+ );
nestedListBlock = [];
}
} else {
@@ -59,24 +58,30 @@ export function getListMarkup(
listHtml.push(' dir = "auto"');
}
listHtml.push('>');
- listHtml.push(getBlockInnerMarkup(
- block,
- entityMap,
- hashtagConfig,
- customEntityTransform,
- ));
+ listHtml.push(
+ getBlockInnerMarkup(
+ block,
+ entityMap,
+ hashtagConfig,
+ customEntityTransform,
+ ),
+ );
listHtml.push('\n');
previousBlock = block;
}
});
if (nestedListBlock && nestedListBlock.length > 0) {
- listHtml.push(getListMarkup(
- nestedListBlock,
- entityMap,
- hashtagConfig,
- directional,
- customEntityTransform,
- ));
+ listHtml.splice(
+ listHtml.length - 1,
+ 0,
+ getListMarkup(
+ nestedListBlock,
+ entityMap,
+ hashtagConfig,
+ directional,
+ customEntityTransform,
+ ),
+ );
}
listHtml.push(`${getBlockTag(previousBlock.type)}>\n`);
return listHtml.join('');
diff --git a/lib/draftjs-to-html.js b/lib/draftjs-to-html.js
index 55f02e7..2286ab7 100644
--- a/lib/draftjs-to-html.js
+++ b/lib/draftjs-to-html.js
@@ -4,6 +4,8 @@
(global = global || self, global.draftjsToHtml = factory());
}(this, (function () { 'use strict';
+ /* @flow */
+
/**
* Utility function to execute callback for eack key->value pair.
*/
@@ -308,7 +310,7 @@
}
if (style === 'UNDERLINE') {
- return "".concat(content, "");
+ return "".concat(content, "");
}
if (style === 'STRIKETHROUGH') {
@@ -617,15 +619,15 @@
}
/**
- * Function to check if a block is of type list.
- */
+ * Function to check if a block is of type list.
+ */
function isList(blockType) {
return blockType === 'unordered-list-item' || blockType === 'ordered-list-item';
}
/**
- * Function will return html markup for a list block.
- */
+ * Function will return html markup for a list block.
+ */
function getListMarkup(listBlocks, entityMap, hashtagConfig, directional, customEntityTransform) {
var listHtml = [];
@@ -641,7 +643,7 @@
listHtml.push("<".concat(getBlockTag(block.type), ">\n"));
} else if (previousBlock.depth === block.depth) {
if (nestedListBlock && nestedListBlock.length > 0) {
- listHtml.push(getListMarkup(nestedListBlock, entityMap, hashtagConfig, directional, customEntityTransform));
+ listHtml.splice(listHtml.length - 1, 0, getListMarkup(nestedListBlock, entityMap, hashtagConfig, directional, customEntityTransform));
nestedListBlock = [];
}
} else {
@@ -669,13 +671,14 @@
});
if (nestedListBlock && nestedListBlock.length > 0) {
- listHtml.push(getListMarkup(nestedListBlock, entityMap, hashtagConfig, directional, customEntityTransform));
+ listHtml.splice(listHtml.length - 1, 0, getListMarkup(nestedListBlock, entityMap, hashtagConfig, directional, customEntityTransform));
}
listHtml.push("".concat(getBlockTag(previousBlock.type), ">\n"));
return listHtml.join('');
}
+ /* @flow */
/**
* The function will generate html markup for given draftjs editorContent.
*/
diff --git a/readme.md b/readme.md
index 06e7136..0156953 100644
--- a/readme.md
+++ b/readme.md
@@ -70,7 +70,7 @@ Following is the list of conversions it supports:
2. Converts ordered and unordered list blocks with depths to nested structure of `, ` and `- `.
-3. Converts inline styles BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, CODE, SUPERSCRIPT, SUBSCRIPT to corresponding HTML tags: `, , ,
, , `.
+3. Converts inline styles BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, CODE, SUPERSCRIPT, SUBSCRIPT to corresponding HTML tags: `, , , , , `.
4. Converts inline styles color, background-color, font-size, font-family to a span tag with inline style details:
``. (The inline styles in JSON object should start with strings `color` or `font-size` like `color-red`, `color-green` or `fontsize-12`, `fontsize-20`).