Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public setMarkdownValue = debounce(() => {
try {
const { form, path } = this.props;
this.state.value.toRAW();
form.setFieldsValue({
[path]: draftToMarkdown(
JSON.parse(this.state.value.toRAW().toString()),
markdownConfig
).replace(/\n\n/g, '\n \n'),
});
} catch (err) {
console.error('Error converting rich text to markdown'); // tslint:disable-line no-console
}
}, 330);
handleSave = ({ updateNode }) => () => {
const { editorState } = this.state;
const { node = {} } = this.props;
const markdown = draftToMarkdown(
convertToRaw(editorState.getCurrentContent())
);
this.setState({ source: markdown, originalEditorState: editorState });
updateNode({ variables: { id: node.id, content: markdown } });
console.log('Synced to GraphCMS');
};
render() {
const createFile = (title, content) =>
`---
title: ${title}
---
${draftToMarkdown(content)}`
const createFile = ({ title, dateModified, content }) => ({
title: title,
dateModified: dateModified,
content: draftToMarkdown(content)
})
const customDraft = (content: Draft.RawDraftContentState): string =>
draftToMarkdown(content, {
entityItems: {
LINK: {
open: () => {
return "[";
},
close: (entity: any) => {
return `](${entity.data.url || entity.data.href})`;
}
}
}
});
export const convertDraftToMd = raw => draftToMarkdown(
raw,
{
styleItems
}
)
} else if (!post.public) {
return Boom.notFound(
"This post is either not public or I couldn't even find it. Things are hard sometimes."
);
} else {
const user = await User.findOne({ _id: post.user }, (err, user) => {
return user;
});
return {
id: req.params.id,
author: {
username: user.username,
avatar: user.gradient || ['#FEB692', '#EA5455']
},
content: draftToMarkdown(post.content, {
entityItems: {
LINK: {
open: () => {
return '[';
},
close: entity => {
return `](${entity.data.url || entity.data.href})`;
}
}
}
}),
title: post.title,
dateAdded: post.dateAdded
};
}