mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-11-07 15:08:24 +00:00
undo removal of stripping <p>s as it breaks HTML /mes
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -112,6 +112,33 @@ export function charactersToImageNode(alt, useSvg, ...unicode) {
|
|||||||
/>;
|
/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function processHtmlForSending(html: string): string {
|
||||||
|
const contentDiv = document.createElement('div');
|
||||||
|
contentDiv.innerHTML = html;
|
||||||
|
|
||||||
|
if (contentDiv.children.length === 0) {
|
||||||
|
return contentDiv.innerHTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
let contentHTML = "";
|
||||||
|
for (let i=0; i < contentDiv.children.length; i++) {
|
||||||
|
const element = contentDiv.children[i];
|
||||||
|
if (element.tagName.toLowerCase() === 'p') {
|
||||||
|
contentHTML += element.innerHTML;
|
||||||
|
// Don't add a <br /> for the last <p>
|
||||||
|
if (i !== contentDiv.children.length - 1) {
|
||||||
|
contentHTML += '<br />';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const temp = document.createElement('div');
|
||||||
|
temp.appendChild(element.cloneNode(true));
|
||||||
|
contentHTML += temp.innerHTML;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return contentHTML;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Given an untrusted HTML string, return a React node with an sanitized version
|
* Given an untrusted HTML string, return a React node with an sanitized version
|
||||||
* of that HTML.
|
* of that HTML.
|
||||||
|
|||||||
+4
-4
@@ -111,7 +111,7 @@ export default class Markdown {
|
|||||||
// you can nest them.
|
// you can nest them.
|
||||||
//
|
//
|
||||||
// Let's try sending with <p/>s anyway for now, though.
|
// Let's try sending with <p/>s anyway for now, though.
|
||||||
/*
|
|
||||||
const real_paragraph = renderer.paragraph;
|
const real_paragraph = renderer.paragraph;
|
||||||
|
|
||||||
renderer.paragraph = function(node, entering) {
|
renderer.paragraph = function(node, entering) {
|
||||||
@@ -124,10 +124,10 @@ export default class Markdown {
|
|||||||
real_paragraph.call(this, node, entering);
|
real_paragraph.call(this, node, entering);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
|
|
||||||
renderer.html_inline = html_if_tag_allowed;
|
renderer.html_inline = html_if_tag_allowed;
|
||||||
|
|
||||||
renderer.html_block = function(node) {
|
renderer.html_block = function(node) {
|
||||||
/*
|
/*
|
||||||
// as with `paragraph`, we only insert line breaks
|
// as with `paragraph`, we only insert line breaks
|
||||||
@@ -138,7 +138,7 @@ export default class Markdown {
|
|||||||
html_if_tag_allowed.call(this, node);
|
html_if_tag_allowed.call(this, node);
|
||||||
/*
|
/*
|
||||||
if (isMultiLine) this.cr();
|
if (isMultiLine) this.cr();
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
return renderer.render(this.parsed);
|
return renderer.render(this.parsed);
|
||||||
|
|||||||
@@ -1089,8 +1089,7 @@ export default class MessageComposerInput extends React.Component {
|
|||||||
if (contentText === '') return true;
|
if (contentText === '') return true;
|
||||||
|
|
||||||
if (shouldSendHTML) {
|
if (shouldSendHTML) {
|
||||||
// FIXME: should we strip out the surrounding <p></p>?
|
contentHTML = HtmlUtils.processHtmlForSending(this.html.serialize(editorState));
|
||||||
contentHTML = this.html.serialize(editorState); // HtmlUtils.processHtmlForSending();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const sourceWithPills = this.plainWithMdPills.serialize(editorState);
|
const sourceWithPills = this.plainWithMdPills.serialize(editorState);
|
||||||
|
|||||||
Reference in New Issue
Block a user