diff --git a/src/components/RichTextArea/RichTextArea.jsx b/src/components/RichTextArea/RichTextArea.jsx index 975daba61..18f1026c3 100644 --- a/src/components/RichTextArea/RichTextArea.jsx +++ b/src/components/RichTextArea/RichTextArea.jsx @@ -396,8 +396,10 @@ class RichTextArea extends React.Component { const {className, avatarUrl, authorName, titlePlaceholder, contentPlaceholder, editMode, isCreating, isGettingComment, disableTitle, disableContent, expandedTitlePlaceholder, editingTopic, hasPrivateSwitch, canUploadAttachment, attachments, textAreaOnly } = this.props const {editorExpanded, editorState, titleValue, oldMDContent, currentMDContent, uploading, isPrivate, isAddLinkOpen, rawFiles, files} = this.state + const emptyStringRegex = /^[\s\n\u200B]*$/g // empty string with space, new line, zero width space character + let canSubmit = (disableTitle || titleValue.trim()) - && (disableContent || editorState.getCurrentContent().hasText()) + && (disableContent || !emptyStringRegex.test(currentMDContent)) if (editMode && canSubmit) { canSubmit = (!disableTitle && titleValue !== this.props.oldTitle) || (!disableContent && oldMDContent !== currentMDContent) || (rawFiles.length > 0 || (attachments && files.length < attachments.length)) diff --git a/src/helpers/markdownToState.js b/src/helpers/markdownToState.js index 376c4b1ad..5295fad58 100644 --- a/src/helpers/markdownToState.js +++ b/src/helpers/markdownToState.js @@ -1,5 +1,6 @@ import {convertFromRaw} from 'draft-js' import sanitizeHtml from 'sanitize-html' +import Alert from 'react-s-alert' const Remarkable = require('remarkable') // Block level items, key is Remarkable's key for them, value returned is @@ -257,6 +258,11 @@ function markdownToState(markdown, options = {}) { const BlockEntities = Object.assign({}, DefaultBlockEntities, options.blockEntities || {}) const BlockStyles = Object.assign({}, DefaultBlockStyles, options.blockStyles || {}) + // when there is no content, add empty paragraph + if (parsedData.length === 0) { + blocks.push(getNewBlock(BlockTypes['paragraph_open']())); + } + parsedData.forEach((item) => { if (item.type === 'bullet_list_open') { @@ -347,10 +353,26 @@ function markdownToState(markdown, options = {}) { }, DefaultBlockType) } - return convertFromRaw({ - entityMap, - blocks, - }) + let result; + try { + result = convertFromRaw({ + entityMap, + blocks, + }); + } catch(error) { + // If any error occurs set value to plain text + const plainTextBlock = getNewBlock(BlockTypes['paragraph_open']()); + plainTextBlock.text = markdown; + + result = convertFromRaw({ + entityMap: [], + blocks: [plainTextBlock], + }); + + Alert.warning('Some message could not be rendered properly, please contact Topcoder Support') + } + + return result; } export default markdownToState