Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion src/components/RichTextArea/RichTextArea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
30 changes: 26 additions & 4 deletions src/helpers/markdownToState.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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