From d26e2a328f8395252f4c54f1cefa00a3524232ac Mon Sep 17 00:00:00 2001 From: okbel Date: Mon, 5 Mar 2018 17:49:05 -0300 Subject: [PATCH] html and content editable normalizer --- .../client/components/Editor.js | 4 +++- plugins/talk-plugin-rich-text-pell/client/utils.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 plugins/talk-plugin-rich-text-pell/client/utils.js diff --git a/plugins/talk-plugin-rich-text-pell/client/components/Editor.js b/plugins/talk-plugin-rich-text-pell/client/components/Editor.js index 33b122f09..c129e146d 100644 --- a/plugins/talk-plugin-rich-text-pell/client/components/Editor.js +++ b/plugins/talk-plugin-rich-text-pell/client/components/Editor.js @@ -4,6 +4,7 @@ import { init } from 'pell'; import styles from './Editor.css'; import cn from 'classnames'; import { pluginName } from '../../package.json'; +import { htmlNormalizer } from '../utils'; class Editor extends React.Component { ref = null; @@ -18,7 +19,7 @@ class Editor extends React.Component { onChange: richTextBody => { // We want to save the original comment body const originalBody = this.ref.childNodes[1].innerText; - onChange(originalBody, { richTextBody }); + onChange(originalBody, { richTextBody: htmlNormalizer(richTextBody) }); }, actions, classes: { @@ -101,6 +102,7 @@ Editor.propTypes = { actions: PropTypes.array, registerHook: PropTypes.func, unregisterHook: PropTypes.func, + isReply: PropTypes.bool, }; export default Editor; diff --git a/plugins/talk-plugin-rich-text-pell/client/utils.js b/plugins/talk-plugin-rich-text-pell/client/utils.js new file mode 100644 index 000000000..e00b7a91c --- /dev/null +++ b/plugins/talk-plugin-rich-text-pell/client/utils.js @@ -0,0 +1,10 @@ +export function htmlNormalizer(htmlInput) { + const str = htmlInput; + // We are normalizing the input from contenteditable of each browser, also removing unnecesary html tags + // https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Editable_content#Differences_in_markup_generation + return str + .replace('

', '

') // IE outputs

instead of

s + .replace('

', '
') // IE outputs

instead of

s + .replace('
', '
') + .replace('
', ''); +}